System.Data.SQLite

Check-in [c1fc6af85e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Bump all version numbers to 1.0.99.0. Update SQLite core library to the latest trunk code.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c1fc6af85eb1dcbe37f151861a17dff20cbe6788
User & Date: mistachkin 2015-09-09 23:34:29.872
Context
2015-09-09
23:40
Update version in one placed missed in the README file. check-in: b3122a99cc user: mistachkin tags: trunk
23:34
Bump all version numbers to 1.0.99.0. Update SQLite core library to the latest trunk code. check-in: c1fc6af85e user: mistachkin tags: trunk
2015-08-25
21:16
Remove duplicate (and incorrect for Visual Studio 2015) link from the download page. check-in: 463bcfb351 user: mistachkin tags: trunk
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to Doc/Extra/Provider/dbfactorysupport.html.
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95







-
+







<configuration>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite"/>
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" 
           description=".NET Framework Data Provider for SQLite"
           type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite,
                 Version=1.0.98.0, Culture=neutral,
                 Version=1.0.99.0, Culture=neutral,
                 PublicKeyToken=db937bc2d44ff139"/>
    </DbProviderFactories>
  </system.data>
</configuration>
</pre>
      </div>
      <p>
Changes to Doc/Extra/Provider/version.html.
39
40
41
42
43
44
45




46
47
48
49
50
51
52
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56







+
+
+
+







          </td>
        </tr>
      </table>
    </div>
    <div id="mainSection">
    <div id="mainBody">
    <h1 class="heading">Version History</h1>
    <p><b>1.0.99.0 - October XX, 2015 <font color="red">(release scheduled)</font></b></p>
    <ul>
      <li>Updated to <a href="https://www.sqlite.org/draft/releaselog/3_8_12.html">SQLite 3.8.12</a>.</li>
    </ul>
    <p><b>1.0.98.0 - August 19, 2015</b></p>
    <ul>
      <li>Updated to <a href="https://www.sqlite.org/releaselog/3_8_11_1.html">SQLite 3.8.11.1</a>.</li>
      <li>Add full support for Visual Studio 2015 and the .NET Framework 4.6.</li>
      <li>Add support for creating custom SQL functions using delegates.</li>
      <li>Implement the Substring method for LINQ using the &quot;substr&quot; core SQL function.&nbsp;<b>** Potentially Incompatible Change **</b></li>
      <li>Prevent encrypted connections from being used with the connection pool. Pursuant to <a href="https://system.data.sqlite.org/index.html/info/89d3a159f1">[89d3a159f1]</a>.&nbsp;<b>** Potentially Incompatible Change **</b></li>
Changes to Doc/Extra/Provider/welcome.html.
156
157
158
159
160
161
162
163

164
165
166
167
168
169
170
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170







-
+







        <font color="red">
          Itanium processor support not currently included.
        </font>
      </p>
      <h1 class="heading">Distributing the Binaries (Compact Framework)</h1>
      <p>Both the <b>System.Data.SQLite.DLL </b>and <b>SQLite.Interop.XXX.DLL</b> files
        must be deployed on the Compact Framework.&nbsp; The XXX is the build number of
        the System.Data.SQLite library (e.g. &quot;098&quot;).&nbsp; The
        the System.Data.SQLite library (e.g. &quot;099&quot;).&nbsp; The
        <b>SQLite.Interop.XXX.DLL</b> file is a fully native assembly compiled for
        the ARM processor, and System.Data.SQLite is the fully-managed Compact
        Framework assembly.</p>
      <hr />
      <div id="footer">
        <p>
          <a href="mailto:sqlite-users@mailinglists.sqlite.org?subject=SQLite.NET%20Class%20Library%20Documentation%20Feedback:%20Welcome">
Changes to NuGet/SQLite.Beta.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25

26
27
28

29
30
31

32
33
34

35
36
37

38
39
40

41
42
43

44
45
46

47
48
49

50
51
52

53
54
55

56
57
58

59
60
61

62
63
64

65
66
67
68
69
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24

25
26
27

28
29
30

31
32
33

34
35
36

37
38
39

40
41
42

43
44
45

46
47
48

49
50
51

52
53
54

55
56
57

58
59
60

61
62
63

64
65
66
67
68
69













-
+










-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+





<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Beta.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.Beta</id>
    <title>System.Data.SQLite (x86/x64) Beta</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a &quot;beta&quot; 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>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
    <copyright>Public Domain</copyright>
    <dependencies>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
      </group>
    </dependencies>
  </metadata>
  <files />
</package>
Changes to NuGet/SQLite.Core.Beta.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Core.Beta.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.Core.Beta</id>
    <title>System.Data.SQLite Core (x86/x64) Beta</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a &quot;beta&quot; 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>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Core.MSIL.Beta.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Core.MSIL.Beta.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.Core.MSIL.Beta</id>
    <title>System.Data.SQLite (MSIL) Beta</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a &quot;beta&quot; package and is not intended for production use.  An ADO.NET provider for SQLite (managed-only).</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Core.MSIL.Test.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Core.MSIL.Test.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.Core.MSIL.Test</id>
    <title>System.Data.SQLite (MSIL) Test</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a pre-release package and is not intended for production use.  An ADO.NET provider for SQLite (managed-only).</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Core.MSIL.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Core.MSIL.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.Core.MSIL</id>
    <title>System.Data.SQLite Core (MSIL)</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>An ADO.NET provider for SQLite (managed-only).</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Core.Test.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Core.Test.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.Core.Test</id>
    <title>System.Data.SQLite Core (x86/x64) Test</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <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>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Core.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Core.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.Core</id>
    <title>System.Data.SQLite Core (x86/x64)</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>The official SQLite database engine for both x86 and x64 along with the ADO.NET provider.</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.EF6.Beta.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.EF6.Beta.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.EF6.Beta</id>
    <title>System.Data.SQLite EF6 Beta</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a &quot;beta&quot; package and is not intended for production use.  Support for Entity Framework 6 using System.Data.SQLite.</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.EF6.Test.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.EF6.Test.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.EF6.Test</id>
    <title>System.Data.SQLite EF6 Test</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a pre-release package and is not intended for production use.  Support for Entity Framework 6 using System.Data.SQLite.</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.EF6.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.EF6.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.EF6</id>
    <title>System.Data.SQLite EF6</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>Support for Entity Framework 6 using System.Data.SQLite.</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Linq.Beta.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Linq.Beta.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.Linq.Beta</id>
    <title>System.Data.SQLite LINQ Beta</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a &quot;beta&quot; package and is not intended for production use.  Support for LINQ using System.Data.SQLite.</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Linq.Test.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Linq.Test.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.Linq.Test</id>
    <title>System.Data.SQLite LINQ Test</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a pre-release package and is not intended for production use.  Support for LINQ using System.Data.SQLite.</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.Linq.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Linq.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.Linq</id>
    <title>System.Data.SQLite LINQ</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>Support for LINQ using System.Data.SQLite.</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
Changes to NuGet/SQLite.MSIL.Beta.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25

26
27
28

29
30
31

32
33
34

35
36
37

38
39
40

41
42
43

44
45
46

47
48
49

50
51
52

53
54
55

56
57
58

59
60
61

62
63
64

65
66
67
68
69
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24

25
26
27

28
29
30

31
32
33

34
35
36

37
38
39

40
41
42

43
44
45

46
47
48

49
50
51

52
53
54

55
56
57

58
59
60

61
62
63

64
65
66
67
68
69













-
+










-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+





<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.MSIL.Beta.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.MSIL.Beta</id>
    <title>System.Data.SQLite (MSIL) Beta</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a &quot;beta&quot; package and is not intended for production use.  This is a legacy package; if possible, please use either the &quot;System.Data.SQLite.Beta&quot; or &quot;System.Data.SQLite.Core.Beta&quot; package instead.  An ADO.NET provider for SQLite (managed-only).</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
    <copyright>Public Domain</copyright>
    <dependencies>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Beta" version="1.0.99.0" />
      </group>
    </dependencies>
  </metadata>
  <files />
</package>
Changes to NuGet/SQLite.MSIL.Test.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25

26
27
28

29
30
31

32
33
34

35
36
37

38
39
40

41
42
43

44
45
46

47
48
49

50
51
52

53
54
55

56
57
58

59
60
61

62
63
64

65
66
67
68
69
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24

25
26
27

28
29
30

31
32
33

34
35
36

37
38
39

40
41
42

43
44
45

46
47
48

49
50
51

52
53
54

55
56
57

58
59
60

61
62
63

64
65
66
67
68
69













-
+










-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+





<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.MSIL.Test.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.MSIL.Test</id>
    <title>System.Data.SQLite (MSIL) Test</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <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 &quot;System.Data.SQLite.Test&quot; or &quot;System.Data.SQLite.Core.Test&quot; package instead.  An ADO.NET provider for SQLite (managed-only).</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
    <copyright>Public Domain</copyright>
    <dependencies>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
      </group>
    </dependencies>
  </metadata>
  <files />
</package>
Changes to NuGet/SQLite.MSIL.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25

26
27
28

29
30
31

32
33
34

35
36
37

38
39
40

41
42
43

44
45
46

47
48
49

50
51
52

53
54
55

56
57
58

59
60
61

62
63
64

65
66
67
68
69
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24

25
26
27

28
29
30

31
32
33

34
35
36

37
38
39

40
41
42

43
44
45

46
47
48

49
50
51

52
53
54

55
56
57

58
59
60

61
62
63

64
65
66
67
68
69













-
+










-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+





<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.MSIL.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.MSIL</id>
    <title>System.Data.SQLite (MSIL)</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a legacy package; if possible, please use either the &quot;System.Data.SQLite&quot; or &quot;System.Data.SQLite.Core&quot; package instead.  An ADO.NET provider for SQLite (managed-only).</description>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
    <copyright>Public Domain</copyright>
    <dependencies>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.MSIL" version="1.0.99.0" />
      </group>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
    </dependencies>
  </metadata>
  <files />
</package>
Changes to NuGet/SQLite.Test.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25

26
27
28

29
30
31

32
33
34

35
36
37

38
39
40

41
42
43

44
45
46

47
48
49

50
51
52

53
54
55

56
57
58

59
60
61

62
63
64

65
66
67
68
69
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24

25
26
27

28
29
30

31
32
33

34
35
36

37
38
39

40
41
42

43
44
45

46
47
48

49
50
51

52
53
54

55
56
57

58
59
60

61
62
63

64
65
66
67
68
69













-
+










-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+





<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Test.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.Test</id>
    <title>System.Data.SQLite (x86/x64) Test</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <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>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
    <copyright>Public Domain</copyright>
    <dependencies>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Core.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Core.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Core.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Core.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Core.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6.Test" version="1.0.99.0" />
      </group>
    </dependencies>
  </metadata>
  <files />
</package>
Changes to NuGet/SQLite.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25

26
27
28

29
30
31

32
33
34

35
36
37

38
39
40

41
42
43

44
45
46

47
48
49

50
51
52

53
54
55

56
57
58

59
60
61

62
63
64

65
66
67
68
69
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24

25
26
27

28
29
30

31
32
33

34
35
36

37
38
39

40
41
42

43
44
45

46
47
48

49
50
51

52
53
54

55
56
57

58
59
60

61
62
63

64
65
66
67
68
69













-
+










-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+





<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite</id>
    <title>System.Data.SQLite (x86/x64)</title>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <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>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
    <copyright>Public Domain</copyright>
    <dependencies>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Core" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Core" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Core" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Core" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Core" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Core" version="1.0.99.0" />
      </group>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
    </dependencies>
  </metadata>
  <files />
</package>
Changes to NuGet/SQLite.x64.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24

25
26
27

28
29
30

31
32
33

34
35
36

37
38
39

40
41
42

43
44
45

46
47
48

49
50
51
52
53
54
55
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23

24
25
26

27
28
29

30
31
32

33
34
35

36
37
38

39
40
41

42
43
44

45
46
47

48
49
50
51
52
53
54
55












-
+










-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.x64.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.x64</id>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a legacy package; if possible, please use either the &quot;System.Data.SQLite&quot; or &quot;System.Data.SQLite.Core&quot; 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>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
    <copyright>Public Domain</copyright>
    <dependencies>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
    </dependencies>
  </metadata>
  <files>
    <file src="..\bin\2008\x64\ReleaseStatic\System.Data.SQLite.dll" target="lib\net20" />
    <file src="..\bin\2008\Release\bin\System.Data.SQLite.xml" target="lib\net20" />
    <file src="..\bin\2010\x64\ReleaseStatic\System.Data.SQLite.dll" target="lib\net40" />
Changes to NuGet/SQLite.x86.nuspec.
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24

25
26
27

28
29
30

31
32
33

34
35
36

37
38
39

40
41
42

43
44
45

46
47
48

49
50
51
52
53
54
55
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
23

24
25
26

27
28
29

30
31
32

33
34
35

36
37
38

39
40
41

42
43
44

45
46
47

48
49
50
51
52
53
54
55












-
+










-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.x86.nuspec -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<package>
  <metadata>
    <id>System.Data.SQLite.x86</id>
    <version>1.0.98.1</version>
    <version>1.0.99.0</version>
    <authors>SQLite Development Team</authors>
    <description>This is a legacy package; if possible, please use either the &quot;System.Data.SQLite&quot; or &quot;System.Data.SQLite.Core&quot; 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>
    <language>en-US</language>
    <projectUrl>https://system.data.sqlite.org/</projectUrl>
    <iconUrl>https://system.data.sqlite.org/images/sqlite128.png</iconUrl>
    <licenseUrl>https://www.sqlite.org/copyright.html</licenseUrl>
    <tags>sqlite database ado.net provider interop</tags>
    <copyright>Public Domain</copyright>
    <dependencies>
      <group targetFramework="net20">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.Linq" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.Linq" version="1.0.99.0" />
      </group>
      <group targetFramework="net40">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net45">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net451">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
      <group targetFramework="net46">
        <dependency id="System.Data.SQLite.EF6" version="1.0.98.1" />
        <dependency id="System.Data.SQLite.EF6" version="1.0.99.0" />
      </group>
    </dependencies>
  </metadata>
  <files>
    <file src="..\bin\2008\Win32\ReleaseStatic\System.Data.SQLite.dll" target="lib\net20" />
    <file src="..\bin\2008\Release\bin\System.Data.SQLite.xml" target="lib\net20" />
    <file src="..\bin\2010\Win32\ReleaseStatic\System.Data.SQLite.dll" target="lib\net40" />
Changes to SQLite.Designer/AssemblyInfo.cs.
39
40
41
42
43
44
45
46
47


39
40
41
42
43
44
45


46
47







-
-
+
+
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.98.0")]
[assembly: AssemblyFileVersion("1.0.98.0")]
[assembly: AssemblyVersion("1.0.99.0")]
[assembly: AssemblyFileVersion("1.0.99.0")]
Changes to SQLite.Designer/source.extension.vsixmanifest.
1
2
3
4
5
6

7
8
9
10
11
12
13
1
2
3
4
5

6
7
8
9
10
11
12
13





-
+







<?xml version="1.0" encoding="utf-8"?>
<Vsix Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
  <Identifier Id="67b5f3a9-cde1-430f-a12b-af95bb064851">
    <Name>System.Data.SQLite Designer</Name>
    <Author>https://system.data.sqlite.org/</Author>
    <Version>1.0.98.0</Version>
    <Version>1.0.99.0</Version>
    <Description>ADO.NET Data Designer for SQLite</Description>
    <Locale>1033</Locale>
    <InstalledByMsi>false</InstalledByMsi>
    <SupportedProducts>
      <VisualStudio Version="10.0">
        <Edition>Pro</Edition>
      </VisualStudio>
Changes to SQLite.Interop/props/SQLite.Interop.2005.vsprops.
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32

33
34
35
36
37

38
39
40
41
42
43
44
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31

32
33
34
35
36

37
38
39
40
41
42
43
44







-
+









-
+




-
+







	<UserMacro
		Name="ConfigurationYear"
		Value="2005"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="INTEROP_BUILD_NUMBER"
		Value="098"
		Value="099"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="INTEROP_LINKER_VERSION"
		Value="1.0"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="INTEROP_MANIFEST_VERSION"
		Value="1.0.98.0"
		Value="1.0.99.0"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="INTEROP_RC_VERSION"
		Value="1,0,98,0"
		Value="1,0,99,0"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="INTEROP_INCLUDE_DIRECTORIES"
		Value="src\core"
		PerformEnvironmentSet="true"
	/>
Changes to SQLite.Interop/props/SQLite.Interop.2008.vsprops.
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32

33
34
35
36
37

38
39
40
41
42
43
44
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31

32
33
34
35
36

37
38
39
40
41
42
43
44







-
+









-
+




-
+







	<UserMacro
		Name="ConfigurationYear"
		Value="2008"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="INTEROP_BUILD_NUMBER"
		Value="098"
		Value="099"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="INTEROP_LINKER_VERSION"
		Value="1.0"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="INTEROP_MANIFEST_VERSION"
		Value="1.0.98.0"
		Value="1.0.99.0"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="INTEROP_RC_VERSION"
		Value="1,0,98,0"
		Value="1,0,99,0"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="INTEROP_INCLUDE_DIRECTORIES"
		Value="src\core"
		PerformEnvironmentSet="true"
	/>
Changes to SQLite.Interop/props/SQLite.Interop.2010.props.
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16


17
18
19
20
21
22
23
1
2
3
4
5
6
7
8
9
10
11
12

13
14


15
16
17
18
19
20
21
22
23












-
+

-
-
+
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Interop.2010.props -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup Label="UserMacros">
    <ConfigurationYear>2010</ConfigurationYear>
    <INTEROP_BUILD_NUMBER>098</INTEROP_BUILD_NUMBER>
    <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER>
    <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    <INTEROP_MANIFEST_VERSION>1.0.98.0</INTEROP_MANIFEST_VERSION>
    <INTEROP_RC_VERSION>1,0,98,0</INTEROP_RC_VERSION>
    <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION>
    <INTEROP_RC_VERSION>1,0,99,0</INTEROP_RC_VERSION>
    <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    <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_EXTRA_DEFINES>
    <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>
    <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>
Changes to SQLite.Interop/props/SQLite.Interop.2012.props.
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16


17
18
19
20
21
22
23
1
2
3
4
5
6
7
8
9
10
11
12

13
14


15
16
17
18
19
20
21
22
23












-
+

-
-
+
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Interop.2012.props -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup Label="UserMacros">
    <ConfigurationYear>2012</ConfigurationYear>
    <INTEROP_BUILD_NUMBER>098</INTEROP_BUILD_NUMBER>
    <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER>
    <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    <INTEROP_MANIFEST_VERSION>1.0.98.0</INTEROP_MANIFEST_VERSION>
    <INTEROP_RC_VERSION>1,0,98,0</INTEROP_RC_VERSION>
    <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION>
    <INTEROP_RC_VERSION>1,0,99,0</INTEROP_RC_VERSION>
    <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    <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_EXTRA_DEFINES>
    <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>
    <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>
Changes to SQLite.Interop/props/SQLite.Interop.2013.props.
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16


17
18
19
20
21
22
23
1
2
3
4
5
6
7
8
9
10
11
12

13
14


15
16
17
18
19
20
21
22
23












-
+

-
-
+
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Interop.2013.props -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
  <PropertyGroup Label="UserMacros">
    <ConfigurationYear>2013</ConfigurationYear>
    <INTEROP_BUILD_NUMBER>098</INTEROP_BUILD_NUMBER>
    <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER>
    <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    <INTEROP_MANIFEST_VERSION>1.0.98.0</INTEROP_MANIFEST_VERSION>
    <INTEROP_RC_VERSION>1,0,98,0</INTEROP_RC_VERSION>
    <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION>
    <INTEROP_RC_VERSION>1,0,99,0</INTEROP_RC_VERSION>
    <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    <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_EXTRA_DEFINES>
    <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>
    <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>
Changes to SQLite.Interop/props/SQLite.Interop.2015.props.
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16


17
18
19
20
21
22
23
1
2
3
4
5
6
7
8
9
10
11
12

13
14


15
16
17
18
19
20
21
22
23












-
+

-
-
+
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * SQLite.Interop.2015.props -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
  <PropertyGroup Label="UserMacros">
    <ConfigurationYear>2015</ConfigurationYear>
    <INTEROP_BUILD_NUMBER>098</INTEROP_BUILD_NUMBER>
    <INTEROP_BUILD_NUMBER>099</INTEROP_BUILD_NUMBER>
    <INTEROP_LINKER_VERSION>1.0</INTEROP_LINKER_VERSION>
    <INTEROP_MANIFEST_VERSION>1.0.98.0</INTEROP_MANIFEST_VERSION>
    <INTEROP_RC_VERSION>1,0,98,0</INTEROP_RC_VERSION>
    <INTEROP_MANIFEST_VERSION>1.0.99.0</INTEROP_MANIFEST_VERSION>
    <INTEROP_RC_VERSION>1,0,99,0</INTEROP_RC_VERSION>
    <INTEROP_INCLUDE_DIRECTORIES>src\core</INTEROP_INCLUDE_DIRECTORIES>
    <INTEROP_LIBRARY_DIRECTORIES></INTEROP_LIBRARY_DIRECTORIES>
    <INTEROP_LIBRARY_DEPENDENCIES></INTEROP_LIBRARY_DEPENDENCIES>
    <INTEROP_DEBUG_DEFINES>INTEROP_DEBUG=0x31F;INTEROP_LOG=1;INTEROP_TEST_EXTENSION=1</INTEROP_DEBUG_DEFINES>
    <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_EXTRA_DEFINES>
    <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>
    <INTEROP_KEY_FILE>$(ProjectDir)..\Keys\System.Data.SQLite.snk</INTEROP_KEY_FILE>
Changes to SQLite.Interop/props/sqlite3.props.
1
2
3
4
5
6
7
8
9
10
11
12
13


14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11


12
13
14
15
16
17
18
19
20











-
-
+
+







<?xml version="1.0" encoding="utf-8"?>
<!--
 *
 * sqlite3.props -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 *
-->
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup Label="UserMacros">
    <SQLITE_MANIFEST_VERSION>3.8.11.1</SQLITE_MANIFEST_VERSION>
    <SQLITE_RC_VERSION>3,8,11,1</SQLITE_RC_VERSION>
    <SQLITE_MANIFEST_VERSION>3.8.12.0</SQLITE_MANIFEST_VERSION>
    <SQLITE_RC_VERSION>3,8,12,0</SQLITE_RC_VERSION>
    <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_FTS5=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=1</SQLITE_COMMON_DEFINES>
    <SQLITE_EXTRA_DEFINES>SQLITE_PLACEHOLDER=1;SQLITE_HAS_CODEC=1</SQLITE_EXTRA_DEFINES>
    <SQLITE_WINCE_200X_DEFINES>SQLITE_OMIT_WAL=1</SQLITE_WINCE_200X_DEFINES>
    <SQLITE_WINCE_2013_DEFINES>HAVE_ERRNO_H=1;SQLITE_MSVC_LOCALTIME_API=1</SQLITE_WINCE_2013_DEFINES>
    <SQLITE_DEBUG_DEFINES>SQLITE_DEBUG=1;SQLITE_MEMDEBUG=1;SQLITE_ENABLE_EXPENSIVE_ASSERT=1</SQLITE_DEBUG_DEFINES>
    <SQLITE_RELEASE_DEFINES>SQLITE_WIN32_MALLOC=1</SQLITE_RELEASE_DEFINES>
    <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
11
12
13
14
15
16
17

18
19
20
21
22

23
24
25
26
27
28
29
10
11
12
13
14
15
16

17
18
19
20
21

22
23
24
25
26
27
28
29







-
+




-
+







<VisualStudioPropertySheet
	ProjectType="Visual C++"
	Version="8.00"
	Name="sqlite3"
	>
	<UserMacro
		Name="SQLITE_MANIFEST_VERSION"
		Value="3.8.11.1"
		Value="3.8.12.0"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="SQLITE_RC_VERSION"
		Value="3,8,11,1"
		Value="3,8,12,0"
		PerformEnvironmentSet="true"
	/>
	<UserMacro
		Name="SQLITE_COMMON_DEFINES"
		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_FTS5=1;SQLITE_ENABLE_LOAD_EXTENSION=1;SQLITE_ENABLE_RTREE=1;SQLITE_SOUNDEX=1;SQLITE_ENABLE_MEMORY_MANAGEMENT=1"
		PerformEnvironmentSet="true"
	/>
Changes to SQLite.Interop/src/core/sqlite3.c.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







/******************************************************************************
** This file is an amalgamation of many separate C source files from SQLite
** version 3.8.11.1.  By combining all the individual C code files into this 
** version 3.8.12.  By combining all the individual C code files into this 
** single large file, the entire code can be compiled as a single translation
** unit.  This allows many compilers to do optimizations that would not be
** possible if the files were compiled separately.  Performance improvements
** of 5% or more are commonly seen when SQLite is compiled as a single
** translation unit.
**
** This file is all you need to compile SQLite.  To use SQLite in other
321
322
323
324
325
326
327
328
329
330



331
332
333
334
335
336
337
321
322
323
324
325
326
327



328
329
330
331
332
333
334
335
336
337







-
-
-
+
+
+







** string contains the date and time of the check-in (UTC) and an SHA1
** hash of the entire source tree.
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION        "3.8.11.1"
#define SQLITE_VERSION_NUMBER 3008011
#define SQLITE_SOURCE_ID      "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
#define SQLITE_VERSION        "3.8.12"
#define SQLITE_VERSION_NUMBER 3008012
#define SQLITE_SOURCE_ID      "2015-09-09 19:44:33 8d2ed150a7a15626965cf994ef48c3ab61eca6ec"

/*
** CAPI3REF: Run-Time Library Version Numbers
** KEYWORDS: sqlite3_version, sqlite3_sourceid
**
** These interfaces provide the same information as the [SQLITE_VERSION],
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
687
688
689
690
691
692
693

694
695
696
697
698
699
700
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701







+







#define SQLITE_IOERR_SHMLOCK           (SQLITE_IOERR | (20<<8))
#define SQLITE_IOERR_SHMMAP            (SQLITE_IOERR | (21<<8))
#define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
#define SQLITE_IOERR_DELETE_NOENT      (SQLITE_IOERR | (23<<8))
#define SQLITE_IOERR_MMAP              (SQLITE_IOERR | (24<<8))
#define SQLITE_IOERR_GETTEMPPATH       (SQLITE_IOERR | (25<<8))
#define SQLITE_IOERR_CONVPATH          (SQLITE_IOERR | (26<<8))
#define SQLITE_IOERR_VNODE             (SQLITE_IOERR | (27<<8))
#define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
#define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
#define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
#define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
#define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
#define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
#define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
3583
3584
3585
3586
3587
3588
3589
3590


3591
3592
3593
3594
3595
3596
3597
3584
3585
3586
3587
3588
3589
3590

3591
3592
3593
3594
3595
3596
3597
3598
3599







-
+
+








/*
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
** METHOD: sqlite3_stmt
**
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
** [prepared statement] S has been stepped at least once using 
** [sqlite3_step(S)] but has not run to completion and/or has not 
** [sqlite3_step(S)] but has neither run to completion (returned
** [SQLITE_DONE] from [sqlite3_step(S)]) nor
** been reset using [sqlite3_reset(S)].  ^The sqlite3_stmt_busy(S)
** interface returns false if S is a NULL pointer.  If S is not a 
** NULL pointer and is not a pointer to a valid [prepared statement]
** object, then the behavior is undefined and probably undesirable.
**
** This interface can be used in combination [sqlite3_next_stmt()]
** to locate all prepared statements associated with a database 
8359
8360
8361
8362
8363
8364
8365
8366


8367

8368
8369
8370
8371
8372
8373
8374








8375
8376
8377
8378
8379
8380
8381
8361
8362
8363
8364
8365
8366
8367

8368
8369
8370
8371







8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386







-
+
+

+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







#  define SQLITE_NOINLINE  __declspec(noinline)
#else
#  define SQLITE_NOINLINE
#endif

/*
** Make sure that the compiler intrinsics we desire are enabled when
** compiling with an appropriate version of MSVC.
** compiling with an appropriate version of MSVC unless prevented by
** the SQLITE_DISABLE_INTRINSIC define.
*/
#if !defined(SQLITE_DISABLE_INTRINSIC)
#if defined(_MSC_VER) && _MSC_VER>=1300
#  if !defined(_WIN32_WCE)
#    include <intrin.h>
#    pragma intrinsic(_byteswap_ushort)
#    pragma intrinsic(_byteswap_ulong)
#  else
#    include <cmnintrin.h>
#  if defined(_MSC_VER) && _MSC_VER>=1300
#    if !defined(_WIN32_WCE)
#      include <intrin.h>
#      pragma intrinsic(_byteswap_ushort)
#      pragma intrinsic(_byteswap_ulong)
#    else
#      include <cmnintrin.h>
#    endif
#  endif
#endif

/*
** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
** 0 means mutexes are permanently disable and the library is never
** threadsafe.  1 means the library is serialized which is the highest
10048
10049
10050
10051
10052
10053
10054



10055
10056
10057
10058
10059
10060

10061
10062
10063
10064
10065
10066
10067
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076







+
+
+






+







** Prototypes for the VDBE interface.  See comments on the implementation
** for a description of what each of these routines does.
*/
SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse*);
SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int);
SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe*,int);
SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe*,int,const char*);
SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
10911
10912
10913
10914
10915
10916
10917

10918
10919
10920
10921
10922
10923
10924
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934







+







#define sqlite3_mutex_try(X)      SQLITE_OK
#define sqlite3_mutex_leave(X)    
#define sqlite3_mutex_held(X)     ((void)(X),1)
#define sqlite3_mutex_notheld(X)  ((void)(X),1)
#define sqlite3MutexAlloc(X)      ((sqlite3_mutex*)8)
#define sqlite3MutexInit()        SQLITE_OK
#define sqlite3MutexEnd()
#define sqlite3MemoryBarrier()    
#define MUTEX_LOGIC(X)
#else
#define MUTEX_LOGIC(X)            X
#endif /* defined(SQLITE_MUTEX_OMIT) */

/************** End of mutex.h ***********************************************/
/************** Continuing where we left off in sqliteInt.h ******************/
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349














11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363






11364
11365
11366
11367
11368
11369
11370
11341
11342
11343
11344
11345
11346
11347












11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388







-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+














+
+
+
+
+
+







};

/*
** Possible values for FuncDef.flags.  Note that the _LENGTH and _TYPEOF
** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG.  There
** are assert() statements in the code to verify this.
*/
#define SQLITE_FUNC_ENCMASK  0x003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
#define SQLITE_FUNC_LIKE     0x004 /* Candidate for the LIKE optimization */
#define SQLITE_FUNC_CASE     0x008 /* Case-sensitive LIKE-type function */
#define SQLITE_FUNC_EPHEM    0x010 /* Ephemeral.  Delete with VDBE */
#define SQLITE_FUNC_NEEDCOLL 0x020 /* sqlite3GetFuncCollSeq() might be called */
#define SQLITE_FUNC_LENGTH   0x040 /* Built-in length() function */
#define SQLITE_FUNC_TYPEOF   0x080 /* Built-in typeof() function */
#define SQLITE_FUNC_COUNT    0x100 /* Built-in count(*) aggregate */
#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
#define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */
#define SQLITE_FUNC_MINMAX  0x1000 /* True for min() and max() aggregates */
#define SQLITE_FUNC_ENCMASK  0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
#define SQLITE_FUNC_LIKE     0x0004 /* Candidate for the LIKE optimization */
#define SQLITE_FUNC_CASE     0x0008 /* Case-sensitive LIKE-type function */
#define SQLITE_FUNC_EPHEM    0x0010 /* Ephemeral.  Delete with VDBE */
#define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/
#define SQLITE_FUNC_LENGTH   0x0040 /* Built-in length() function */
#define SQLITE_FUNC_TYPEOF   0x0080 /* Built-in typeof() function */
#define SQLITE_FUNC_COUNT    0x0100 /* Built-in count(*) aggregate */
#define SQLITE_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */
#define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
#define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
#define SQLITE_FUNC_MINMAX   0x1000 /* True for min() and max() aggregates */
#define SQLITE_FUNC_SLOCHNG  0x2000 /* "Slow Change". Value constant during a
                                    ** single query - might change over time */

/*
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
** used to create the initializers for the FuncDef structures.
**
**   FUNCTION(zName, nArg, iArg, bNC, xFunc)
**     Used to create a scalar function definition of a function zName 
**     implemented by C function xFunc that accepts nArg arguments. The
**     value passed as iArg is cast to a (void*) and made available
**     as the user-data (sqlite3_user_data()) for the function. If 
**     argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
**
**   VFUNCTION(zName, nArg, iArg, bNC, xFunc)
**     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
**
**   DFUNCTION(zName, nArg, iArg, bNC, xFunc)
**     Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
**     adds the SQLITE_FUNC_SLOCHNG flag.  Used for date & time functions
**     and functions like sqlite_version() that can change, but not during
**     a single query.
**
**   AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
**     Used to create an aggregate function definition implemented by
**     the C functions xStep and xFinal. The first four parameters
**     are interpreted in the same way as the first 4 parameters to
**     FUNCTION().
**
11378
11379
11380
11381
11382
11383
11384



11385
11386
11387
11388
11389

11390
11391
11392
11393
11394
11395
11396
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409

11410
11411
11412
11413
11414
11415
11416
11417







+
+
+




-
+







*/
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
  {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
  {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
#define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
  {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
  {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
   SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
  {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
  {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
   pArg, 0, xFunc, 0, 0, #zName, 0, 0}
#define LIKEFUNC(zName, nArg, arg, flags) \
  {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
   (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
  {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
   SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
11426
11427
11428
11429
11430
11431
11432

11433
11434
11435
11436
11437
11438
11439
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461







+







** hash table.
*/
struct Module {
  const sqlite3_module *pModule;       /* Callback pointers */
  const char *zName;                   /* Name passed to create_module() */
  void *pAux;                          /* pAux passed to create_module() */
  void (*xDestroy)(void *);            /* Module destructor function */
  Table *pEpoTab;                      /* Eponymous table for this module */
};

/*
** information about each column of an SQL table is held in an instance
** of this structure.
*/
struct Column {
11471
11472
11473
11474
11475
11476
11477

11478
11479
11480
11481
11482
11483
11484
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507







+







};

/*
** A sort order can be either ASC or DESC.
*/
#define SQLITE_SO_ASC       0  /* Sort in ascending order */
#define SQLITE_SO_DESC      1  /* Sort in ascending order */
#define SQLITE_SO_UNDEFINED -1 /* No sort order specified */

/*
** Column affinity types.
**
** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
** 't' for SQLITE_AFF_TEXT.  But we can save a little space and improve
** the speed a little by numbering the values consecutively.  
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586

11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603

11604
11605
11606
11607
11608
11609
11610
11600
11601
11602
11603
11604
11605
11606

11607

11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624

11625
11626
11627
11628
11629
11630
11631
11632







-

-
+
















-
+







struct Table {
  char *zName;         /* Name of the table or view */
  Column *aCol;        /* Information about each column */
  Index *pIndex;       /* List of SQL indexes on this table. */
  Select *pSelect;     /* NULL for tables.  Points to definition if a view. */
  FKey *pFKey;         /* Linked list of all foreign keys in this table */
  char *zColAff;       /* String defining the affinity of each column */
#ifndef SQLITE_OMIT_CHECK
  ExprList *pCheck;    /* All CHECK constraints */
#endif
                       /*   ... also used as column name list in a VIEW */
  int tnum;            /* Root BTree page for this table */
  i16 iPKey;           /* If not negative, use aCol[iPKey] as the rowid */
  i16 nCol;            /* Number of columns in this table */
  u16 nRef;            /* Number of pointers to this Table */
  LogEst nRowLogEst;   /* Estimated rows in table - from sqlite_stat1 table */
  LogEst szTabRow;     /* Estimated size of each table row in bytes */
#ifdef SQLITE_ENABLE_COSTMULT
  LogEst costMult;     /* Cost multiplier for using this table */
#endif
  u8 tabFlags;         /* Mask of TF_* values */
  u8 keyConf;          /* What to do in case of uniqueness conflict on iPKey */
#ifndef SQLITE_OMIT_ALTERTABLE
  int addColOffset;    /* Offset in CREATE TABLE stmt to add a new column */
#endif
#ifndef SQLITE_OMIT_VIRTUALTABLE
  int nModuleArg;      /* Number of arguments to the module */
  char **azModuleArg;  /* Text of all module args. [0] is module name */
  char **azModuleArg;  /* 0: module 1: schema 2: vtab name 3...: args */
  VTable *pVTable;     /* List of VTable objects. */
#endif
  Trigger *pTrigger;   /* List of triggers stored in pSchema */
  Schema *pSchema;     /* Schema that contains this table */
  Table *pNextZombie;  /* Next on the Parse.pZombieTab list */
};

11817
11818
11819
11820
11821
11822
11823

11824
11825
11826
11827
11828
11829
11830
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853







+







  Table *pTable;           /* The SQL table being indexed */
  char *zColAff;           /* String defining the affinity of each column */
  Index *pNext;            /* The next index associated with the same table */
  Schema *pSchema;         /* Schema containing this index */
  u8 *aSortOrder;          /* for each column: True==DESC, False==ASC */
  char **azColl;           /* Array of collation sequence names for index */
  Expr *pPartIdxWhere;     /* WHERE clause for partial indices */
  ExprList *aColExpr;      /* Column expressions */
  int tnum;                /* DB Page containing root of this index */
  LogEst szIdxRow;         /* Estimated average row size in bytes */
  u16 nKeyCol;             /* Number of columns forming the key */
  u16 nColumn;             /* Number of columns stored in the index */
  u8 onError;              /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
  unsigned idxType:2;      /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
  unsigned bUnordered:1;   /* Use this index for == or IN queries only */
12066
12067
12068
12069
12070
12071
12072
12073

12074
12075

12076
12077
12078
12079
12080
12081
12082
12089
12090
12091
12092
12093
12094
12095

12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106







-
+


+







#define EP_Skip      0x001000 /* COLLATE, AS, or UNLIKELY */
#define EP_Reduced   0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
#define EP_Static    0x008000 /* Held in memory not obtained from malloc() */
#define EP_MemToken  0x010000 /* Need to sqlite3DbFree() Expr.zToken */
#define EP_NoReduce  0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
#define EP_Unlikely  0x040000 /* unlikely() or likelihood() function */
#define EP_ConstFunc 0x080000 /* Node is a SQLITE_FUNC_CONSTANT function */
#define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
#define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
#define EP_Alias     0x400000 /* Is an alias for a result set column */

/*
** Combinations of two or more EP_* flags
*/
#define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */

/*
12231
12232
12233
12234
12235
12236
12237

12238
12239
12240
12241
12242








12243
12244
12245
12246
12247
12248
12249

12250
12251




12252
12253
12254
12255
12256
12257
12258
12255
12256
12257
12258
12259
12260
12261
12262





12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278


12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289







+
-
-
-
-
-
+
+
+
+
+
+
+
+







+
-
-
+
+
+
+







    char *zName;      /* Name of the table */
    char *zAlias;     /* The "B" part of a "A AS B" phrase.  zName is the "A" */
    Table *pTab;      /* An SQL table corresponding to zName */
    Select *pSelect;  /* A SELECT statement used in place of a table name */
    int addrFillSub;  /* Address of subroutine to manifest a subquery */
    int regReturn;    /* Register holding return address of addrFillSub */
    int regResult;    /* Registers holding results of a co-routine */
    struct {
    u8 jointype;      /* Type of join between this able and the previous */
    unsigned notIndexed :1;    /* True if there is a NOT INDEXED clause */
    unsigned isCorrelated :1;  /* True if sub-query is correlated */
    unsigned viaCoroutine :1;  /* Implemented as a co-routine */
    unsigned isRecursive :1;   /* True for recursive reference in WITH */
      u8 jointype;      /* Type of join between this able and the previous */
      unsigned notIndexed :1;    /* True if there is a NOT INDEXED clause */
      unsigned isIndexedBy :1;   /* True if there is an INDEXED BY clause */
      unsigned isTabFunc :1;     /* True if table-valued-function syntax */
      unsigned isCorrelated :1;  /* True if sub-query is correlated */
      unsigned viaCoroutine :1;  /* Implemented as a co-routine */
      unsigned isRecursive :1;   /* True for recursive reference in WITH */
    } fg;
#ifndef SQLITE_OMIT_EXPLAIN
    u8 iSelectId;     /* If pSelect!=0, the id of the sub-select in EQP */
#endif
    int iCursor;      /* The VDBE cursor number used to access this table */
    Expr *pOn;        /* The ON clause of a join */
    IdList *pUsing;   /* The USING clause of a join */
    Bitmask colUsed;  /* Bit N (1<<N) set if column N of pTab is used */
    union {
    char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
    Index *pIndex;    /* Index structure corresponding to zIndex, if any */
      char *zIndexedBy;    /* Identifier from "INDEXED BY <zIndex>" clause */
      ExprList *pFuncArg;  /* Arguments to table-valued-function */
    } u1;
    Index *pIBIndex;  /* Index structure corresponding to u1.zIndexedBy */
  } a[1];             /* One entry for each identifier on the list */
};

/*
** Permitted values of the SrcList.a.jointype field
*/
#define JT_INNER     0x0001    /* Any kind of inner or cross join */
12330
12331
12332
12333
12334
12335
12336

12337
12338
12339
12340
12341
12342
12343
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375







+







** 
*/
#define NC_AllowAgg  0x0001  /* Aggregate functions are allowed here */
#define NC_HasAgg    0x0002  /* One or more aggregate functions seen */
#define NC_IsCheck   0x0004  /* True if resolving names in a CHECK constraint */
#define NC_InAggFunc 0x0008  /* True if analyzing arguments to an agg func */
#define NC_PartIdx   0x0010  /* True if resolving a partial index WHERE */
#define NC_IdxExpr   0x0020  /* True if resolving columns of CREATE INDEX */
#define NC_MinMaxAgg 0x1000  /* min/max aggregates seen.  See note above */

/*
** An instance of the following structure contains all information
** needed to generate code for a single SELECT statement.
**
** nLimit is set to -1 if there is no LIMIT clause.  nOffset is set to 0.
12599
12600
12601
12602
12603
12604
12605
12606

12607
12608
12609
12610
12611
12612
12613
12631
12632
12633
12634
12635
12636
12637

12638
12639
12640
12641
12642
12643
12644
12645







-
+







  int nTab;            /* Number of previously allocated VDBE cursors */
  int nMem;            /* Number of memory cells used so far */
  int nSet;            /* Number of sets used so far */
  int nOnce;           /* Number of OP_Once instructions so far */
  int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */
  int iFixedOp;        /* Never back out opcodes iFixedOp-1 or earlier */
  int ckBase;          /* Base register of data during check constraints */
  int iPartIdxTab;     /* Table corresponding to a partial index */
  int iSelfTab;        /* Table of an index whose exprs are being coded */
  int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
  int iCacheCnt;       /* Counter used to generate aColCache[].lru values */
  int nLabel;          /* Number of labels used */
  int *aLabel;         /* Space to hold the labels */
  struct yColCache {
    int iTable;           /* Table cursor number */
    i16 iColumn;          /* Table column number */
12969
12970
12971
12972
12973
12974
12975
12976

12977
12978
12979
12980
12981
12982
12983
13001
13002
13003
13004
13005
13006
13007

13008
13009
13010
13011
13012
13013
13014
13015







-
+







struct With {
  int nCte;                       /* Number of CTEs in the WITH clause */
  With *pOuter;                   /* Containing WITH clause, or NULL */
  struct Cte {                    /* For each CTE in the WITH clause.... */
    char *zName;                    /* Name of this CTE */
    ExprList *pCols;                /* List of explicit column names, or NULL */
    Select *pSelect;                /* The definition of this CTE */
    const char *zErr;               /* Error message for circular references */
    const char *zCteErr;            /* Error message for circular references */
  } a[1];
};

#ifdef SQLITE_DEBUG
/*
** An instance of the TreeView object is used for printing the content of
** data structures on sqlite3DebugPrintf() using a tree-like view.
13116
13117
13118
13119
13120
13121
13122

13123
13124
13125
13126
13127
13128
13129
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162







+








#ifndef SQLITE_MUTEX_OMIT
SQLITE_PRIVATE   sqlite3_mutex_methods const *sqlite3DefaultMutex(void);
SQLITE_PRIVATE   sqlite3_mutex_methods const *sqlite3NoopMutex(void);
SQLITE_PRIVATE   sqlite3_mutex *sqlite3MutexAlloc(int);
SQLITE_PRIVATE   int sqlite3MutexInit(void);
SQLITE_PRIVATE   int sqlite3MutexEnd(void);
SQLITE_PRIVATE   void sqlite3MemoryBarrier(void);
#endif

SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int);
SQLITE_PRIVATE void sqlite3StatusUp(int, int);
SQLITE_PRIVATE void sqlite3StatusDown(int, int);
SQLITE_PRIVATE void sqlite3StatusSet(int, int);

13183
13184
13185
13186
13187
13188
13189

13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201


13202
13203
13204
13205
13206
13207
13208
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244







+












+
+







SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index*, i16);
SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*);
SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
13236
13237
13238
13239
13240
13241
13242
13243

13244
13245
13246
13247
13248
13249
13250
13272
13273
13274
13275
13276
13277
13278

13279
13280
13281
13282
13283
13284
13285
13286







-
+








SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int);
SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*);
SQLITE_PRIVATE void sqlite3RowSetInsert(RowSet*, i64);
SQLITE_PRIVATE int sqlite3RowSetTest(RowSet*, int iBatch, i64);
SQLITE_PRIVATE int sqlite3RowSetNext(RowSet*, i64*);

SQLITE_PRIVATE void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
SQLITE_PRIVATE void sqlite3CreateView(Parse*,Token*,Token*,Token*,ExprList*,Select*,int,int);

#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
SQLITE_PRIVATE   int sqlite3ViewGetColumnNames(Parse*,Table*);
#else
# define sqlite3ViewGetColumnNames(A,B) 0
#endif

13266
13267
13268
13269
13270
13271
13272

13273
13274
13275
13276
13277
13278
13279
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316







+







SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
                                      Token*, Select*, Expr*, IdList*);
SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*);
SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**);
SQLITE_PRIVATE Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
13296
13297
13298
13299
13300
13301
13302

13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318

13319
13320

13321
13322
13323
13324
13325
13326
13327
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355

13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366







+















-
+


+







SQLITE_PRIVATE u64 sqlite3WhereOutputRowCount(WhereInfo*);
SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int);
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*);
SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
#define SQLITE_ECEL_DUP      0x01  /* Deep, not shallow copies */
#define SQLITE_ECEL_FACTOR   0x02  /* Factor out constant terms */
#define SQLITE_ECEL_REF      0x04  /* Use ExprList.u.x.iOrderByCol */
SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
13485
13486
13487
13488
13489
13490
13491
13492

13493
13494
13495
13496
13497
13498
13499
13524
13525
13526
13527
13528
13529
13530

13531
13532
13533
13534
13535
13536
13537
13538







-
+







#define putVarint32(A,B)  \
  (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
  sqlite3PutVarint((A),(B)))
#define getVarint    sqlite3GetVarint
#define putVarint    sqlite3PutVarint


SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3*, Index*);
SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...);
13557
13558
13559
13560
13561
13562
13563

13564
13565
13566
13567
13568
13569
13570
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610







+







SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*);
SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *, int, int);
SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
SQLITE_PRIVATE void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *);
SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*);
13665
13666
13667
13668
13669
13670
13671


13672
13673
13674
13675
13676
13677
13678
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720







+
+







SQLITE_PRIVATE    void sqlite3VtabUnlock(VTable *);
SQLITE_PRIVATE    void sqlite3VtabUnlockList(sqlite3*);
SQLITE_PRIVATE    int sqlite3VtabSavepoint(sqlite3 *, int, int);
SQLITE_PRIVATE    void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
SQLITE_PRIVATE    VTable *sqlite3GetVTable(sqlite3*, Table*);
#  define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
#endif
SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
SQLITE_PRIVATE void sqlite3VtabArgInit(Parse*);
SQLITE_PRIVATE void sqlite3VtabArgExtend(Parse*, Token*);
SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*);
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558








16559
16560
16561
16562
16563
16564
16565
16586
16587
16588
16589
16590
16591
16592








16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







** This function registered all of the above C functions as SQL
** functions.  This should be the only routine in this file with
** external linkage.
*/
SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void){
  static SQLITE_WSD FuncDef aDateTimeFuncs[] = {
#ifndef SQLITE_OMIT_DATETIME_FUNCS
    FUNCTION(julianday,        -1, 0, 0, juliandayFunc ),
    FUNCTION(date,             -1, 0, 0, dateFunc      ),
    FUNCTION(time,             -1, 0, 0, timeFunc      ),
    FUNCTION(datetime,         -1, 0, 0, datetimeFunc  ),
    FUNCTION(strftime,         -1, 0, 0, strftimeFunc  ),
    FUNCTION(current_time,      0, 0, 0, ctimeFunc     ),
    FUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
    FUNCTION(current_date,      0, 0, 0, cdateFunc     ),
    DFUNCTION(julianday,        -1, 0, 0, juliandayFunc ),
    DFUNCTION(date,             -1, 0, 0, dateFunc      ),
    DFUNCTION(time,             -1, 0, 0, timeFunc      ),
    DFUNCTION(datetime,         -1, 0, 0, datetimeFunc  ),
    DFUNCTION(strftime,         -1, 0, 0, strftimeFunc  ),
    DFUNCTION(current_time,      0, 0, 0, ctimeFunc     ),
    DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
    DFUNCTION(current_date,      0, 0, 0, cdateFunc     ),
#else
    STR_FUNCTION(current_time,      0, "%H:%M:%S",          0, currentTimeFunc),
    STR_FUNCTION(current_date,      0, "%Y-%m-%d",          0, currentTimeFunc),
    STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc),
#endif
  };
  int i;
19271
19272
19273
19274
19275
19276
19277

19278
19279
19280
19281
19282
19283
19284
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327







+







    pTo->xMutexEnd = pFrom->xMutexEnd;
    pTo->xMutexFree = pFrom->xMutexFree;
    pTo->xMutexEnter = pFrom->xMutexEnter;
    pTo->xMutexTry = pFrom->xMutexTry;
    pTo->xMutexLeave = pFrom->xMutexLeave;
    pTo->xMutexHeld = pFrom->xMutexHeld;
    pTo->xMutexNotheld = pFrom->xMutexNotheld;
    sqlite3MemoryBarrier();
    pTo->xMutexAlloc = pFrom->xMutexAlloc;
  }
  rc = sqlite3GlobalConfig.mutex.xMutexInit();

#ifdef SQLITE_DEBUG
  GLOBAL(int, mutexIsInit) = 1;
#endif
19677
19678
19679
19680
19681
19682
19683











19684
19685
19686
19687
19688
19689
19690
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744







+
+
+
+
+
+
+
+
+
+
+







static int pthreadMutexHeld(sqlite3_mutex *p){
  return (p->nRef!=0 && pthread_equal(p->owner, pthread_self()));
}
static int pthreadMutexNotheld(sqlite3_mutex *p){
  return p->nRef==0 || pthread_equal(p->owner, pthread_self())==0;
}
#endif

/*
** Try to provide a memory barrier operation, needed for initialization only.
*/
SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
#if defined(SQLITE_MEMORY_BARRIER)
  SQLITE_MEMORY_BARRIER;
#elif defined(__GNUC__)
  __sync_synchronize();
#endif
}

/*
** Initialize and deinitialize the mutex subsystem.
*/
static int pthreadMutexInit(void){ return SQLITE_OK; }
static int pthreadMutexEnd(void){ return SQLITE_OK; }

20339
20340
20341
20342
20343
20344
20345













20346
20347
20348
20349
20350
20351
20352
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419







+
+
+
+
+
+
+
+
+
+
+
+
+







}

static int winMutexNotheld(sqlite3_mutex *p){
  DWORD tid = GetCurrentThreadId();
  return winMutexNotheld2(p, tid);
}
#endif

/*
** Try to provide a memory barrier operation, needed for initialization only.
*/
SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
#if defined(SQLITE_MEMORY_BARRIER)
  SQLITE_MEMORY_BARRIER;
#elif defined(__GNUC__)
  __sync_synchronize();
#else
  MemoryBarrier();
#endif
}

/*
** Initialize and deinitialize the mutex subsystem.
*/
static sqlite3_mutex winMutex_staticMutexes[] = {
  SQLITE3_MUTEX_INITIALIZER,
  SQLITE3_MUTEX_INITIALIZER,
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707

20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726

20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738

20739
20740
20741
20742
20743
20744

20745
20746
20747
20748


20749
20750
20751

20752

20753
20754
20755
20756
20757



20758
20759


20760




20761
20762
20763













20764
20765
20766


20767
20768
20769






20770
20771
20772

20773

20774
20775
20776
20777
20778
20779
20780

20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799

20800
20801
20802




20803
20804

20805
20806
20807
20808
20809
20810
20811
20812
20760
20761
20762
20763
20764
20765
20766








20767


20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783

20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795

20796


20797



20798




20799
20800
20801
20802
20803
20804

20805
20806




20807
20808
20809


20810
20811
20812
20813
20814
20815
20816



20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829



20830
20831



20832
20833
20834
20835
20836
20837
20838
20839

20840

20841
20842
20843
20844
20845
20846
20847

20848
20849
20850
20851
20852
20853
20854
20855
20856
20857

20858
20859
20860
20861
20862
20863


20864
20865



20866
20867
20868
20869
20870

20871

20872
20873
20874
20875
20876
20877
20878







-
-
-
-
-
-
-
-
+
-
-
















-
+











-
+
-
-

-
-
-
+
-
-
-
-
+
+



+
-
+

-
-
-
-
+
+
+
-
-
+
+

+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
-
-
-
+
+
+
+
+
+


-
+
-
+






-
+









-






-
-

+
-
-
-
+
+
+
+

-
+
-







} ScratchFreeslot;

/*
** State information local to the memory allocation subsystem.
*/
static SQLITE_WSD struct Mem0Global {
  sqlite3_mutex *mutex;         /* Mutex to serialize access */

  /*
  ** The alarm callback and its arguments.  The mem0.mutex lock will
  ** be held while the callback is running.  Recursive calls into
  ** the memory subsystem are allowed, but no new callbacks will be
  ** issued.
  */
  sqlite3_int64 alarmThreshold;
  sqlite3_int64 alarmThreshold;  /* The soft heap limit */
  void (*alarmCallback)(void*, sqlite3_int64,int);
  void *alarmArg;

  /*
  ** Pointers to the end of sqlite3GlobalConfig.pScratch memory
  ** (so that a range test can be used to determine if an allocation
  ** being freed came from pScratch) and a pointer to the list of
  ** unused scratch allocations.
  */
  void *pScratchEnd;
  ScratchFreeslot *pScratchFree;
  u32 nScratchFree;

  /*
  ** True if heap is nearly "full" where "full" is defined by the
  ** sqlite3_soft_heap_limit() setting.
  */
  int nearlyFull;
} mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
} mem0 = { 0, 0, 0, 0, 0, 0 };

#define mem0 GLOBAL(struct Mem0Global, mem0)

/*
** Return the memory allocator mutex. sqlite3_status() needs it.
*/
SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void){
  return mem0.mutex;
}

/*
** This routine runs when the memory allocator sees that the
** Return the amount of memory currently in use.
** total memory allocation is about to exceed the soft heap
** limit.
*/
static void softHeapLimitEnforcer(
  void *NotUsed, 
  sqlite3_int64 NotUsed2,
static sqlite3_int64 memInUse(void){
  int allocSize
){
  UNUSED_PARAMETER2(NotUsed, NotUsed2);
  sqlite3_release_memory(allocSize);
  assert( sqlite3_mutex_held(mem0.mutex) );
  return sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
}

/*
** Called when the soft heap limit is exceeded for an allocation
** Change the alarm callback
** of nBytes.
*/
static int sqlite3MemoryAlarm(
  void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
  void *pArg,
  sqlite3_int64 iThreshold
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
static void sqlite3HeapLimitExceeded(int nByte){
  sqlite3_int64 excess = memInUse() + nByte - mem0.alarmThreshold;
){
  sqlite3_int64 nUsed;
  sqlite3_mutex_leave(mem0.mutex);
  sqlite3_release_memory((int)(excess & 0x7fffffff));
  sqlite3_mutex_enter(mem0.mutex);
}
#else
# define sqlite3HeapLimitExceeded(X)  /* no-op */
#endif
  mem0.alarmCallback = xCallback;
  mem0.alarmArg = pArg;
  mem0.alarmThreshold = iThreshold;

/*
** Check to see if increasing the total memory usage by nNew bytes
** will exceed the soft heap limit.  
**
** If the soft heap limit is exceeded, set the mem0.nearlyFull flag
** and invoke sqlite3HeapLimitExceeded() to try to free up some
** memory.
*/
static void sqlite3CheckSoftHeapLimit(int nNew){
  assert( sqlite3_mutex_held(mem0.mutex) );
  if( mem0.alarmThreshold>0 ){
    if( mem0.alarmThreshold-nNew >= memInUse() ){
  nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
  mem0.nearlyFull = (iThreshold>0 && iThreshold<=nUsed);
  sqlite3_mutex_leave(mem0.mutex);
      mem0.nearlyFull = 1;
      sqlite3HeapLimitExceeded(nNew);
  return SQLITE_OK;
}

    }else{
      mem0.nearlyFull = 0;
    }
  }
}

#ifndef SQLITE_OMIT_DEPRECATED
/*
** Deprecated external interface.  Internal/core SQLite code
** Deprecated external interface.  First deprecated 2007-11-05.  Changed
** should call sqlite3MemoryAlarm.
** into a no-op on 2015-09-02.
*/
SQLITE_API int SQLITE_STDCALL sqlite3_memory_alarm(
  void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
  void *pArg,
  sqlite3_int64 iThreshold
){
  return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
  return SQLITE_OK;
}
#endif

/*
** Set the soft heap-size limit for the library. Passing a zero or 
** negative value indicates no limit.
*/
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 n){
  sqlite3_int64 priorLimit;
  sqlite3_int64 excess;
#ifndef SQLITE_OMIT_AUTOINIT
  int rc = sqlite3_initialize();
  if( rc ) return -1;
#endif
  sqlite3_mutex_enter(mem0.mutex);
  priorLimit = mem0.alarmThreshold;
  sqlite3_mutex_leave(mem0.mutex);
  if( n<0 ) return priorLimit;
  if( n>0 ){
    mem0.alarmThreshold = n;
    sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, n);
  }else{
    sqlite3MemoryAlarm(0, 0, 0);
    sqlite3CheckSoftHeapLimit(0);
  }else if( n==0 ){
    mem0.alarmThreshold = 0;
    mem0.nearlyFull = 0;
  }
  excess = sqlite3_memory_used() - n;
  sqlite3_mutex_leave(mem0.mutex);
  if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
  return priorLimit;
}
SQLITE_API void SQLITE_STDCALL sqlite3_soft_heap_limit(int n){
  if( n<0 ) n = 0;
  sqlite3_soft_heap_limit64(n);
}

20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929

20930
20931
20932
20933
20934
20935
20936
20937


20938
20939
20940
20941
20942
20943
20944
20955
20956
20957
20958
20959
20960
20961



















20962
20963
20964
20965
20966
20967
20968
20969
20970
20971





20972




20973
20974


20975
20976
20977
20978
20979
20980
20981
20982
20983







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










-
-
-
-
-
+
-
-
-
-


-
-
+
+







*/
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag){
  sqlite3_int64 res, mx;
  sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, resetFlag);
  return mx;
}

/*
** Trigger the alarm 
*/
static void sqlite3MallocAlarm(int nByte){
  void (*xCallback)(void*,sqlite3_int64,int);
  sqlite3_int64 nowUsed;
  void *pArg;
  if( mem0.alarmCallback==0 ) return;
  xCallback = mem0.alarmCallback;
  nowUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
  pArg = mem0.alarmArg;
  mem0.alarmCallback = 0;
  sqlite3_mutex_leave(mem0.mutex);
  xCallback(pArg, nowUsed, nByte);
  sqlite3_mutex_enter(mem0.mutex);
  mem0.alarmCallback = xCallback;
  mem0.alarmArg = pArg;
}

/*
** Do a memory allocation with statistics and alarms.  Assume the
** lock is already held.
*/
static int mallocWithAlarm(int n, void **pp){
  int nFull;
  void *p;
  assert( sqlite3_mutex_held(mem0.mutex) );
  nFull = sqlite3GlobalConfig.m.xRoundup(n);
  sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
  if( mem0.alarmCallback!=0 ){
    sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
    if( nUsed >= mem0.alarmThreshold - nFull ){
      mem0.nearlyFull = 1;
      sqlite3MallocAlarm(nFull);
  sqlite3CheckSoftHeapLimit(nFull);
    }else{
      mem0.nearlyFull = 0;
    }
  }
  p = sqlite3GlobalConfig.m.xMalloc(nFull);
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  if( p==0 && mem0.alarmCallback ){
    sqlite3MallocAlarm(nFull);
  if( p==0 && mem0.alarmThreshold ){
    sqlite3HeapLimitExceeded(nFull);
    p = sqlite3GlobalConfig.m.xMalloc(nFull);
  }
#endif
  if( p ){
    nFull = sqlite3MallocSize(p);
    sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull);
    sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
21104
21105
21106
21107
21108
21109
21110


21111
21112
21113



21114
21115
21116
21117
21118
21119
21120
21121


21122
21123




21124
21125
21126
21127
21128
21129
21130
21143
21144
21145
21146
21147
21148
21149
21150
21151



21152
21153
21154





21155
21156
21157
21158
21159


21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170







+
+
-
-
-
+
+
+
-
-
-
-
-



+
+
-
-
+
+
+
+







** sqlite3Malloc() or sqlite3_malloc().
*/
SQLITE_PRIVATE int sqlite3MallocSize(void *p){
  assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
  return sqlite3GlobalConfig.m.xSize(p);
}
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
  if( db==0 || !isLookaside(db,p) ){
#if SQLITE_DEBUG
  if( db==0 ){
    assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
    assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
    if( db==0 ){
      assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
      assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
    return sqlite3MallocSize(p);
  }else{
    assert( sqlite3_mutex_held(db->mutex) );
    if( isLookaside(db, p) ){
      return db->lookaside.sz;
    }else{
      assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
      assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
    }
#endif
      return sqlite3GlobalConfig.m.xSize(p);
    }
    return sqlite3GlobalConfig.m.xSize(p);
  }else{
    assert( sqlite3_mutex_held(db->mutex) );
    return db->lookaside.sz;
  }
}
SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void *p){
  assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
  assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
  return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
}
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221

21222
21223

21224
21225


21226
21227

21228
21229
21230
21231
21232
21233
21234
21252
21253
21254
21255
21256
21257
21258



21259

21260
21261


21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273







-
-
-
+
-

+
-
-
+
+


+







  nNew = sqlite3GlobalConfig.m.xRoundup((int)nBytes);
  if( nOld==nNew ){
    pNew = pOld;
  }else if( sqlite3GlobalConfig.bMemstat ){
    sqlite3_mutex_enter(mem0.mutex);
    sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
    nDiff = nNew - nOld;
    if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 
          mem0.alarmThreshold-nDiff ){
      sqlite3MallocAlarm(nDiff);
    sqlite3CheckSoftHeapLimit(nDiff);
    }
    pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
    if( pNew==0 && mem0.alarmCallback ){
      sqlite3MallocAlarm((int)nBytes);
    if( pNew==0 && mem0.alarmThreshold ){
      sqlite3HeapLimitExceeded((int)nBytes);
      pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
    }
#endif
    if( pNew ){
      nNew = sqlite3MallocSize(pNew);
      sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
    }
    sqlite3_mutex_leave(mem0.mutex);
  }else{
    pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
21931
21932
21933
21934
21935
21936
21937
21938
21939

21940
21941
21942
21943
21944
21945
21946
21947


21948
21949
21950

21951
21952

21953
21954
21955
21956
21957
21958
21959
21970
21971
21972
21973
21974
21975
21976


21977
21978
21979
21980
21981
21982



21983
21984



21985


21986
21987
21988
21989
21990
21991
21992
21993







-
-
+





-
-
-
+
+
-
-
-
+
-
-
+







          bufpt = "NaN";
          length = 3;
          break;
        }
        if( realvalue>0.0 ){
          LONGDOUBLE_TYPE scale = 1.0;
          while( realvalue>=1e100*scale && exp<=350 ){ scale *= 1e100;exp+=100;}
          while( realvalue>=1e64*scale && exp<=350 ){ scale *= 1e64; exp+=64; }
          while( realvalue>=1e8*scale && exp<=350 ){ scale *= 1e8; exp+=8; }
          while( realvalue>=1e10*scale && exp<=350 ){ scale *= 1e10; exp+=10; }
          while( realvalue>=10.0*scale && exp<=350 ){ scale *= 10.0; exp++; }
          realvalue /= scale;
          while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; }
          while( realvalue<1.0 ){ realvalue *= 10.0; exp--; }
          if( exp>350 ){
            if( prefix=='-' ){
              bufpt = "-Inf";
            }else if( prefix=='+' ){
            bufpt = buf;
            buf[0] = prefix;
              bufpt = "+Inf";
            }else{
              bufpt = "Inf";
            memcpy(buf+(prefix!=0),"Inf",4);
            }
            length = sqlite3Strlen30(bufpt);
            length = 3+(prefix!=0);
            break;
          }
        }
        bufpt = buf;
        /*
        ** If the field type is etGENERIC, then convert to either etEXP
        ** or etFLOAT, as appropriate.
22094
22095
22096
22097
22098
22099
22100

22101
22102
22103
22104
22105
22106

22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117



22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136

22137
22138
22139
22140
22141
22142
22143
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140

22141
22142
22143
22144
22145
22146
22147
22148
22149



22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170

22171
22172
22173
22174
22175
22176
22177
22178







+





-
+








-
-
-
+
+
+


















-
+







        buf[0] = c;
        bufpt = buf;
        break;
      case etSTRING:
      case etDYNSTRING:
        if( bArgList ){
          bufpt = getTextArg(pArgList);
          xtype = etSTRING;
        }else{
          bufpt = va_arg(ap,char*);
        }
        if( bufpt==0 ){
          bufpt = "";
        }else if( xtype==etDYNSTRING && !bArgList ){
        }else if( xtype==etDYNSTRING ){
          zExtra = bufpt;
        }
        if( precision>=0 ){
          for(length=0; length<precision && bufpt[length]; length++){}
        }else{
          length = sqlite3Strlen30(bufpt);
        }
        break;
      case etSQLESCAPE:
      case etSQLESCAPE2:
      case etSQLESCAPE3: {
      case etSQLESCAPE:           /* Escape ' characters */
      case etSQLESCAPE2:          /* Escape ' and enclose in '...' */
      case etSQLESCAPE3: {        /* Escape " characters */
        int i, j, k, n, isnull;
        int needQuote;
        char ch;
        char q = ((xtype==etSQLESCAPE3)?'"':'\'');   /* Quote character */
        char *escarg;

        if( bArgList ){
          escarg = getTextArg(pArgList);
        }else{
          escarg = va_arg(ap,char*);
        }
        isnull = escarg==0;
        if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
        k = precision;
        for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
          if( ch==q )  n++;
        }
        needQuote = !isnull && xtype==etSQLESCAPE2;
        n += i + 1 + needQuote*2;
        n += i + 3;
        if( n>etBUFSIZE ){
          bufpt = zExtra = sqlite3Malloc( n );
          if( bufpt==0 ){
            setStrAccumError(pAccum, STRACCUM_NOMEM);
            return;
          }
        }else{
22525
22526
22527
22528
22529
22530
22531
22532


22533
22534
22535
22536
22537
22538
22539
22560
22561
22562
22563
22564
22565
22566

22567
22568
22569
22570
22571
22572
22573
22574
22575







-
+
+







  fprintf(stdout,"%s", zBuf);
  fflush(stdout);
}
#endif


/*
** variable-argument wrapper around sqlite3VXPrintf().
** variable-argument wrapper around sqlite3VXPrintf().  The bFlags argument
** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats.
*/
SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
  va_list ap;
  va_start(ap,zFormat);
  sqlite3VXPrintf(p, bFlags, zFormat, ap);
  va_end(ap);
}
22623
22624
22625
22626
22627
22628
22629

22630

22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
















22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710








































































22711
22712
22713



22714
22715
22716
22717
22718
22719
22720
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668











22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684





































































22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756



22757
22758
22759
22760
22761
22762
22763
22764
22765
22766







+

+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+









/*
** Generate a human-readable description of a the Select object.
*/
SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
  int n = 0;
  int cnt = 0;
  pView = sqlite3TreeViewPush(pView, moreToFollow);
  do{
  sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x",
    ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
    ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags
  );
  if( p->pSrc && p->pSrc->nSrc ) n++;
  if( p->pWhere ) n++;
  if( p->pGroupBy ) n++;
  if( p->pHaving ) n++;
  if( p->pOrderBy ) n++;
  if( p->pLimit ) n++;
  if( p->pOffset ) n++;
    sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x",
      ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
      ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags
    );
    if( cnt++ ) sqlite3TreeViewPop(pView);
    if( p->pPrior ){
      n = 1000;
    }else{
      n = 0;
      if( p->pSrc && p->pSrc->nSrc ) n++;
      if( p->pWhere ) n++;
      if( p->pGroupBy ) n++;
      if( p->pHaving ) n++;
      if( p->pOrderBy ) n++;
      if( p->pLimit ) n++;
      if( p->pOffset ) n++;
  if( p->pPrior ) n++;
  sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
  if( p->pSrc && p->pSrc->nSrc ){
    int i;
    pView = sqlite3TreeViewPush(pView, (n--)>0);
    sqlite3TreeViewLine(pView, "FROM");
    for(i=0; i<p->pSrc->nSrc; i++){
      struct SrcList_item *pItem = &p->pSrc->a[i];
      StrAccum x;
      char zLine[100];
      sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
      sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
      if( pItem->zDatabase ){
        sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
      }else if( pItem->zName ){
        sqlite3XPrintf(&x, 0, " %s", pItem->zName);
      }
      if( pItem->pTab ){
        sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName);
      }
      if( pItem->zAlias ){
        sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias);
      }
      if( pItem->jointype & JT_LEFT ){
        sqlite3XPrintf(&x, 0, " LEFT-JOIN");
      }
      sqlite3StrAccumFinish(&x);
      sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1); 
      if( pItem->pSelect ){
        sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
      }
      sqlite3TreeViewPop(pView);
    }
    sqlite3TreeViewPop(pView);
  }
  if( p->pWhere ){
    sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
    sqlite3TreeViewExpr(pView, p->pWhere, 0);
    sqlite3TreeViewPop(pView);
  }
  if( p->pGroupBy ){
    sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
  }
  if( p->pHaving ){
    sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
    sqlite3TreeViewExpr(pView, p->pHaving, 0);
    sqlite3TreeViewPop(pView);
  }
  if( p->pOrderBy ){
    sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
  }
  if( p->pLimit ){
    sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
    sqlite3TreeViewExpr(pView, p->pLimit, 0);
    sqlite3TreeViewPop(pView);
  }
  if( p->pOffset ){
    sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
    sqlite3TreeViewExpr(pView, p->pOffset, 0);
    sqlite3TreeViewPop(pView);
  }
  if( p->pPrior ){
    const char *zOp = "UNION";
    switch( p->op ){
      case TK_ALL:         zOp = "UNION ALL";  break;
      case TK_INTERSECT:   zOp = "INTERSECT";  break;
      case TK_EXCEPT:      zOp = "EXCEPT";     break;
    }
    sqlite3TreeViewItem(pView, zOp, (n--)>0);
    }
    sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
    if( p->pSrc && p->pSrc->nSrc ){
      int i;
      pView = sqlite3TreeViewPush(pView, (n--)>0);
      sqlite3TreeViewLine(pView, "FROM");
      for(i=0; i<p->pSrc->nSrc; i++){
        struct SrcList_item *pItem = &p->pSrc->a[i];
        StrAccum x;
        char zLine[100];
        sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
        sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
        if( pItem->zDatabase ){
          sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
        }else if( pItem->zName ){
          sqlite3XPrintf(&x, 0, " %s", pItem->zName);
        }
        if( pItem->pTab ){
          sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName);
        }
        if( pItem->zAlias ){
          sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias);
        }
        if( pItem->fg.jointype & JT_LEFT ){
          sqlite3XPrintf(&x, 0, " LEFT-JOIN");
        }
        sqlite3StrAccumFinish(&x);
        sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1); 
        if( pItem->pSelect ){
          sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
        }
        if( pItem->fg.isTabFunc ){
          sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
        }
        sqlite3TreeViewPop(pView);
      }
      sqlite3TreeViewPop(pView);
    }
    if( p->pWhere ){
      sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
      sqlite3TreeViewExpr(pView, p->pWhere, 0);
      sqlite3TreeViewPop(pView);
    }
    if( p->pGroupBy ){
      sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
    }
    if( p->pHaving ){
      sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
      sqlite3TreeViewExpr(pView, p->pHaving, 0);
      sqlite3TreeViewPop(pView);
    }
    if( p->pOrderBy ){
      sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
    }
    if( p->pLimit ){
      sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
      sqlite3TreeViewExpr(pView, p->pLimit, 0);
      sqlite3TreeViewPop(pView);
    }
    if( p->pOffset ){
      sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
      sqlite3TreeViewExpr(pView, p->pOffset, 0);
      sqlite3TreeViewPop(pView);
    }
    if( p->pPrior ){
      const char *zOp = "UNION";
      switch( p->op ){
        case TK_ALL:         zOp = "UNION ALL";  break;
        case TK_INTERSECT:   zOp = "INTERSECT";  break;
        case TK_EXCEPT:      zOp = "EXCEPT";     break;
      }
      sqlite3TreeViewItem(pView, zOp, 1);
    sqlite3TreeViewSelect(pView, p->pPrior, 0);
    sqlite3TreeViewPop(pView);
  }
    }
    p = p->pPrior;
  }while( p!=0 );
  sqlite3TreeViewPop(pView);
}

/*
** Generate a human-readable explanation of an expression tree.
*/
SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22827
22828
22829
22830
22831
22832
22833





22834
22835
22836
22837
22838
22839
22840







-
-
-
-
-







                          pExpr->u.zToken, pExpr->iColumn);
      break;
    }
    case TK_REGISTER: {
      sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
      break;
    }
    case TK_AS: {
      sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
      sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
      break;
    }
    case TK_ID: {
      sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
      break;
    }
#ifndef SQLITE_OMIT_CAST
    case TK_CAST: {
      /* Expressions of the form:   CAST(pLeft AS token) */
22960
22961
22962
22963
22964
22965
22966





22967

22968
22969
22970
22971
22972
22973
22974
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021







+
+
+
+
+

+







  pView = sqlite3TreeViewPush(pView, moreToFollow);
  if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
  if( pList==0 ){
    sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
  }else{
    sqlite3TreeViewLine(pView, "%s", zLabel);
    for(i=0; i<pList->nExpr; i++){
      int j = pList->a[i].u.x.iOrderByCol;
      if( j ){
        sqlite3TreeViewPush(pView, 0);
        sqlite3TreeViewLine(pView, "iOrderByCol=%d", j);
      }
      sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
      if( j ) sqlite3TreeViewPop(pView);
    }
  }
  sqlite3TreeViewPop(pView);
}

#endif /* SQLITE_DEBUG */

24975
24976
24977
24978
24979
24980
24981
24982

24983
24984
24985

24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998

24999

25000
25001
25002

25003

25004
25005
25006
25007
25008
25009
25010
25022
25023
25024
25025
25026
25027
25028

25029



25030

25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043

25044
25045
25046
25047
25048

25049
25050
25051
25052
25053
25054
25055
25056







-
+
-
-
-
+
-












+
-
+



+
-
+







}

/*
** Return the number of bytes that will be needed to store the given
** 64-bit integer.
*/
SQLITE_PRIVATE int sqlite3VarintLen(u64 v){
  int i = 0;
  int i;
  do{
    i++;
    v >>= 7;
  for(i=1; (v >>= 7)!=0; i++){ assert( i<9 ); }
  }while( v!=0 && ALWAYS(i<9) );
  return i;
}


/*
** Read or write a four-byte big-endian integer value.
*/
SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){
#if SQLITE_BYTEORDER==4321
  u32 x;
  memcpy(&x,p,4);
  return x;
#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
#elif SQLITE_BYTEORDER==1234 && defined(__GNUC__) && GCC_VERSION>=4003000
    && defined(__GNUC__) && GCC_VERSION>=4003000
  u32 x;
  memcpy(&x,p,4);
  return __builtin_bswap32(x);
#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
#elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300
    && defined(_MSC_VER) && _MSC_VER>=1300
  u32 x;
  memcpy(&x,p,4);
  return _byteswap_ulong(x);
#else
  testcase( p[0]&0x80 );
  return ((unsigned)p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
#endif
29101
29102
29103
29104
29105
29106
29107
29108
29109
29110
29111
29112
29113
29114
29115
29147
29148
29149
29150
29151
29152
29153

29154
29155
29156
29157
29158
29159
29160







-







  int prior = 0;
#if (!defined(USE_PREAD) && !defined(USE_PREAD64))
  i64 newOffset;
#endif
  TIMER_START;
  assert( cnt==(cnt&0x1ffff) );
  assert( id->h>2 );
  cnt &= 0x1ffff;
  do{
#if defined(USE_PREAD)
    got = osPread(id->h, pBuf, cnt, offset);
    SimulateIOError( got = -1 );
#elif defined(USE_PREAD64)
    got = osPread64(id->h, pBuf, cnt, offset);
    SimulateIOError( got = -1 );
29318
29319
29320
29321
29322
29323
29324
29325
29326


29327
29328
29329
29330
29331
29332
29333
29334

29335
29336
29337
29338
29339
29340
29341
29363
29364
29365
29366
29367
29368
29369


29370
29371
29372
29373
29374
29375
29376
29377
29378

29379
29380
29381
29382
29383
29384
29385
29386







-
-
+
+







-
+







      memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, nCopy);
      pBuf = &((u8 *)pBuf)[nCopy];
      amt -= nCopy;
      offset += nCopy;
    }
  }
#endif

  while( amt>0 && (wrote = seekAndWrite(pFile, offset, pBuf, amt))>0 ){
 
  while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){
    amt -= wrote;
    offset += wrote;
    pBuf = &((char*)pBuf)[wrote];
  }
  SimulateIOError(( wrote=(-1), amt=1 ));
  SimulateDiskfullError(( wrote=0, amt=1 ));

  if( amt>0 ){
  if( amt>wrote ){
    if( wrote<0 && pFile->lastErrno!=ENOSPC ){
      /* lastErrno set by seekAndWrite */
      return SQLITE_IOERR_WRITE;
    }else{
      storeLastErrno(pFile, 0); /* not a system error */
      return SQLITE_FULL;
    }
39796
39797
39798
39799
39800
39801
39802
39803

39804
39805
39806
39807
39808
39809
39810
39841
39842
39843
39844
39845
39846
39847

39848
39849
39850
39851
39852
39853
39854
39855







-
+








/*
** A complete page cache is an instance of this structure.
*/
struct PCache {
  PgHdr *pDirty, *pDirtyTail;         /* List of dirty pages in LRU order */
  PgHdr *pSynced;                     /* Last synced page in dirty page list */
  int nRef;                           /* Number of referenced pages */
  int nRefSum;                        /* Sum of ref counts over all pages */
  int szCache;                        /* Configured cache size */
  int szPage;                         /* Size of every page in this cache */
  int szExtra;                        /* Size of extra space for each page */
  u8 bPurgeable;                      /* True if pages are on backing store */
  u8 eCreate;                         /* eCreate value for for xFetch() */
  int (*xStress)(void*,PgHdr*);       /* Call to try make a page clean */
  void *pStress;                      /* Argument to xStress */
39961
39962
39963
39964
39965
39966
39967
39968

39969
39970
39971
39972
39973
39974
39975
40006
40007
40008
40009
40010
40011
40012

40013
40014
40015
40016
40017
40018
40019
40020







-
+







}

/*
** Change the page size for PCache object. The caller must ensure that there
** are no outstanding page references when this function is called.
*/
SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
  assert( pCache->nRef==0 && pCache->pDirty==0 );
  assert( pCache->nRefSum==0 && pCache->pDirty==0 );
  if( pCache->szPage ){
    sqlite3_pcache *pNew;
    pNew = sqlite3GlobalConfig.pcache2.xCreate(
                szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
                pCache->bPurgeable
    );
    if( pNew==0 ) return SQLITE_NOMEM;
40128
40129
40130
40131
40132
40133
40134
40135
40136

40137
40138
40139
40140
40141
40142
40143
40144
40145
40146
40147
40148
40149
40150


40151
40152
40153
40154
40155
40156
40157
40158
40159
40160
40161
40162
40163
40164
40165

40166
40167
40168
40169
40170
40171
40172
40173
40174
40175
40176
40177
40178

40179
40180
40181
40182
40183
40184
40185
40173
40174
40175
40176
40177
40178
40179


40180

40181
40182
40183
40184
40185
40186
40187
40188
40189
40190



40191
40192
40193
40194
40195
40196
40197
40198
40199
40200
40201
40202
40203
40204
40205
40206
40207
40208
40209
40210
40211
40212
40213
40214
40215
40216
40217
40218
40219
40220

40221
40222
40223
40224
40225
40226
40227
40228







-
-
+
-










-
-
-
+
+















+












-
+








  assert( pPage!=0 );
  pPgHdr = (PgHdr *)pPage->pExtra;

  if( !pPgHdr->pPage ){
    return pcacheFetchFinishWithInit(pCache, pgno, pPage);
  }
  if( 0==pPgHdr->nRef ){
    pCache->nRef++;
  pCache->nRefSum++;
  }
  pPgHdr->nRef++;
  return pPgHdr;
}

/*
** Decrement the reference count on a page. If the page is clean and the
** reference count drops to 0, then it is made eligible for recycling.
*/
SQLITE_PRIVATE void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){
  assert( p->nRef>0 );
  p->nRef--;
  if( p->nRef==0 ){
    p->pCache->nRef--;
  p->pCache->nRefSum--;
  if( (--p->nRef)==0 ){
    if( p->flags&PGHDR_CLEAN ){
      pcacheUnpin(p);
    }else if( p->pDirtyPrev!=0 ){
      /* Move the page to the head of the dirty list. */
      pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
    }
  }
}

/*
** Increase the reference count of a supplied page by 1.
*/
SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){
  assert(p->nRef>0);
  p->nRef++;
  p->pCache->nRefSum++;
}

/*
** Drop a page from the cache. There must be exactly one reference to the
** page. This function deletes that reference, so after it returns the
** page pointed to by p is invalid.
*/
SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
  assert( p->nRef==1 );
  if( p->flags&PGHDR_DIRTY ){
    pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
  }
  p->pCache->nRef--;
  p->pCache->nRefSum--;
  sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
}

/*
** Make sure the page is marked as dirty. If it isn't dirty already,
** make it so.
*/
40267
40268
40269
40270
40271
40272
40273
40274

40275
40276
40277
40278

40279
40280
40281
40282
40283
40284
40285
40310
40311
40312
40313
40314
40315
40316

40317
40318
40319
40320

40321
40322
40323
40324
40325
40326
40327
40328







-
+



-
+







      */
      assert( p->pgno>0 );
      if( ALWAYS(p->pgno>pgno) ){
        assert( p->flags&PGHDR_DIRTY );
        sqlite3PcacheMakeClean(p);
      }
    }
    if( pgno==0 && pCache->nRef ){
    if( pgno==0 && pCache->nRefSum ){
      sqlite3_pcache_page *pPage1;
      pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
      if( ALWAYS(pPage1) ){  /* Page 1 is always available in cache, because
                             ** pCache->nRef>0 */
                             ** pCache->nRefSum>0 */
        memset(pPage1->pBuf, 0, pCache->szPage);
        pgno = 1;
      }
    }
    sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
  }
}
40377
40378
40379
40380
40381
40382
40383
40384




40385
40386
40387

40388
40389
40390
40391
40392
40393
40394
40420
40421
40422
40423
40424
40425
40426

40427
40428
40429
40430
40431
40432

40433
40434
40435
40436
40437
40438
40439
40440







-
+
+
+
+


-
+







  for(p=pCache->pDirty; p; p=p->pDirtyNext){
    p->pDirty = p->pDirtyNext;
  }
  return pcacheSortDirtyList(pCache->pDirty);
}

/* 
** Return the total number of referenced pages held by the cache.
** Return the total number of references to all pages held by the cache.
**
** This is not the total number of pages referenced, but the sum of the
** reference count for all pages.
*/
SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
  return pCache->nRef;
  return pCache->nRefSum;
}

/*
** Return the number of references to the page supplied as an argument.
*/
SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr *p){
  return p->nRef;
40515
40516
40517
40518
40519
40520
40521
40522

40523
40524
40525
40526
40527
40528
40529
40530
40531
40532
40533
40534
40535
40536
40537
40538
40539
40540
40541
40542


















40543
40544
40545
40546
40547
40548
40549
40561
40562
40563
40564
40565
40566
40567

40568
40569
40570
40571
40572
40573
40574
40575
40576
40577
40578
40579
40580
40581
40582
40583
40584
40585
40586
40587
40588
40589
40590
40591
40592
40593
40594
40595
40596
40597
40598
40599
40600
40601
40602
40603
40604
40605
40606
40607
40608
40609
40610
40611
40612
40613







-
+




















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







**         SQLITE_CONFIG_PAGECACHE.
**    (3)  PCache-local bulk allocation.
**
** The third case is a chunk of heap memory (defaulting to 100 pages worth)
** that is allocated when the page cache is created.  The size of the local
** bulk allocation can be adjusted using 
**
**     sqlite3_config(SQLITE_CONFIG_PCACHE, 0, 0, N).
**     sqlite3_config(SQLITE_CONFIG_PAGECACHE, 0, 0, N).
**
** If N is positive, then N pages worth of memory are allocated using a single
** sqlite3Malloc() call and that memory is used for the first N pages allocated.
** Or if N is negative, then -1024*N bytes of memory are allocated and used
** for as many pages as can be accomodated.
**
** Only one of (2) or (3) can be used.  Once the memory available to (2) or
** (3) is exhausted, subsequent allocations fail over to the general-purpose
** memory allocator (1).
**
** Earlier versions of SQLite used only methods (1) and (2).  But experiments
** show that method (3) with N==100 provides about a 5% performance boost for
** common workloads.
*/
/* #include "sqliteInt.h" */

typedef struct PCache1 PCache1;
typedef struct PgHdr1 PgHdr1;
typedef struct PgFreeslot PgFreeslot;
typedef struct PGroup PGroup;

/*
** Each cache entry is represented by an instance of the following 
** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
** PgHdr1.pCache->szPage bytes is allocated directly before this structure 
** in memory.
*/
struct PgHdr1 {
  sqlite3_pcache_page page;      /* Base class. Must be first. pBuf & pExtra */
  unsigned int iKey;             /* Key value (page number) */
  u8 isPinned;                   /* Page in use, not on the LRU list */
  u8 isBulkLocal;                /* This page from bulk local storage */
  u8 isAnchor;                   /* This is the PGroup.lru element */
  PgHdr1 *pNext;                 /* Next in hash table chain */
  PCache1 *pCache;               /* Cache that currently owns this page */
  PgHdr1 *pLruNext;              /* Next in LRU list of unpinned pages */
  PgHdr1 *pLruPrev;              /* Previous in LRU list of unpinned pages */
};

/* Each page cache (or PCache) belongs to a PGroup.  A PGroup is a set 
** of one or more PCaches that are able to recycle each other's unpinned
** pages when they are under memory pressure.  A PGroup is an instance of
** the following object.
**
** This page cache implementation works in one of two modes:
40565
40566
40567
40568
40569
40570
40571
40572

40573
40574
40575
40576
40577
40578
40579
40629
40630
40631
40632
40633
40634
40635

40636
40637
40638
40639
40640
40641
40642
40643







-
+







*/
struct PGroup {
  sqlite3_mutex *mutex;          /* MUTEX_STATIC_LRU or NULL */
  unsigned int nMaxPage;         /* Sum of nMax for purgeable caches */
  unsigned int nMinPage;         /* Sum of nMin for purgeable caches */
  unsigned int mxPinned;         /* nMaxpage + 10 - nMinPage */
  unsigned int nCurrentPage;     /* Number of purgeable pages allocated */
  PgHdr1 *pLruHead, *pLruTail;   /* LRU list of unpinned pages */
  PgHdr1 lru;                    /* The beginning and end of the LRU list */
};

/* Each page cache is an instance of the following object.  Every
** open database file (including each in-memory database and each
** temporary or transient database) has a single page cache which
** is an instance of this object.
**
40603
40604
40605
40606
40607
40608
40609
40610
40611
40612
40613
40614
40615
40616
40617
40618
40619
40620
40621
40622
40623
40624
40625
40626
40627
40628
40629
40630
40631
40632
40633
40667
40668
40669
40670
40671
40672
40673

















40674
40675
40676
40677
40678
40679
40680







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







  unsigned int nPage;                 /* Total number of pages in apHash */
  unsigned int nHash;                 /* Number of slots in apHash[] */
  PgHdr1 **apHash;                    /* Hash table for fast lookup by key */
  PgHdr1 *pFree;                      /* List of unused pcache-local pages */
  void *pBulk;                        /* Bulk memory used by pcache-local */
};

/*
** Each cache entry is represented by an instance of the following 
** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
** PgHdr1.pCache->szPage bytes is allocated directly before this structure 
** in memory.
*/
struct PgHdr1 {
  sqlite3_pcache_page page;
  unsigned int iKey;             /* Key value (page number) */
  u8 isPinned;                   /* Page in use, not on the LRU list */
  u8 isBulkLocal;                /* This page from bulk local storage */
  PgHdr1 *pNext;                 /* Next in hash table chain */
  PCache1 *pCache;               /* Cache that currently owns this page */
  PgHdr1 *pLruNext;              /* Next in LRU list of unpinned pages */
  PgHdr1 *pLruPrev;              /* Previous in LRU list of unpinned pages */
};

/*
** Free slots in the allocator used to divide up the global page cache
** buffer provided using the SQLITE_CONFIG_PAGECACHE mechanism.
*/
struct PgFreeslot {
  PgFreeslot *pNext;  /* Next free slot */
};
40679
40680
40681
40682
40683
40684
40685

40686
40687
40688
40689
40690
40691
40692
40726
40727
40728
40729
40730
40731
40732
40733
40734
40735
40736
40737
40738
40739
40740







+







# define pcache1EnterMutex(X) sqlite3_mutex_enter((X)->mutex)
# define pcache1LeaveMutex(X) sqlite3_mutex_leave((X)->mutex)
# define PCACHE1_MIGHT_USE_GROUP_MUTEX 1
#endif

/******************************************************************************/
/******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/


/*
** This function is called during initialization if a static buffer is 
** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
** verb to sqlite3_config(). Parameter pBuf points to an allocation large
** enough to contain 'n' buffers of 'sz' bytes each.
**
40739
40740
40741
40742
40743
40744
40745

40746
40747
40748
40749
40750
40751
40752
40787
40788
40789
40790
40791
40792
40793
40794
40795
40796
40797
40798
40799
40800
40801







+







    int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
    int i;
    for(i=0; i<nBulk; i++){
      PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
      pX->page.pBuf = zBulk;
      pX->page.pExtra = &pX[1];
      pX->isBulkLocal = 1;
      pX->isAnchor = 0;
      pX->pNext = pCache->pFree;
      pCache->pFree = pX;
      zBulk += pCache->szAlloc;
    }
  }
  return pCache->pFree!=0;
}
40842
40843
40844
40845
40846
40847
40848
40849

40850
40851
40852
40853
40854
40855
40856
40857
40858
40859
40860
40861
40862
40863
40864
40865
40866

40867
40868
40869
40870
40871
40872
40873
40874
40875
40876
40877
40878

40879
40880
40881
40882
40883
40884
40885

40886
40887
40888
40889
40890
40891
40892
40891
40892
40893
40894
40895
40896
40897

40898
40899
40900
40901
40902
40903
40904
40905
40906
40907
40908
40909
40910
40911
40912
40913
40914
40915
40916
40917
40918
40919
40920
40921
40922
40923
40924
40925
40926
40927
40928
40929
40930
40931
40932
40933
40934
40935
40936
40937
40938
40939
40940
40941
40942
40943
40944







-
+

















+












+







+







  }
}
#endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */

/*
** Allocate a new page object initially associated with cache pCache.
*/
static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
  PgHdr1 *p = 0;
  void *pPg;

  assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
  if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
    p = pCache->pFree;
    pCache->pFree = p->pNext;
    p->pNext = 0;
  }else{
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
    /* The group mutex must be released before pcache1Alloc() is called. This
    ** is because it might call sqlite3_release_memory(), which assumes that 
    ** this mutex is not held. */
    assert( pcache1.separateCache==0 );
    assert( pCache->pGroup==&pcache1.grp );
    pcache1LeaveMutex(pCache->pGroup);
#endif
    if( benignMalloc ) sqlite3BeginBenignMalloc();
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
    pPg = pcache1Alloc(pCache->szPage);
    p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
    if( !pPg || !p ){
      pcache1Free(pPg);
      sqlite3_free(p);
      pPg = 0;
    }
#else
    pPg = pcache1Alloc(pCache->szAlloc);
    p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
#endif
    if( benignMalloc ) sqlite3EndBenignMalloc();
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
    pcache1EnterMutex(pCache->pGroup);
#endif
    if( pPg==0 ) return 0;
    p->page.pBuf = pPg;
    p->page.pExtra = &p[1];
    p->isBulkLocal = 0;
    p->isAnchor = 0;
  }
  if( pCache->bPurgeable ){
    pCache->pGroup->nCurrentPage++;
  }
  return p;
}

41005
41006
41007
41008
41009
41010
41011
41012
41013


41014
41015
41016

41017
41018
41019
41020
41021

41022
41023
41024
41025
41026
41027


41028
41029
41030
41031
41032
41033
41034
41057
41058
41059
41060
41061
41062
41063


41064
41065
41066


41067





41068



41069
41070
41071
41072
41073
41074
41075
41076
41077
41078
41079
41080







-
-
+
+

-
-
+
-
-
-
-
-
+
-
-
-



+
+







*/
static PgHdr1 *pcache1PinPage(PgHdr1 *pPage){
  PCache1 *pCache;

  assert( pPage!=0 );
  assert( pPage->isPinned==0 );
  pCache = pPage->pCache;
  assert( pPage->pLruNext || pPage==pCache->pGroup->pLruTail );
  assert( pPage->pLruPrev || pPage==pCache->pGroup->pLruHead );
  assert( pPage->pLruNext );
  assert( pPage->pLruPrev );
  assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
  if( pPage->pLruPrev ){
    pPage->pLruPrev->pLruNext = pPage->pLruNext;
  pPage->pLruPrev->pLruNext = pPage->pLruNext;
  }else{
    pCache->pGroup->pLruHead = pPage->pLruNext;
  }
  if( pPage->pLruNext ){
    pPage->pLruNext->pLruPrev = pPage->pLruPrev;
  pPage->pLruNext->pLruPrev = pPage->pLruPrev;
  }else{
    pCache->pGroup->pLruTail = pPage->pLruPrev;
  }
  pPage->pLruNext = 0;
  pPage->pLruPrev = 0;
  pPage->isPinned = 1;
  assert( pPage->isAnchor==0 );
  assert( pCache->pGroup->lru.isAnchor==1 );
  pCache->nRecyclable--;
  return pPage;
}


/*
** Remove the page supplied as an argument from the hash table 
41053
41054
41055
41056
41057
41058
41059

41060
41061
41062



41063
41064
41065
41066
41067
41068
41069
41099
41100
41101
41102
41103
41104
41105
41106
41107


41108
41109
41110
41111
41112
41113
41114
41115
41116
41117







+

-
-
+
+
+








/*
** If there are currently more than nMaxPage pages allocated, try
** to recycle pages to reduce the number allocated to nMaxPage.
*/
static void pcache1EnforceMaxPage(PCache1 *pCache){
  PGroup *pGroup = pCache->pGroup;
  PgHdr1 *p;
  assert( sqlite3_mutex_held(pGroup->mutex) );
  while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
    PgHdr1 *p = pGroup->pLruTail;
  while( pGroup->nCurrentPage>pGroup->nMaxPage
      && (p=pGroup->lru.pLruPrev)->isAnchor==0
  ){
    assert( p->pCache->pGroup==pGroup );
    assert( p->isPinned==0 );
    pcache1PinPage(p);
    pcache1RemoveFromHash(p, 1);
  }
  if( pCache->nPage==0 && pCache->pBulk ){
    sqlite3_free(pCache->pBulk);
41189
41190
41191
41192
41193
41194
41195




41196
41197
41198
41199
41200
41201
41202
41237
41238
41239
41240
41241
41242
41243
41244
41245
41246
41247
41248
41249
41250
41251
41252
41253
41254







+
+
+
+







  if( pCache ){
    if( pcache1.separateCache ){
      pGroup = (PGroup*)&pCache[1];
      pGroup->mxPinned = 10;
    }else{
      pGroup = &pcache1.grp;
    }
    if( pGroup->lru.isAnchor==0 ){
      pGroup->lru.isAnchor = 1;
      pGroup->lru.pLruPrev = pGroup->lru.pLruNext = &pGroup->lru;
    }
    pCache->pGroup = pGroup;
    pCache->szPage = szPage;
    pCache->szExtra = szExtra;
    pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
    pCache->bPurgeable = (bPurgeable ? 1 : 0);
    pcache1EnterMutex(pGroup);
    pcache1ResizeHash(pCache);
41296
41297
41298
41299
41300
41301
41302
41303

41304
41305
41306
41307

41308
41309
41310
41311
41312
41313
41314
41315
41316
41317
41318
41319
41320
41321
41322
41323
41324
41325

41326
41327
41328
41329
41330
41331
41332
41333
41348
41349
41350
41351
41352
41353
41354

41355
41356
41357
41358

41359
41360
41361
41362
41363
41364
41365
41366
41367
41368
41369
41370
41371
41372
41373
41374
41375


41376

41377
41378
41379
41380
41381
41382
41383







-
+



-
+
















-
-
+
-







  }

  if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
  assert( pCache->nHash>0 && pCache->apHash );

  /* Step 4. Try to recycle a page. */
  if( pCache->bPurgeable
   && pGroup->pLruTail
   && !pGroup->lru.pLruPrev->isAnchor
   && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
  ){
    PCache1 *pOther;
    pPage = pGroup->pLruTail;
    pPage = pGroup->lru.pLruPrev;
    assert( pPage->isPinned==0 );
    pcache1RemoveFromHash(pPage, 0);
    pcache1PinPage(pPage);
    pOther = pPage->pCache;
    if( pOther->szAlloc != pCache->szAlloc ){
      pcache1FreePage(pPage);
      pPage = 0;
    }else{
      pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
    }
  }

  /* Step 5. If a usable page buffer has still not been found, 
  ** attempt to allocate a new one. 
  */
  if( !pPage ){
    if( createFlag==1 ){ sqlite3BeginBenignMalloc(); }
    pPage = pcache1AllocPage(pCache);
    pPage = pcache1AllocPage(pCache, createFlag==1);
    if( createFlag==1 ){ sqlite3EndBenignMalloc(); }
  }

  if( pPage ){
    unsigned int h = iKey % pCache->nHash;
    pCache->nPage++;
    pPage->iKey = iKey;
    pPage->pNext = pCache->apHash[h];
41411
41412
41413
41414
41415
41416
41417

41418



41419
41420
41421
41422
41423
41424
41425
41461
41462
41463
41464
41465
41466
41467
41468

41469
41470
41471
41472
41473
41474
41475
41476
41477
41478







+
-
+
+
+







  PCache1 *pCache = (PCache1 *)p;
  PgHdr1 *pPage = 0;

  /* Step 1: Search the hash table for an existing entry. */
  pPage = pCache->apHash[iKey % pCache->nHash];
  while( pPage && pPage->iKey!=iKey ){ pPage = pPage->pNext; }

  /* Step 2: If the page was found in the hash table, then return it.
  /* Step 2: Abort if no existing page is found and createFlag is 0 */
  ** If the page was not in the hash table and createFlag is 0, abort.
  ** Otherwise (page not in hash and createFlag!=0) continue with
  ** subsequent steps to try to create the page. */
  if( pPage ){
    if( !pPage->isPinned ){
      return pcache1PinPage(pPage);
    }else{
      return pPage;
    }
  }else if( createFlag ){
41488
41489
41490
41491
41492
41493
41494
41495
41496
41497
41498
41499
41500
41501
41502
41503
41504
41505




41506
41507
41508
41509
41510
41511
41512
41513
41514
41515
41516
41541
41542
41543
41544
41545
41546
41547

41548
41549
41550
41551
41552
41553




41554
41555
41556
41557




41558
41559
41560
41561
41562
41563
41564







-






-
-
-
-
+
+
+
+
-
-
-
-







  assert( pPage->pCache==pCache );
  pcache1EnterMutex(pGroup);

  /* It is an error to call this function if the page is already 
  ** part of the PGroup LRU list.
  */
  assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
  assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
  assert( pPage->isPinned==1 );

  if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
    pcache1RemoveFromHash(pPage, 1);
  }else{
    /* Add the page to the PGroup LRU list. */
    if( pGroup->pLruHead ){
      pGroup->pLruHead->pLruPrev = pPage;
      pPage->pLruNext = pGroup->pLruHead;
      pGroup->pLruHead = pPage;
    PgHdr1 **ppFirst = &pGroup->lru.pLruNext;
    pPage->pLruPrev = &pGroup->lru;
    (pPage->pLruNext = *ppFirst)->pLruPrev = pPage;
    *ppFirst = pPage;
    }else{
      pGroup->pLruTail = pPage;
      pGroup->pLruHead = pPage;
    }
    pCache->nRecyclable++;
    pPage->isPinned = 0;
  }

  pcache1LeaveMutex(pCache->pGroup);
}

41640
41641
41642
41643
41644
41645
41646
41647




41648
41649
41650
41651
41652
41653
41654
41688
41689
41690
41691
41692
41693
41694

41695
41696
41697
41698
41699
41700
41701
41702
41703
41704
41705







-
+
+
+
+







SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
  int nFree = 0;
  assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
  assert( sqlite3_mutex_notheld(pcache1.mutex) );
  if( sqlite3GlobalConfig.nPage==0 ){
    PgHdr1 *p;
    pcache1EnterMutex(&pcache1.grp);
    while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
    while( (nReq<0 || nFree<nReq)
       &&  (p=pcache1.grp.lru.pLruPrev)!=0
       &&  p->isAnchor==0
    ){
      nFree += pcache1MemSize(p->page.pBuf);
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
      nFree += sqlite3MemSize(p);
#endif
      assert( p->isPinned==0 );
      pcache1PinPage(p);
      pcache1RemoveFromHash(p, 1);
41668
41669
41670
41671
41672
41673
41674
41675

41676
41677
41678
41679
41680
41681
41682
41719
41720
41721
41722
41723
41724
41725

41726
41727
41728
41729
41730
41731
41732
41733







-
+







  int *pnCurrent,      /* OUT: Total number of pages cached */
  int *pnMax,          /* OUT: Global maximum cache size */
  int *pnMin,          /* OUT: Sum of PCache1.nMin for purgeable caches */
  int *pnRecyclable    /* OUT: Total number of pages available for recycling */
){
  PgHdr1 *p;
  int nRecyclable = 0;
  for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){
  for(p=pcache1.grp.lru.pLruNext; !p->isAnchor; p=p->pLruNext){
    assert( p->isPinned==0 );
    nRecyclable++;
  }
  *pnCurrent = pcache1.grp.nCurrentPage;
  *pnMax = (int)pcache1.grp.nMaxPage;
  *pnMin = (int)pcache1.grp.nMinPage;
  *pnRecyclable = nRecyclable;
42982
42983
42984
42985
42986
42987
42988
42989

42990
42991
42992
42993
42994
42995
42996
43033
43034
43035
43036
43037
43038
43039

43040
43041
43042
43043
43044
43045
43046
43047







-
+







  u8 eState;                  /* Pager state (OPEN, READER, WRITER_LOCKED..) */
  u8 eLock;                   /* Current lock held on database file */
  u8 changeCountDone;         /* Set after incrementing the change-counter */
  u8 setMaster;               /* True if a m-j name has been written to jrnl */
  u8 doNotSpill;              /* Do not spill the cache when non-zero */
  u8 subjInMemory;            /* True to use in-memory sub-journals */
  u8 bUseFetch;               /* True to use xFetch() */
  u8 hasBeenUsed;             /* True if any content previously read */
  u8 hasHeldSharedLock;       /* True if a shared lock has ever been held */
  Pgno dbSize;                /* Number of pages in the database */
  Pgno dbOrigSize;            /* dbSize before the current transaction */
  Pgno dbFileSize;            /* Number of pages in the database file */
  Pgno dbHintSize;            /* Value passed to FCNTL_SIZE_HINT call */
  int errCode;                /* One of several kinds of errors */
  int nRec;                   /* Pages journalled since last j-header written */
  u32 cksumInit;              /* Quasi-random value added to every checksum */
47432
47433
47434
47435
47436
47437
47438
47439

47440
47441
47442

47443
47444
47445
47446
47447
47448
47449
47483
47484
47485
47486
47487
47488
47489

47490
47491
47492

47493
47494
47495
47496
47497
47498
47499
47500







-
+


-
+








      assert( pPager->eState==PAGER_OPEN );
      assert( (pPager->eLock==SHARED_LOCK)
           || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
      );
    }

    if( !pPager->tempFile && pPager->hasBeenUsed ){
    if( !pPager->tempFile && pPager->hasHeldSharedLock ){
      /* The shared-lock has just been acquired then check to
      ** see if the database has been modified.  If the database has changed,
      ** flush the cache.  The pPager->hasBeenUsed flag prevents this from
      ** flush the cache.  The hasHeldSharedLock flag prevents this from
      ** occurring on the very first access to a file, in order to save a
      ** single unnecessary sqlite3OsRead() call at the start-up.
      **
      ** Database changes are detected by looking at 15 bytes beginning
      ** at offset 24 into the file.  The first 4 of these 16 bytes are
      ** a 32-bit counter that is incremented with each change.  The
      ** other bytes change randomly with each file change when
47505
47506
47507
47508
47509
47510
47511

47512
47513
47514
47515
47516
47517
47518
47556
47557
47558
47559
47560
47561
47562
47563
47564
47565
47566
47567
47568
47569
47570







+







 failed:
  if( rc!=SQLITE_OK ){
    assert( !MEMDB );
    pager_unlock(pPager);
    assert( pPager->eState==PAGER_OPEN );
  }else{
    pPager->eState = PAGER_READER;
    pPager->hasHeldSharedLock = 1;
  }
  return rc;
}

/*
** If the reference count has reached zero, rollback any active
** transaction and unlock the pager.
47588
47589
47590
47591
47592
47593
47594
47595

47596
47597
47598
47599
47600
47601







47602
47603
47604
47605
47606
47607
47608
47609

47610
47611
47612
47613
47614
47615
47616
47640
47641
47642
47643
47644
47645
47646

47647
47648
47649
47650
47651
47652
47653
47654
47655
47656
47657
47658
47659
47660
47661
47662
47663
47664




47665
47666
47667
47668
47669
47670
47671
47672







-
+






+
+
+
+
+
+
+




-
-
-
-
+







  u32 iFrame = 0;                 /* Frame to read from WAL file */
  const int noContent = (flags & PAGER_GET_NOCONTENT);

  /* It is acceptable to use a read-only (mmap) page for any page except
  ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
  ** flag was specified by the caller. And so long as the db is not a 
  ** temporary or in-memory database.  */
  const int bMmapOk = (pgno!=1 && USEFETCH(pPager)
  const int bMmapOk = (pgno>1 && USEFETCH(pPager)
   && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
#ifdef SQLITE_HAS_CODEC
   && pPager->xCodec==0
#endif
  );

  /* Optimization note:  Adding the "pgno<=1" term before "pgno==0" here
  ** allows the compiler optimizer to reuse the results of the "pgno>1"
  ** test in the previous statement, and avoid testing pgno==0 in the
  ** common case where pgno is large. */
  if( pgno<=1 && pgno==0 ){
    return SQLITE_CORRUPT_BKPT;
  }
  assert( pPager->eState>=PAGER_READER );
  assert( assert_pager_state(pPager) );
  assert( noContent==0 || bMmapOk==0 );

  if( pgno==0 ){
    return SQLITE_CORRUPT_BKPT;
  }
  pPager->hasBeenUsed = 1;
  assert( pPager->hasHeldSharedLock==1 );

  /* If the pager is in the error state, return an error immediately. 
  ** Otherwise, request the page from the PCache layer. */
  if( pPager->errCode!=SQLITE_OK ){
    rc = pPager->errCode;
  }else{
    if( bMmapOk && pagerUseWal(pPager) ){
47757
47758
47759
47760
47761
47762
47763
47764

47765
47766
47767
47768
47769
47770
47771
47813
47814
47815
47816
47817
47818
47819

47820
47821
47822
47823
47824
47825
47826
47827







-
+







*/
SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){
  sqlite3_pcache_page *pPage;
  assert( pPager!=0 );
  assert( pgno!=0 );
  assert( pPager->pPCache!=0 );
  pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
  assert( pPage==0 || pPager->hasBeenUsed );
  assert( pPage==0 || pPager->hasHeldSharedLock );
  if( pPage==0 ) return 0;
  return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
}

/*
** Release a page reference.
**
48724
48725
48726
48727
48728
48729
48730
48731

48732
48733
48734
48735
48736
48737
48738
48780
48781
48782
48783
48784
48785
48786

48787
48788
48789
48790
48791
48792
48793
48794







-
+







*/
SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager *pPager){
  return pPager->readOnly;
}

#ifdef SQLITE_DEBUG
/*
** Return the number of references to the pager.
** Return the sum of the reference counts for all pages held by pPager.
*/
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
  return sqlite3PcacheRefCount(pPager->pPCache);
}
#endif

/*
50036
50037
50038
50039
50040
50041
50042

50043
50044
50045
50046
50047
50048
50049
50092
50093
50094
50095
50096
50097
50098
50099
50100
50101
50102
50103
50104
50105
50106







+







  u8 writeLock;              /* True if in a write transaction */
  u8 ckptLock;               /* True if holding a checkpoint lock */
  u8 readOnly;               /* WAL_RDWR, WAL_RDONLY, or WAL_SHM_RDONLY */
  u8 truncateOnCommit;       /* True to truncate WAL file on commit */
  u8 syncHeader;             /* Fsync the WAL header if true */
  u8 padToSectorBoundary;    /* Pad transactions out to the next sector */
  WalIndexHdr hdr;           /* Wal-index header for current transaction */
  u32 minFrame;              /* Ignore wal frames before this one */
  const char *zWalName;      /* Name of WAL file */
  u32 nCkpt;                 /* Checkpoint sequence counter in the wal-header */
#ifdef SQLITE_DEBUG
  u8 lockError;              /* True if a locking error has occurred */
#endif
};

51904
51905
51906
51907
51908
51909
51910
51911
51912
51913
51914
51915



















51916

51917
51918
51919
51920
51921
51922
51923
51961
51962
51963
51964
51965
51966
51967





51968
51969
51970
51971
51972
51973
51974
51975
51976
51977
51978
51979
51980
51981
51982
51983
51984
51985
51986
51987
51988
51989
51990
51991
51992
51993
51994
51995







-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+







    ** that the log file may have been wrapped by a writer, or that frames
    ** that occur later in the log than pWal->hdr.mxFrame may have been
    ** copied into the database by a checkpointer. If either of these things
    ** happened, then reading the database with the current value of
    ** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
    ** instead.
    **
    ** This does not guarantee that the copy of the wal-index header is up to
    ** date before proceeding. That would not be possible without somehow
    ** blocking writers. It only guarantees that a dangerous checkpoint or 
    ** log-wrap (either of which would require an exclusive lock on
    ** WAL_READ_LOCK(mxI)) has not occurred since the snapshot was valid.
    ** Before checking that the live wal-index header has not changed
    ** since it was read, set Wal.minFrame to the first frame in the wal
    ** file that has not yet been checkpointed. This client will not need
    ** to read any frames earlier than minFrame from the wal file - they
    ** can be safely read directly from the database file.
    **
    ** Because a ShmBarrier() call is made between taking the copy of 
    ** nBackfill and checking that the wal-header in shared-memory still
    ** matches the one cached in pWal->hdr, it is guaranteed that the 
    ** checkpointer that set nBackfill was not working with a wal-index
    ** header newer than that cached in pWal->hdr. If it were, that could
    ** cause a problem. The checkpointer could omit to checkpoint
    ** a version of page X that lies before pWal->minFrame (call that version
    ** A) on the basis that there is a newer version (version B) of the same
    ** page later in the wal file. But if version B happens to like past
    ** frame pWal->hdr.mxFrame - then the client would incorrectly assume
    ** that it can read version A from the database file. However, since
    ** we can guarantee that the checkpointer that set nBackfill could not
    ** see any pages past pWal->hdr.mxFrame, this problem does not come up.
    */
    pWal->minFrame = pInfo->nBackfill+1;
    walShmBarrier(pWal);
    if( pInfo->aReadMark[mxI]!=mxReadMark
     || memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr))
    ){
      walUnlockShared(pWal, WAL_READ_LOCK(mxI));
      return WAL_RETRY;
    }else{
51980
51981
51982
51983
51984
51985
51986

51987
51988
51989
51990
51991
51992
51993
52052
52053
52054
52055
52056
52057
52058
52059
52060
52061
52062
52063
52064
52065
52066







+







  Wal *pWal,                      /* WAL handle */
  Pgno pgno,                      /* Database page number to read data for */
  u32 *piRead                     /* OUT: Frame number (or zero) */
){
  u32 iRead = 0;                  /* If !=0, WAL frame to return data from */
  u32 iLast = pWal->hdr.mxFrame;  /* Last page in WAL for this reader */
  int iHash;                      /* Used to loop through N hash tables */
  int iMinHash;

  /* This routine is only be called from within a read transaction. */
  assert( pWal->readLock>=0 || pWal->lockError );

  /* If the "last page" field of the wal-index header snapshot is 0, then
  ** no data will be read from the wal under any circumstances. Return early
  ** in this case as an optimization.  Likewise, if pWal->readLock==0, 
52020
52021
52022
52023
52024
52025
52026

52027

52028
52029
52030
52031
52032
52033
52034
52035
52036
52037
52038
52039
52040
52041
52042

52043
52044
52045
52046
52047
52048
52049
52050
52051
52052
52053
52054
52055
52056
52057
52058

52059

52060
52061
52062
52063
52064
52065
52066
52093
52094
52095
52096
52097
52098
52099
52100

52101
52102
52103
52104
52105
52106
52107
52108
52109
52110
52111
52112
52113
52114
52115

52116
52117
52118
52119
52120
52121
52122
52123
52124
52125
52126
52127
52128
52129
52130
52131
52132
52133

52134
52135
52136
52137
52138
52139
52140
52141







+
-
+














-
+
















+
-
+







  **   (aPgno[iFrame]==pgno): 
  **     This condition filters out normal hash-table collisions.
  **
  **   (iFrame<=iLast): 
  **     This condition filters out entries that were added to the hash
  **     table after the current read-transaction had started.
  */
  iMinHash = walFramePage(pWal->minFrame);
  for(iHash=walFramePage(iLast); iHash>=0 && iRead==0; iHash--){
  for(iHash=walFramePage(iLast); iHash>=iMinHash && iRead==0; iHash--){
    volatile ht_slot *aHash;      /* Pointer to hash table */
    volatile u32 *aPgno;          /* Pointer to array of page numbers */
    u32 iZero;                    /* Frame number corresponding to aPgno[0] */
    int iKey;                     /* Hash slot index */
    int nCollide;                 /* Number of hash collisions remaining */
    int rc;                       /* Error code */

    rc = walHashGet(pWal, iHash, &aHash, &aPgno, &iZero);
    if( rc!=SQLITE_OK ){
      return rc;
    }
    nCollide = HASHTABLE_NSLOT;
    for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
      u32 iFrame = aHash[iKey] + iZero;
      if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
      if( iFrame<=iLast && iFrame>=pWal->minFrame && aPgno[aHash[iKey]]==pgno ){
        assert( iFrame>iRead || CORRUPT_DB );
        iRead = iFrame;
      }
      if( (nCollide--)==0 ){
        return SQLITE_CORRUPT_BKPT;
      }
    }
  }

#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
  /* If expensive assert() statements are available, do a linear search
  ** of the wal-index file content. Make sure the results agree with the
  ** result obtained using the hash indexes above.  */
  {
    u32 iRead2 = 0;
    u32 iTest;
    assert( pWal->minFrame>0 );
    for(iTest=iLast; iTest>0; iTest--){
    for(iTest=iLast; iTest>=pWal->minFrame; iTest--){
      if( walFramePgno(pWal, iTest)==pgno ){
        iRead2 = iTest;
        break;
      }
    }
    assert( iRead==iRead2 );
  }
53492
53493
53494
53495
53496
53497
53498
53499


53500

53501

53502
53503
53504
53505
53506
53507
53508
53567
53568
53569
53570
53571
53572
53573

53574
53575
53576
53577

53578
53579
53580
53581
53582
53583
53584
53585







-
+
+

+
-
+







/*
** get2byteAligned(), unlike get2byte(), requires that its argument point to a
** two-byte aligned address.  get2bytea() is only used for accessing the
** cell addresses in a btree header.
*/
#if SQLITE_BYTEORDER==4321
# define get2byteAligned(x)  (*(u16*)(x))
#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000
#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
    && GCC_VERSION>=4008000
# define get2byteAligned(x)  __builtin_bswap16(*(u16*)(x))
#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
#elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300
    && defined(_MSC_VER) && _MSC_VER>=1300
# define get2byteAligned(x)  _byteswap_ushort(*(u16*)(x))
#else
# define get2byteAligned(x)  ((x)[0]<<8 | (x)[1])
#endif

/************** End of btreeInt.h ********************************************/
/************** Continuing where we left off in btmutex.c ********************/
62490
62491
62492
62493
62494
62495
62496
62497
62498
62499
62500
62501
62502
62503
62504
62505
62506

62507
62508
62509
62510
62511
62512
62513
62514
62567
62568
62569
62570
62571
62572
62573

62574
62575
62576
62577
62578
62579
62580
62581

62582

62583
62584
62585
62586
62587
62588
62589







-








-
+
-







*/
static void checkAppendMsg(
  IntegrityCk *pCheck,
  const char *zFormat,
  ...
){
  va_list ap;
  char zBuf[200];
  if( !pCheck->mxErr ) return;
  pCheck->mxErr--;
  pCheck->nErr++;
  va_start(ap, zFormat);
  if( pCheck->errMsg.nChar ){
    sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
  }
  if( pCheck->zPfx ){
    sqlite3_snprintf(sizeof(zBuf), zBuf, pCheck->zPfx, pCheck->v1, pCheck->v2);
    sqlite3XPrintf(&pCheck->errMsg, 0, pCheck->zPfx, pCheck->v1, pCheck->v2);
    sqlite3StrAccumAppendAll(&pCheck->errMsg, zBuf);
  }
  sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
  va_end(ap);
  if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
    pCheck->mallocFailed = 1;
  }
}
65325
65326
65327
65328
65329
65330
65331
65332

65333
65334
65335
65336
65337
65338
65339
65400
65401
65402
65403
65404
65405
65406

65407
65408
65409
65410
65411
65412
65413
65414







-
+







}

/*
** The expression object indicated by the second argument is guaranteed
** to be a scalar SQL function. If
**
**   * all function arguments are SQL literals,
**   * the SQLITE_FUNC_CONSTANT function flag is set, and
**   * one of the SQLITE_FUNC_CONSTANT or _SLOCHNG function flags is set, and
**   * the SQLITE_FUNC_NEEDCOLL function flag is not set,
**
** then this routine attempts to invoke the SQL function. Assuming no
** error occurs, output parameter (*ppVal) is set to point to a value 
** object containing the result before returning SQLITE_OK.
**
** Affinity aff is applied to the result of the function before returning.
65366
65367
65368
65369
65370
65371
65372
65373

65374
65375
65376
65377
65378
65379
65380
65441
65442
65443
65444
65445
65446
65447

65448
65449
65450
65451
65452
65453
65454
65455







-
+







  assert( pCtx!=0 );
  assert( (p->flags & EP_TokenOnly)==0 );
  pList = p->x.pList;
  if( pList ) nVal = pList->nExpr;
  nName = sqlite3Strlen30(p->u.zToken);
  pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
  assert( pFunc );
  if( (pFunc->funcFlags & SQLITE_FUNC_CONSTANT)==0 
  if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0 
   || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
  ){
    return SQLITE_OK;
  }

  if( pList ){
    apVal = (sqlite3_value**)sqlite3DbMallocZero(db, sizeof(apVal[0]) * nVal);
65960
65961
65962
65963
65964
65965
65966
65967

65968
65969
65970
65971
65972
65973
65974
66035
66036
66037
66038
66039
66040
66041

66042
66043
66044
66045
66046
66047
66048
66049







-
+







}

/*
** Return the SQL associated with a prepared statement
*/
SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt){
  Vdbe *p = (Vdbe *)pStmt;
  return (p && p->isPrepareV2) ? p->zSql : 0;
  return p ? p->zSql : 0;
}

/*
** Swap all content between two VDBE structures.
*/
SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
  Vdbe tmp, *pTmp;
66107
66108
66109
66110
66111
66112
66113






































66114
66115
66116
66117
66118
66119
66120
66121
66122
66123
66124
66125
66126
66127
66128
66129
66130
66131
66132
66133


66134
66135
66136
66137
66138
66139
66140
66182
66183
66184
66185
66186
66187
66188
66189
66190
66191
66192
66193
66194
66195
66196
66197
66198
66199
66200
66201
66202
66203
66204
66205
66206
66207
66208
66209
66210
66211
66212
66213
66214
66215
66216
66217
66218
66219
66220
66221
66222
66223
66224
66225
66226
66227
66228
66229
66230
66231
66232
66233
66234
66235
66236
66237
66238
66239
66240
66241
66242
66243
66244
66245

66246
66247
66248
66249
66250
66251
66252
66253
66254







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



















-
+
+







SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe *p, int op, int p1){
  return sqlite3VdbeAddOp3(p, op, p1, 0, 0);
}
SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe *p, int op, int p1, int p2){
  return sqlite3VdbeAddOp3(p, op, p1, p2, 0);
}

/* Generate code for an unconditional jump to instruction iDest
*/
SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe *p, int iDest){
  return sqlite3VdbeAddOp3(p, OP_Goto, 0, iDest, 0);
}

/* Generate code to cause the string zStr to be loaded into
** register iDest
*/
SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe *p, int iDest, const char *zStr){
  return sqlite3VdbeAddOp4(p, OP_String8, 0, iDest, 0, zStr, 0);
}

/*
** Generate code that initializes multiple registers to string or integer
** constants.  The registers begin with iDest and increase consecutively.
** One register is initialized for each characgter in zTypes[].  For each
** "s" character in zTypes[], the register is a string if the argument is
** not NULL, or OP_Null if the value is a null pointer.  For each "i" character
** in zTypes[], the register is initialized to an integer.
*/
SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe *p, int iDest, const char *zTypes, ...){
  va_list ap;
  int i;
  char c;
  va_start(ap, zTypes);
  for(i=0; (c = zTypes[i])!=0; i++){
    if( c=='s' ){
      const char *z = va_arg(ap, const char*);
      int addr = sqlite3VdbeAddOp2(p, z==0 ? OP_Null : OP_String8, 0, iDest++);
      if( z ) sqlite3VdbeChangeP4(p, addr, z, 0);
    }else{
      assert( c=='i' );
      sqlite3VdbeAddOp2(p, OP_Integer, va_arg(ap, int), iDest++);
    }
  }
  va_end(ap);
}

/*
** Add an opcode that includes the p4 value as a pointer.
*/
SQLITE_PRIVATE int sqlite3VdbeAddOp4(
  Vdbe *p,            /* Add the opcode to this VM */
  int op,             /* The new opcode */
  int p1,             /* The P1 operand */
  int p2,             /* The P2 operand */
  int p3,             /* The P3 operand */
  const char *zP4,    /* The P4 operand */
  int p4type          /* P4 operand type */
){
  int addr = sqlite3VdbeAddOp3(p, op, p1, p2, p3);
  sqlite3VdbeChangeP4(p, addr, zP4, p4type);
  return addr;
}

/*
** Add an opcode that includes the p4 value with a P4_INT64 type.
** Add an opcode that includes the p4 value with a P4_INT64 or
** P4_REAL type.
*/
SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(
  Vdbe *p,            /* Add the opcode to this VM */
  int op,             /* The new opcode */
  int p1,             /* The P1 operand */
  int p2,             /* The P2 operand */
  int p3,             /* The P3 operand */
66211
66212
66213
66214
66215
66216
66217

66218

66219
66220
66221
66222
66223
66224
66225
66325
66326
66327
66328
66329
66330
66331
66332

66333
66334
66335
66336
66337
66338
66339
66340







+
-
+







** a prior call to sqlite3VdbeMakeLabel().
*/
SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
  Parse *p = v->pParse;
  int j = -1-x;
  assert( v->magic==VDBE_MAGIC_INIT );
  assert( j<p->nLabel );
  assert( j>=0 );
  if( ALWAYS(j>=0) && p->aLabel ){
  if( p->aLabel ){
    p->aLabel[j] = v->nOp;
  }
  p->iFixedOp = v->nOp - 1;
}

/*
** Mark the VDBE as one that can only be run one time.
66355
66356
66357
66358
66359
66360
66361

66362
66363
66364




66365
66366


66367
66368
66369
66370


66371
66372



66373
66374
66375
66376
66377
66378
66379
66470
66471
66472
66473
66474
66475
66476
66477



66478
66479
66480
66481
66482

66483
66484
66485



66486
66487
66488

66489
66490
66491
66492
66493
66494
66495
66496
66497
66498







+
-
-
-
+
+
+
+

-
+
+

-
-
-
+
+

-
+
+
+







  ** from failing.  */
  return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter
              || (hasCreateTable && hasInitCoroutine) );
}
#endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */

/*
** This routine is called after all opcodes have been inserted.  It loops
** Loop through the program looking for P2 values that are negative
** on jump instructions.  Each such value is a label.  Resolve the
** label by setting the P2 value to its correct non-zero value.
** through all the opcodes and fixes up some details.
**
** (1) For each jump instruction with a negative P2 value (a label)
**     resolve the P2 value to an actual address.
**
** This routine is called once after all opcodes have been inserted.
** (2) Compute the maximum number of arguments used by any SQL function
**     and store that value in *pMaxFuncArgs.
**
** Variable *pMaxFuncArgs is set to the maximum value of any P2 argument 
** to an OP_Function, OP_AggStep or OP_VFilter opcode. This is used by 
** sqlite3VdbeMakeReady() to size the Vdbe.apArg[] array.
** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
**     indicate what the prepared statement actually does.
**
** The Op.opflags field is set on all opcodes.
** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
**
** (5) Reclaim the memory allocated for storing labels.
*/
static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
  int i;
  int nMaxArgs = *pMaxFuncArgs;
  Op *pOp;
  Parse *pParse = p->pParse;
  int *aLabel = pParse->aLabel;
66478
66479
66480
66481
66482
66483
66484
66485



66486
66487
66488
66489
66490
66491
66492

66493
66494
66495


66496
66497
66498
66499
66500
66501
66502
66503
66504
66505
66506
66507
66508












66509
66510

66511
66512
66513

66514
66515

66516
66517
66518
66519
66520



66521
66522
66523


66524
66525
66526
66527
66528
66529
66530
66531
66597
66598
66599
66600
66601
66602
66603

66604
66605
66606
66607
66608
66609
66610
66611


66612



66613
66614













66615
66616
66617
66618
66619
66620
66621
66622
66623
66624
66625
66626
66627

66628
66629
66630

66631
66632

66633
66634
66635



66636
66637
66638
66639


66640
66641

66642
66643
66644
66645
66646
66647
66648







-
+
+
+





-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
+


-
+

-
+


-
-
-
+
+
+

-
-
+
+
-







}

/*
** Add a whole list of operations to the operation stack.  Return the
** address of the first operation added.
*/
SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){
  int addr;
  int addr, i;
  VdbeOp *pOut;
  assert( nOp>0 );
  assert( p->magic==VDBE_MAGIC_INIT );
  if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){
    return 0;
  }
  addr = p->nOp;
  if( ALWAYS(nOp>0) ){
    int i;
  pOut = &p->aOp[addr];
    VdbeOpList const *pIn = aOp;
    for(i=0; i<nOp; i++, pIn++){
      int p2 = pIn->p2;
  for(i=0; i<nOp; i++, aOp++, pOut++){
    int p2 = aOp->p2;
      VdbeOp *pOut = &p->aOp[i+addr];
      pOut->opcode = pIn->opcode;
      pOut->p1 = pIn->p1;
      if( p2<0 ){
        assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP );
        pOut->p2 = addr + ADDR(p2);
      }else{
        pOut->p2 = p2;
      }
      pOut->p3 = pIn->p3;
      pOut->p4type = P4_NOTUSED;
      pOut->p4.p = 0;
      pOut->p5 = 0;
    pOut->opcode = aOp->opcode;
    pOut->p1 = aOp->p1;
    if( p2<0 ){
      assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP );
      pOut->p2 = addr + ADDR(p2);
    }else{
      pOut->p2 = p2;
    }
    pOut->p3 = aOp->p3;
    pOut->p4type = P4_NOTUSED;
    pOut->p4.p = 0;
    pOut->p5 = 0;
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
      pOut->zComment = 0;
    pOut->zComment = 0;
#endif
#ifdef SQLITE_VDBE_COVERAGE
      pOut->iSrcLine = iLineno+i;
    pOut->iSrcLine = iLineno+i;
#else
      (void)iLineno;
    (void)iLineno;
#endif
#ifdef SQLITE_DEBUG
      if( p->db->flags & SQLITE_VdbeAddopTrace ){
        sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
      }
    if( p->db->flags & SQLITE_VdbeAddopTrace ){
      sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
    }
#endif
    }
    p->nOp += nOp;
  }
  p->nOp += nOp;
  }
  return addr;
}

#if defined(SQLITE_ENABLE_STMT_SCANSTATUS)
/*
** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus().
*/
66550
66551
66552
66553
66554
66555
66556

66557

66558
66559
66560
66561
66562

66563
66564
66565
66566




66567
66568
66569
66570
66571
66572
66573
66574
66575
66576
66577


66578
66579
66580
66581
66582
66583
66584
66585
66586
66587


66588
66589
66590
66591
66592
66593
66594

66595
66596
66597
66598

66599
66600
66601
66602
66603
66604
66605
66606
66607
66608

66609
66610
66611
66612
66613
66614
66615
66667
66668
66669
66670
66671
66672
66673
66674

66675



66676

66677




66678
66679
66680
66681
66682





66683




66684
66685





66686




66687
66688







66689




66690

66691
66692
66693
66694
66695
66696
66697

66698
66699
66700
66701
66702
66703
66704
66705
66706







+
-
+
-
-
-

-
+
-
-
-
-
+
+
+
+

-
-
-
-
-

-
-
-
-
+
+
-
-
-
-
-

-
-
-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
-
+
-







-

+







    p->aScan = aNew;
  }
}
#endif


/*
** Change the value of the opcode, or P1, P2, P3, or P5 operands
** Change the value of the P1 operand for a specific instruction.
** for a specific instruction.
** This routine is useful when a large program is loaded from a
** static array using sqlite3VdbeAddOpList but we want to make a
** few minor changes to the program.
*/
SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, u32 addr, int val){
SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe *p, u32 addr, u8 iNewOpcode){
  assert( p!=0 );
  if( ((u32)p->nOp)>addr ){
    p->aOp[addr].p1 = val;
  }
  sqlite3VdbeGetOp(p,addr)->opcode = iNewOpcode;
}
SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, u32 addr, int val){
  sqlite3VdbeGetOp(p,addr)->p1 = val;
}

/*
** Change the value of the P2 operand for a specific instruction.
** This routine is useful for setting a jump destination.
*/
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, u32 addr, int val){
  assert( p!=0 );
  if( ((u32)p->nOp)>addr ){
    p->aOp[addr].p2 = val;
  }
  sqlite3VdbeGetOp(p,addr)->p2 = val;
}
}

/*
** Change the value of the P3 operand for a specific instruction.
*/
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){
  assert( p!=0 );
  if( ((u32)p->nOp)>addr ){
    p->aOp[addr].p3 = val;
  }
  sqlite3VdbeGetOp(p,addr)->p3 = val;
}
}

/*
** Change the value of the P5 operand for the most recently
** added operation.
*/
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 val){
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){
  assert( p!=0 );
  if( p->aOp ){
    assert( p->nOp>0 );
    p->aOp[p->nOp-1].p5 = val;
  sqlite3VdbeGetOp(p,-1)->p5 = p5;
  }
}

/*
** Change the P2 operand of instruction addr so that it points to
** the address of the next instruction to be coded.
*/
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){
  sqlite3VdbeChangeP2(p, addr, p->nOp);
  p->pParse->iFixedOp = p->nOp - 1;
  sqlite3VdbeChangeP2(p, addr, p->nOp);
}


/*
** If the input FuncDef structure is ephemeral, then free it.  If
** the FuncDef is not ephermal, then do nothing.
*/
66986
66987
66988
66989
66990
66991
66992
66993

66994

66995
66996
66997
66998
66999
67000
67001
67077
67078
67079
67080
67081
67082
67083

67084
67085
67086
67087
67088
67089
67090
67091
67092
67093







-
+

+







        CollSeq *pColl = pKeyInfo->aColl[j];
        const char *zColl = pColl ? pColl->zName : "nil";
        int n = sqlite3Strlen30(zColl);
        if( n==6 && memcmp(zColl,"BINARY",6)==0 ){
          zColl = "B";
          n = 1;
        }
        if( i+n>nTemp-6 ){
        if( i+n>nTemp-7 ){
          memcpy(&zTemp[i],",...",4);
          i += 4;
          break;
        }
        zTemp[i++] = ',';
        if( pKeyInfo->aSortOrder[j] ){
          zTemp[i++] = '-';
        }
        memcpy(&zTemp[i], zColl, n+1);
70752
70753
70754
70755
70756
70757
70758
70759

70760
70761
70762
70763
70764
70765
70766
70844
70845
70846
70847
70848
70849
70850

70851
70852
70853
70854
70855
70856
70857
70858







-
+







  ** returned if this statement was compiled using the legacy 
  ** sqlite3_prepare() interface. According to the docs, this can only
  ** be one of the values in the first assert() below. Variable p->rc 
  ** contains the value that would be returned if sqlite3_finalize() 
  ** were called on statement p.
  */
  assert( rc==SQLITE_ROW  || rc==SQLITE_DONE   || rc==SQLITE_ERROR 
       || rc==SQLITE_BUSY || rc==SQLITE_MISUSE
       || (rc&0xff)==SQLITE_BUSY || rc==SQLITE_MISUSE
  );
  assert( (p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE) || p->rc==p->rcApp );
  if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
    /* If this statement was prepared using sqlite3_prepare_v2(), and an
    ** error has occurred, then return the error code in p->rc to the
    ** caller. Set the error code in the database handle to the same value.
    */ 
70837
70838
70839
70840
70841
70842
70843
70844

70845
70846
70847
70848
70849
70850
70851
70929
70930
70931
70932
70933
70934
70935

70936
70937
70938
70939
70940
70941
70942
70943







-
+







** IMPLEMENTATION-OF: R-46798-50301 The sqlite3_context_db_handle() interface
** returns a copy of the pointer to the database connection (the 1st
** parameter) of the sqlite3_create_function() and
** sqlite3_create_function16() routines that originally registered the
** application defined function.
*/
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context *p){
  assert( p && p->pFunc );
  assert( p && p->pOut );
  return p->pOut->db;
}

/*
** Return the current time for a statement.  If the current time
** is requested more than once within the same run of a single prepared
** statement, the exact same time is returned for each invocation regardless
72655
72656
72657
72658
72659
72660
72661
72662

72663
72664
72665
72666
72667
72668
72669
72747
72748
72749
72750
72751
72752
72753

72754
72755
72756
72757
72758
72759
72760
72761







-
+







  assert( p->magic==VDBE_MAGIC_RUN );  /* sqlite3_step() verifies this */
  sqlite3VdbeEnter(p);
  if( p->rc==SQLITE_NOMEM ){
    /* This happens if a malloc() inside a call to sqlite3_column_text() or
    ** sqlite3_column_text16() failed.  */
    goto no_mem;
  }
  assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
  assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
  assert( p->bIsReader || p->readOnly!=0 );
  p->rc = SQLITE_OK;
  p->iCurrentTime = 0;
  assert( p->explain==0 );
  p->pResultSet = 0;
  db->busyHandler.nBusy = 0;
  if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
75092
75093
75094
75095
75096
75097
75098

75099
75100
75101
75102
75103





75104
75105
75106
75107
75108
75109
75110
75111
75184
75185
75186
75187
75188
75189
75190
75191





75192
75193
75194
75195
75196

75197
75198
75199
75200
75201
75202
75203







+
-
-
-
-
-
+
+
+
+
+
-







      assert( desiredAutoCommit==1 );
      sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
      db->autoCommit = 1;
    }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
      goto vdbe_return;
    }else{
      db->autoCommit = (u8)desiredAutoCommit;
    }
      if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
        p->pc = (int)(pOp - aOp);
        db->autoCommit = (u8)(1-desiredAutoCommit);
        p->rc = rc = SQLITE_BUSY;
        goto vdbe_return;
    if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
      p->pc = (int)(pOp - aOp);
      db->autoCommit = (u8)(1-desiredAutoCommit);
      p->rc = rc = SQLITE_BUSY;
      goto vdbe_return;
      }
    }
    assert( db->nStatement==0 );
    sqlite3CloseSavepoints(db);
    if( p->rc==SQLITE_OK ){
      rc = SQLITE_DONE;
    }else{
      rc = SQLITE_ERROR;
75169
75170
75171
75172
75173
75174
75175


75176

75177
75178

75179
75180
75181
75182
75183
75184
75185
75261
75262
75263
75264
75265
75266
75267
75268
75269

75270
75271

75272
75273
75274
75275
75276
75277
75278
75279







+
+
-
+

-
+







    rc = SQLITE_READONLY;
    goto abort_due_to_error;
  }
  pBt = db->aDb[pOp->p1].pBt;

  if( pBt ){
    rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
    testcase( rc==SQLITE_BUSY_SNAPSHOT );
    testcase( rc==SQLITE_BUSY_RECOVERY );
    if( rc==SQLITE_BUSY ){
    if( (rc&0xff)==SQLITE_BUSY ){
      p->pc = (int)(pOp - aOp);
      p->rc = rc = SQLITE_BUSY;
      p->rc = rc;
      goto vdbe_return;
    }
    if( rc!=SQLITE_OK ){
      goto abort_due_to_error;
    }

    if( pOp->p2 && p->usesStmtJournal 
79007
79008
79009
79010
79011
79012
79013

79014

79015
79016
79017
79018
79019
79020
79021
79101
79102
79103
79104
79105
79106
79107
79108

79109
79110
79111
79112
79113
79114
79115
79116







+
-
+







          }
        }
      }
#endif
      for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
        int j;
        for(j=0; j<pIdx->nKeyCol; j++){
          /* FIXME: Be smarter about indexes that use expressions */
          if( pIdx->aiColumn[j]==iCol ){
          if( pIdx->aiColumn[j]==iCol || pIdx->aiColumn[j]==(-2) ){
            zFault = "indexed";
          }
        }
      }
      if( zFault ){
        sqlite3DbFree(db, zErr);
        zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
82588
82589
82590
82591
82592
82593
82594





82595
82596
82597
82598
82599
82600
82601
82683
82684
82685
82686
82687
82688
82689
82690
82691
82692
82693
82694
82695
82696
82697
82698
82699
82700
82701







+
+
+
+
+








  pSrc = p->pSrc;
  if( ALWAYS(pSrc) ){
    for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
      if( sqlite3WalkSelect(pWalker, pItem->pSelect) ){
        return WRC_Abort;
      }
      if( pItem->fg.isTabFunc
       && sqlite3WalkExprList(pWalker, pItem->u1.pFuncArg)
      ){
        return WRC_Abort;
      }
    }
  }
  return WRC_Continue;
} 

/*
** Call sqlite3WalkExpr() for every expression in Select statement p.
82685
82686
82687
82688
82689
82690
82691
82692
82693
82694
82695
82696
82697
82698
82699
82700
82701
82702
82703
82704
82705
82706
82707
82708
82709
82710
82711
82712
82713
82714
82715
82716
82717
82718
82719
82720
82721
82722
82785
82786
82787
82788
82789
82790
82791
























82792
82793
82794
82795
82796
82797
82798







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







  }
}

/*
** Turn the pExpr expression into an alias for the iCol-th column of the
** result set in pEList.
**
** If the result set column is a simple column reference, then this routine
** makes an exact copy.  But for any other kind of expression, this
** routine make a copy of the result set column as the argument to the
** TK_AS operator.  The TK_AS operator causes the expression to be
** evaluated just once and then reused for each alias.
**
** The reason for suppressing the TK_AS term when the expression is a simple
** column reference is so that the column reference will be recognized as
** usable by indices within the WHERE clause processing logic. 
**
** The TK_AS operator is inhibited if zType[0]=='G'.  This means
** that in a GROUP BY clause, the expression is evaluated twice.  Hence:
**
**     SELECT random()%5 AS x, count(*) FROM tab GROUP BY x
**
** Is equivalent to:
**
**     SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5
**
** The result of random()%5 in the GROUP BY clause is probably different
** from the result in the result-set.  On the other hand Standard SQL does
** not allow the GROUP BY clause to contain references to result-set columns.
** So this should never come up in well-formed queries.
**
** If the reference is followed by a COLLATE operator, then make sure
** the COLLATE operator is preserved.  For example:
**
**     SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase;
**
** Should be transformed into:
**
82742
82743
82744
82745
82746
82747
82748
82749
82750

82751
82752
82753
82754
82755
82756
82757
82758
82759
82760
82761

82762
82763
82764
82765
82766
82767
82768
82818
82819
82820
82821
82822
82823
82824


82825








82826
82827
82828
82829
82830
82831
82832
82833
82834
82835
82836







-
-
+
-
-
-
-
-
-
-
-



+








  assert( iCol>=0 && iCol<pEList->nExpr );
  pOrig = pEList->a[iCol].pExpr;
  assert( pOrig!=0 );
  db = pParse->db;
  pDup = sqlite3ExprDup(db, pOrig, 0);
  if( pDup==0 ) return;
  if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
    incrAggFunctionDepth(pDup, nSubquery);
  if( zType[0]!='G' ) incrAggFunctionDepth(pDup, nSubquery);
    pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
    if( pDup==0 ) return;
    ExprSetProperty(pDup, EP_Skip);
    if( pEList->a[iCol].u.x.iAlias==0 ){
      pEList->a[iCol].u.x.iAlias = (u16)(++pParse->nAlias);
    }
    pDup->iTable = pEList->a[iCol].u.x.iAlias;
  }
  if( pExpr->op==TK_COLLATE ){
    pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
  }
  ExprSetProperty(pDup, EP_Alias);

  /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This 
  ** prevents ExprDelete() from deleting the Expr structure itself,
  ** allowing it to be repopulated by the memcpy() on the following line.
  ** The pExpr->u.zToken might point into memory that will be freed by the
  ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
  ** make a copy of the token before doing the sqlite3DbFree().
82946
82947
82948
82949
82950
82951
82952
82953

82954
82955
82956
82957
82958
82959
82960
82961
82962
82963
82964
82965
82966
82967
82968
82969


82970
82971
82972
82973
82974
82975
82976
83014
83015
83016
83017
83018
83019
83020

83021
83022
83023
83024
83025
83026
83027
83028
83029
83030
83031
83032
83033
83034
83035


83036
83037
83038
83039
83040
83041
83042
83043
83044







-
+














-
-
+
+







        for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
          if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
            /* If there has been exactly one prior match and this match
            ** is for the right-hand table of a NATURAL JOIN or is in a 
            ** USING clause, then skip this match.
            */
            if( cnt==1 ){
              if( pItem->jointype & JT_NATURAL ) continue;
              if( pItem->fg.jointype & JT_NATURAL ) continue;
              if( nameInUsingClause(pItem->pUsing, zCol) ) continue;
            }
            cnt++;
            pMatch = pItem;
            /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
            pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
            break;
          }
        }
      }
      if( pMatch ){
        pExpr->iTable = pMatch->iCursor;
        pExpr->pTab = pMatch->pTab;
        /* RIGHT JOIN not (yet) supported */
        assert( (pMatch->jointype & JT_RIGHT)==0 );
        if( (pMatch->jointype & JT_LEFT)!=0 ){
        assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
        if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
          ExprSetProperty(pExpr, EP_CanBeNull);
        }
        pSchema = pExpr->pTab->pSchema;
      }
    } /* if( pSrcList ) */

#ifndef SQLITE_OMIT_TRIGGER
83047
83048
83049
83050
83051
83052
83053
83054

83055
83056

83057
83058
83059
83060
83061
83062
83063
83115
83116
83117
83118
83119
83120
83121

83122
83123

83124
83125
83126
83127
83128
83129
83130
83131







-
+

-
+







    **
    ** In cases like this, replace pExpr with a copy of the expression that
    ** forms the result set entry ("a+b" in the example) and return immediately.
    ** Note that the expression in the result set should have already been
    ** resolved by the time the WHERE clause is resolved.
    **
    ** The ability to use an output result-set column in the WHERE, GROUP BY,
    ** or HAVING clauses, or as part of a larger expression in the ORDRE BY
    ** or HAVING clauses, or as part of a larger expression in the ORDER BY
    ** clause is not standard SQL.  This is a (goofy) SQLite extension, that
    ** is supported for backwards compatibility only.  TO DO: Issue a warning
    ** is supported for backwards compatibility only. Hence, we issue a warning
    ** on sqlite3_log() whenever the capability is used.
    */
    if( (pEList = pNC->pEList)!=0
     && zTab==0
     && cnt==0
    ){
      for(j=0; j<pEList->nExpr; j++){
83146
83147
83148
83149
83150
83151
83152
83153

83154
83155
83156
83157
83158
83159
83160
83214
83215
83216
83217
83218
83219
83220

83221
83222
83223
83224
83225
83226
83227
83228







-
+







  pExpr->pLeft = 0;
  sqlite3ExprDelete(db, pExpr->pRight);
  pExpr->pRight = 0;
  pExpr->op = (isTrigger ? TK_TRIGGER : TK_COLUMN);
lookupname_end:
  if( cnt==1 ){
    assert( pNC!=0 );
    if( pExpr->op!=TK_AS ){
    if( !ExprHasProperty(pExpr, EP_Alias) ){
      sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
    }
    /* Increment the nRef value on all name contexts from TopNC up to
    ** the point where the name matched. */
    for(;;){
      assert( pTopNC!=0 );
      pTopNC->nRef++;
83187
83188
83189
83190
83191
83192
83193
83194
83195


83196
83197

83198
83199
83200


83201

83202
83203


83204
83205
83206
83207

83208
83209
83210
83211
83212
83213
83214
83215
83216
83217
83218



83219
83220
83221
83222
83223
83224
83225
83226
83227
83228
83229
83230
83255
83256
83257
83258
83259
83260
83261


83262
83263
83264

83265
83266
83267

83268
83269
83270
83271


83272
83273




83274
83275










83276
83277
83278
83279
83280



83281
83282
83283
83284
83285
83286
83287







-
-
+
+

-
+


-
+
+

+
-
-
+
+
-
-
-
-
+

-
-
-
-
-
-
-
-
-
-
+
+
+


-
-
-







    }
    ExprSetProperty(p, EP_Resolved);
  }
  return p;
}

/*
** Report an error that an expression is not valid for a partial index WHERE
** clause.
** Report an error that an expression is not valid for some set of
** pNC->ncFlags values determined by validMask.
*/
static void notValidPartIdxWhere(
static void notValid(
  Parse *pParse,       /* Leave error message here */
  NameContext *pNC,    /* The name context */
  const char *zMsg     /* Type of error */
  const char *zMsg,    /* Type of error */
  int validMask        /* Set of contexts for which prohibited */
){
  assert( (validMask&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr))==0 );
  if( (pNC->ncFlags & NC_PartIdx)!=0 ){
    sqlite3ErrorMsg(pParse, "%s prohibited in partial index WHERE clauses",
  if( (pNC->ncFlags & validMask)!=0 ){
    const char *zIn = "partial index WHERE clauses";
                    zMsg);
  }
}

    if( pNC->ncFlags & NC_IdxExpr )      zIn = "index expressions";
#ifndef SQLITE_OMIT_CHECK
/*
** Report an error that an expression is not valid for a CHECK constraint.
*/
static void notValidCheckConstraint(
  Parse *pParse,       /* Leave error message here */
  NameContext *pNC,    /* The name context */
  const char *zMsg     /* Type of error */
){
  if( (pNC->ncFlags & NC_IsCheck)!=0 ){
    sqlite3ErrorMsg(pParse,"%s prohibited in CHECK constraints", zMsg);
    else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
#endif
    sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
  }
}
#else
# define notValidCheckConstraint(P,N,M)
#endif

/*
** Expression p should encode a floating point value between 1.0 and 0.0.
** Return 1024 times this value.  Or return -1 if p is not a floating point
** value between 1.0 and 0.0.
*/
static int exprProbability(Expr *p){
83301
83302
83303
83304
83305
83306
83307


83308
83309
83310
83311
83312
83313
83314
83358
83359
83360
83361
83362
83363
83364
83365
83366
83367
83368
83369
83370
83371
83372
83373







+
+







    case TK_DOT: {
      const char *zColumn;
      const char *zTable;
      const char *zDb;
      Expr *pRight;

      /* if( pSrcList==0 ) break; */
      notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr);
      /*notValid(pParse, pNC, "the \".\" operator", NC_PartIdx|NC_IsCheck, 1);*/
      pRight = pExpr->pRight;
      if( pRight->op==TK_ID ){
        zDb = 0;
        zTable = pExpr->pLeft->u.zToken;
        zColumn = pRight->u.zToken;
      }else{
        assert( pRight->op==TK_DOT );
83330
83331
83332
83333
83334
83335
83336
83337

83338
83339
83340
83341
83342
83343
83344
83389
83390
83391
83392
83393
83394
83395

83396
83397
83398
83399
83400
83401
83402
83403







-
+







      int auth;                   /* Authorization to use the function */
      int nId;                    /* Number of characters in function name */
      const char *zId;            /* The function name. */
      FuncDef *pDef;              /* Information about the function */
      u8 enc = ENC(pParse->db);   /* The database encoding */

      assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
      notValidPartIdxWhere(pParse, pNC, "functions");
      notValid(pParse, pNC, "functions", NC_PartIdx);
      zId = pExpr->u.zToken;
      nId = sqlite3Strlen30(zId);
      pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
      if( pDef==0 ){
        pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
        if( pDef==0 ){
          no_such_func = 1;
83378
83379
83380
83381
83382
83383
83384
83385




83386
83387






83388
83389
83390
83391
83392
83393
83394
83437
83438
83439
83440
83441
83442
83443

83444
83445
83446
83447
83448
83449
83450
83451
83452
83453
83454
83455
83456
83457
83458
83459
83460
83461
83462







-
+
+
+
+


+
+
+
+
+
+







                                    pDef->zName);
            pNC->nErr++;
          }
          pExpr->op = TK_NULL;
          return WRC_Prune;
        }
#endif
        if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ){
        if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
          /* For the purposes of the EP_ConstFunc flag, date and time
          ** functions and other functions that change slowly are considered
          ** constant because they are constant for the duration of one query */
          ExprSetProperty(pExpr,EP_ConstFunc);
        }
        if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
          /* Date/time functions that use 'now', and other functions like
          ** sqlite_version() that might change over time cannot be used
          ** in an index. */
          notValid(pParse, pNC, "non-deterministic functions", NC_IdxExpr);
        }
      }
      if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
        sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
        pNC->nErr++;
        is_agg = 0;
      }else if( no_such_func && pParse->db->init.busy==0 ){
        sqlite3ErrorMsg(pParse, "no such function: %.*s", nId, zId);
83426
83427
83428
83429
83430
83431
83432
83433

83434
83435
83436
83437
83438
83439
83440
83441
83442
83443
83444

83445
83446
83447
83448
83449
83450
83451
83452
83494
83495
83496
83497
83498
83499
83500

83501

83502
83503
83504
83505
83506
83507
83508
83509
83510

83511

83512
83513
83514
83515
83516
83517
83518







-
+
-









-
+
-







    case TK_SELECT:
    case TK_EXISTS:  testcase( pExpr->op==TK_EXISTS );
#endif
    case TK_IN: {
      testcase( pExpr->op==TK_IN );
      if( ExprHasProperty(pExpr, EP_xIsSelect) ){
        int nRef = pNC->nRef;
        notValidCheckConstraint(pParse, pNC, "subqueries");
        notValid(pParse, pNC, "subqueries", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
        notValidPartIdxWhere(pParse, pNC, "subqueries");
        sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
        assert( pNC->nRef>=nRef );
        if( nRef!=pNC->nRef ){
          ExprSetProperty(pExpr, EP_VarSelect);
        }
      }
      break;
    }
    case TK_VARIABLE: {
      notValidCheckConstraint(pParse, pNC, "parameters");
      notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
      notValidPartIdxWhere(pParse, pNC, "parameters");
      break;
    }
  }
  return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
}

/*
83782
83783
83784
83785
83786
83787
83788
83789
83790
83791
83792
83793
83794
83795
83796
83848
83849
83850
83851
83852
83853
83854

83855
83856
83857
83858
83859
83860
83861







-







*/
static int resolveSelectStep(Walker *pWalker, Select *p){
  NameContext *pOuterNC;  /* Context that contains this SELECT */
  NameContext sNC;        /* Name context of this SELECT */
  int isCompound;         /* True if p is a compound select */
  int nCompound;          /* Number of compound terms processed so far */
  Parse *pParse;          /* Parsing context */
  ExprList *pEList;       /* Result set expression list */
  int i;                  /* Loop counter */
  ExprList *pGroupBy;     /* The GROUP BY clause */
  Select *pLeftmost;      /* Left-most of SELECT of a compound */
  sqlite3 *db;            /* Database connection */
  

  assert( p!=0 );
83855
83856
83857
83858
83859
83860
83861
83862

83863
83864
83865
83866
83867
83868
83869
83870
83871
83872


83873
83874
83875
83876
83877
83878
83879
83880
83881
83882
83883
83884
83885
83886
83887
83888

83889
83890
83891
83892
83893
83894
83895
83896
83897
83898
83920
83921
83922
83923
83924
83925
83926

83927
83928
83929
83930
83931
83932
83933
83934
83935


83936
83937
83938
83939
83940
83941
83942
83943
83944
83945
83946
83947
83948





83949



83950
83951
83952
83953
83954
83955
83956







-
+








-
-
+
+











-
-
-
-
-
+
-
-
-







        int nRef = 0;             /* Refcount for pOuterNC and outer contexts */
        const char *zSavedContext = pParse->zAuthContext;

        /* Count the total number of references to pOuterNC and all of its
        ** parent contexts. After resolving references to expressions in
        ** pItem->pSelect, check if this value has changed. If so, then
        ** SELECT statement pItem->pSelect must be correlated. Set the
        ** pItem->isCorrelated flag if this is the case. */
        ** pItem->fg.isCorrelated flag if this is the case. */
        for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef += pNC->nRef;

        if( pItem->zName ) pParse->zAuthContext = pItem->zName;
        sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
        pParse->zAuthContext = zSavedContext;
        if( pParse->nErr || db->mallocFailed ) return WRC_Abort;

        for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef -= pNC->nRef;
        assert( pItem->isCorrelated==0 && nRef<=0 );
        pItem->isCorrelated = (nRef!=0);
        assert( pItem->fg.isCorrelated==0 && nRef<=0 );
        pItem->fg.isCorrelated = (nRef!=0);
      }
    }
  
    /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
    ** resolve the result-set expression list.
    */
    sNC.ncFlags = NC_AllowAgg;
    sNC.pSrcList = p->pSrc;
    sNC.pNext = pOuterNC;
  
    /* Resolve names in the result set. */
    pEList = p->pEList;
    assert( pEList!=0 );
    for(i=0; i<pEList->nExpr; i++){
      Expr *pX = pEList->a[i].pExpr;
      if( sqlite3ResolveExprNames(&sNC, pX) ){
    if( sqlite3ResolveExprListNames(&sNC, p->pEList) ) return WRC_Abort;
        return WRC_Abort;
      }
    }
  
    /* If there are no aggregate functions in the result-set, and no GROUP BY 
    ** expression, do not allow aggregates in any of the other expressions.
    */
    assert( (p->selFlags & SF_Aggregate)==0 );
    pGroupBy = p->pGroupBy;
    if( pGroupBy || (sNC.ncFlags & NC_HasAgg)!=0 ){
83916
83917
83918
83919
83920
83921
83922










83923
83924
83925
83926
83927
83928
83929
83974
83975
83976
83977
83978
83979
83980
83981
83982
83983
83984
83985
83986
83987
83988
83989
83990
83991
83992
83993
83994
83995
83996
83997







+
+
+
+
+
+
+
+
+
+







    **
    ** Minor point: If this is the case, then the expression will be
    ** re-evaluated for each reference to it.
    */
    sNC.pEList = p->pEList;
    if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
    if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;

    /* Resolve names in table-valued-function arguments */
    for(i=0; i<p->pSrc->nSrc; i++){
      struct SrcList_item *pItem = &p->pSrc->a[i];
      if( pItem->fg.isTabFunc
       && sqlite3ResolveExprListNames(&sNC, pItem->u1.pFuncArg) 
      ){
        return WRC_Abort;
      }
    }

    /* The ORDER BY and GROUP BY clauses may not refer to terms in
    ** outer queries 
    */
    sNC.pNext = 0;
    sNC.ncFlags |= NC_AllowAgg;

84080
84081
84082
84083
84084
84085
84086
















84087
84088
84089
84090
84091
84092
84093
84148
84149
84150
84151
84152
84153
84154
84155
84156
84157
84158
84159
84160
84161
84162
84163
84164
84165
84166
84167
84168
84169
84170
84171
84172
84173
84174
84175
84176
84177







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  if( pNC->ncFlags & NC_HasAgg ){
    ExprSetProperty(pExpr, EP_Agg);
  }
  pNC->ncFlags |= savedHasAgg;
  return ExprHasProperty(pExpr, EP_Error);
}

/*
** Resolve all names for all expression in an expression list.  This is
** just like sqlite3ResolveExprNames() except that it works for an expression
** list rather than a single expression.
*/
SQLITE_PRIVATE int sqlite3ResolveExprListNames( 
  NameContext *pNC,       /* Namespace to resolve expressions in. */
  ExprList *pList         /* The expression list to be analyzed. */
){
  int i;
  assert( pList!=0 );
  for(i=0; i<pList->nExpr; i++){
    if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort;
  }
  return WRC_Continue;
}

/*
** Resolve all names in all expressions of a SELECT and in all
** decendents of the SELECT, including compounds off of p->pPrior,
** subqueries in expressions, and subqueries used as FROM clause
** terms.
**
84123
84124
84125
84126
84127
84128
84129
84130

84131
84132
84133
84134
84135
84136
84137
84138

84139
84140
84141
84142
84143
84144
84145
84146
84147
84148
84149

84150
84151
84152
84153
84154
84155
84156
84157
84158
84159
84160
84161
84162
84207
84208
84209
84210
84211
84212
84213

84214
84215
84216
84217
84218
84219

84220

84221
84222
84223
84224
84225
84226
84227
84228
84229
84230
84231

84232






84233
84234
84235
84236
84237
84238
84239







-
+





-

-
+










-
+
-
-
-
-
-
-







** is set to -1 and the Expr.iColumn value is set to the column number.
**
** Any errors cause an error message to be set in pParse.
*/
SQLITE_PRIVATE void sqlite3ResolveSelfReference(
  Parse *pParse,      /* Parsing context */
  Table *pTab,        /* The table being referenced */
  int type,           /* NC_IsCheck or NC_PartIdx */
  int type,           /* NC_IsCheck or NC_PartIdx or NC_IdxExpr */
  Expr *pExpr,        /* Expression to resolve.  May be NULL. */
  ExprList *pList     /* Expression list to resolve.  May be NUL. */
){
  SrcList sSrc;                   /* Fake SrcList for pParse->pNewTable */
  NameContext sNC;                /* Name context for pParse->pNewTable */
  int i;                          /* Loop counter */

  assert( type==NC_IsCheck || type==NC_PartIdx );
  assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr );
  memset(&sNC, 0, sizeof(sNC));
  memset(&sSrc, 0, sizeof(sSrc));
  sSrc.nSrc = 1;
  sSrc.a[0].zName = pTab->zName;
  sSrc.a[0].pTab = pTab;
  sSrc.a[0].iCursor = -1;
  sNC.pParse = pParse;
  sNC.pSrcList = &sSrc;
  sNC.ncFlags = type;
  if( sqlite3ResolveExprNames(&sNC, pExpr) ) return;
  if( pList ){
  if( pList ) sqlite3ResolveExprListNames(&sNC, pList);
    for(i=0; i<pList->nExpr; i++){
      if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
        return;
      }
    }
  }
}

/************** End of resolve.c *********************************************/
/************** Begin file expr.c ********************************************/
/*
** 2001 September 15
**
84246
84247
84248
84249
84250
84251
84252
84253

84254
84255
84256
84257
84258
84259
84260
84261
84262
84263
84264

84265
84266
84267
84268
84269
84270
84271
84323
84324
84325
84326
84327
84328
84329

84330
84331
84332
84333
84334
84335
84336
84337
84338
84339
84340

84341
84342
84343
84344
84345
84346
84347
84348







-
+










-
+







  assert( zC!=0 );
  s.z = zC;
  s.n = sqlite3Strlen30(s.z);
  return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0);
}

/*
** Skip over any TK_COLLATE or TK_AS operators and any unlikely()
** Skip over any TK_COLLATE operators and any unlikely()
** or likelihood() function at the root of an expression.
*/
SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){
  while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
    if( ExprHasProperty(pExpr, EP_Unlikely) ){
      assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
      assert( pExpr->x.pList->nExpr>0 );
      assert( pExpr->op==TK_FUNCTION );
      pExpr = pExpr->x.pList->a[0].pExpr;
    }else{
      assert( pExpr->op==TK_COLLATE || pExpr->op==TK_AS );
      assert( pExpr->op==TK_COLLATE );
      pExpr = pExpr->pLeft;
    }
  }   
  return pExpr;
}

/*
84588
84589
84590
84591
84592
84593
84594
84595

84596
84597
84598
84599
84600
84601
84602
84665
84666
84667
84668
84669
84670
84671

84672
84673
84674
84675
84676
84677
84678
84679







-
+







**
** Construct a new expression node and return a pointer to it.  Memory
** for this node and for the pToken argument is a single allocation
** obtained from sqlite3DbMalloc().  The calling function
** is responsible for making sure the node eventually gets freed.
**
** If dequote is true, then the token (if it exists) is dequoted.
** If dequote is false, no dequoting is performance.  The deQuote
** If dequote is false, no dequoting is performed.  The deQuote
** parameter is ignored if pToken is NULL or if the token does not
** appear to be quoted.  If the quotes were of the form "..." (double-quotes)
** then the EP_DblQuoted flag is set on the expression node.
**
** Special case:  If op==TK_INTEGER and pToken points to a string that
** can be translated into a 32-bit integer, then the token is not
** stored in u.zToken.  Instead, the integer values is written
85189
85190
85191
85192
85193
85194
85195
85196

85197
85198
85199
85200

85201
85202
85203
85204
85205







85206
85207
85208
85209
85210
85211
85212
85266
85267
85268
85269
85270
85271
85272

85273
85274
85275
85276

85277





85278
85279
85280
85281
85282
85283
85284
85285
85286
85287
85288
85289
85290
85291







-
+



-
+
-
-
-
-
-
+
+
+
+
+
+
+







    struct SrcList_item *pNewItem = &pNew->a[i];
    struct SrcList_item *pOldItem = &p->a[i];
    Table *pTab;
    pNewItem->pSchema = pOldItem->pSchema;
    pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
    pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
    pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
    pNewItem->jointype = pOldItem->jointype;
    pNewItem->fg = pOldItem->fg;
    pNewItem->iCursor = pOldItem->iCursor;
    pNewItem->addrFillSub = pOldItem->addrFillSub;
    pNewItem->regReturn = pOldItem->regReturn;
    pNewItem->isCorrelated = pOldItem->isCorrelated;
    if( pNewItem->fg.isIndexedBy ){
    pNewItem->viaCoroutine = pOldItem->viaCoroutine;
    pNewItem->isRecursive = pOldItem->isRecursive;
    pNewItem->zIndexedBy = sqlite3DbStrDup(db, pOldItem->zIndexedBy);
    pNewItem->notIndexed = pOldItem->notIndexed;
    pNewItem->pIndex = pOldItem->pIndex;
      pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
    }
    pNewItem->pIBIndex = pOldItem->pIBIndex;
    if( pNewItem->fg.isTabFunc ){
      pNewItem->u1.pFuncArg = 
          sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
    }
    pTab = pNewItem->pTab = pOldItem->pTab;
    if( pTab ){
      pTab->nRef++;
    }
    pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
    pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
    pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
85312
85313
85314
85315
85316
85317
85318














85319
85320
85321
85322
85323
85324
85325
85391
85392
85393
85394
85395
85396
85397
85398
85399
85400
85401
85402
85403
85404
85405
85406
85407
85408
85409
85410
85411
85412
85413
85414
85415
85416
85417
85418







+
+
+
+
+
+
+
+
+
+
+
+
+
+








no_mem:     
  /* Avoid leaking memory if malloc has failed. */
  sqlite3ExprDelete(db, pExpr);
  sqlite3ExprListDelete(db, pList);
  return 0;
}

/*
** Set the sort order for the last element on the given ExprList.
*/
SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder){
  if( p==0 ) return;
  assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC>=0 && SQLITE_SO_DESC>0 );
  assert( p->nExpr>0 );
  if( iSortOrder<0 ){
    assert( p->a[p->nExpr-1].sortOrder==SQLITE_SO_ASC );
    return;
  }
  p->a[p->nExpr-1].sortOrder = (u8)iSortOrder;
}

/*
** Set the ExprList.a[].zName element of the most recently added item
** on the expression list.
**
** pList might be NULL following an OOM error.  But pName should never be
** NULL.  If a memory allocation fails, the pParse->db->mallocFailed flag
86284
86285
86286
86287
86288
86289
86290
86291

86292
86293
86294
86295
86296
86297
86298
86299
86300
86301
86302
86303
86304
86305
86306
86307
86308
86309

86310
86311
86312
86313
86314
86315
86316
86377
86378
86379
86380
86381
86382
86383

86384
86385
86386
86387
86388
86389
86390
86391
86392
86393
86394
86395
86396
86397
86398
86399
86400
86401

86402
86403
86404
86405
86406
86407
86408
86409







-
+

















-
+







                          (void*)pColl, P4_COLLSEQ); VdbeCoverage(v);
        sqlite3VdbeChangeP5(v, affinity | SQLITE_JUMPIFNULL);
      }
      sqlite3ReleaseTempReg(pParse, regToFree);
    }
    if( regCkNull ){
      sqlite3VdbeAddOp2(v, OP_IsNull, regCkNull, destIfNull); VdbeCoverage(v);
      sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
      sqlite3VdbeGoto(v, destIfFalse);
    }
    sqlite3VdbeResolveLabel(v, labelOk);
    sqlite3ReleaseTempReg(pParse, regCkNull);
  }else{
  
    /* If the LHS is NULL, then the result is either false or NULL depending
    ** on whether the RHS is empty or not, respectively.
    */
    if( sqlite3ExprCanBeNull(pExpr->pLeft) ){
      if( destIfNull==destIfFalse ){
        /* Shortcut for the common case where the false and NULL outcomes are
        ** the same. */
        sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); VdbeCoverage(v);
      }else{
        int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); VdbeCoverage(v);
        sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
        VdbeCoverage(v);
        sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
        sqlite3VdbeGoto(v, destIfNull);
        sqlite3VdbeJumpHere(v, addr1);
      }
    }
  
    if( eType==IN_INDEX_ROWID ){
      /* In this case, the RHS is the ROWID of table b-tree
      */
86352
86353
86354
86355
86356
86357
86358
86359

86360
86361
86362
86363
86364
86365
86366
86445
86446
86447
86448
86449
86450
86451

86452
86453
86454
86455
86456
86457
86458
86459







-
+







        ** answer is NULL if the RHS contains NULLs and the answer is
        ** FALSE if the RHS is NULL-free.
        */
        j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
        VdbeCoverage(v);
        sqlite3VdbeAddOp2(v, OP_IsNull, rRhsHasNull, destIfNull);
        VdbeCoverage(v);
        sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
        sqlite3VdbeGoto(v, destIfFalse);
        sqlite3VdbeJumpHere(v, j1);
      }
    }
  }
  sqlite3ReleaseTempReg(pParse, r1);
  sqlite3ExprCachePop(pParse);
  VdbeComment((v, "end IN expr"));
86570
86571
86572
86573
86574
86575
86576






















86577
86578
86579
86580
86581
86582
86583
86663
86664
86665
86666
86667
86668
86669
86670
86671
86672
86673
86674
86675
86676
86677
86678
86679
86680
86681
86682
86683
86684
86685
86686
86687
86688
86689
86690
86691
86692
86693
86694
86695
86696
86697
86698







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  struct yColCache *p;
  for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
    if( p->iReg==iReg ){
      p->tempReg = 0;
    }
  }
}

/* Generate code that will load into register regOut a value that is
** appropriate for the iIdxCol-th column of index pIdx.
*/
SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(
  Parse *pParse,  /* The parsing context */
  Index *pIdx,    /* The index whose column is to be loaded */
  int iTabCur,    /* Cursor pointing to a table row */
  int iIdxCol,    /* The column of the index to be loaded */
  int regOut      /* Store the index column value in this register */
){
  i16 iTabCol = pIdx->aiColumn[iIdxCol];
  if( iTabCol>=(-1) ){
    sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur,
                                    iTabCol, regOut);
    return;
  }
  assert( pIdx->aColExpr );
  assert( pIdx->aColExpr->nExpr>iIdxCol );
  pParse->iSelfTab = iTabCur;
  sqlite3ExprCode(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
}

/*
** Generate code to extract the value of the iCol-th column of a table.
*/
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
  Vdbe *v,        /* The VDBE under construction */
  Table *pTab,    /* The table containing the value */
86756
86757
86758
86759
86760
86761
86762
86763
86764



86765
86766
86767
86768
86769
86770
86771
86772
86773
86774
86775
86776
86777
86778
86779
86780
86781
86782
86783
86784
86785

86786
86787
86788
86789
86790
86791
86792
86871
86872
86873
86874
86875
86876
86877


86878
86879
86880
86881
86882
86883
86884
86885
86886
86887
86888
86889
86890
86891
86892
86893
86894
86895
86896
86897
86898
86899
86900

86901
86902
86903
86904
86905
86906
86907
86908







-
-
+
+
+




















-
+







      int iTab = pExpr->iTable;
      if( iTab<0 ){
        if( pParse->ckBase>0 ){
          /* Generating CHECK constraints or inserting into partial index */
          inReg = pExpr->iColumn + pParse->ckBase;
          break;
        }else{
          /* Deleting from a partial index */
          iTab = pParse->iPartIdxTab;
          /* Coding an expression that is part of an index where column names
          ** in the index refer to the table to which the index belongs */
          iTab = pParse->iSelfTab;
        }
      }
      inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
                               pExpr->iColumn, iTab, target,
                               pExpr->op2);
      break;
    }
    case TK_INTEGER: {
      codeInteger(pParse, pExpr, 0, target);
      break;
    }
#ifndef SQLITE_OMIT_FLOATING_POINT
    case TK_FLOAT: {
      assert( !ExprHasProperty(pExpr, EP_IntValue) );
      codeReal(v, pExpr->u.zToken, 0, target);
      break;
    }
#endif
    case TK_STRING: {
      assert( !ExprHasProperty(pExpr, EP_IntValue) );
      sqlite3VdbeAddOp4(v, OP_String8, 0, target, 0, pExpr->u.zToken, 0);
      sqlite3VdbeLoadString(v, target, pExpr->u.zToken);
      break;
    }
    case TK_NULL: {
      sqlite3VdbeAddOp2(v, OP_Null, 0, target);
      break;
    }
#ifndef SQLITE_OMIT_BLOB_LITERAL
86817
86818
86819
86820
86821
86822
86823
86824
86825
86826
86827
86828
86829
86830
86831
86832
86833
86834
86933
86934
86935
86936
86937
86938
86939




86940
86941
86942
86943
86944
86945
86946







-
-
-
-







      }
      break;
    }
    case TK_REGISTER: {
      inReg = pExpr->iTable;
      break;
    }
    case TK_AS: {
      inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
      break;
    }
#ifndef SQLITE_OMIT_CAST
    case TK_CAST: {
      /* Expressions of the form:   CAST(pLeft AS token) */
      inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
      if( inReg!=target ){
        sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
        inReg = target;
87051
87052
87053
87054
87055
87056
87057
87058

87059
87060
87061
87062
87063
87064
87065
87163
87164
87165
87166
87167
87168
87169

87170
87171
87172
87173
87174
87175
87176
87177







-
+







            testcase( pDef->funcFlags & OPFLAG_LENGTHARG );
            pFarg->a[0].pExpr->op2 = 
                  pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG);
          }
        }

        sqlite3ExprCachePush(pParse);     /* Ticket 2ea2425d34be */
        sqlite3ExprCodeExprList(pParse, pFarg, r1,
        sqlite3ExprCodeExprList(pParse, pFarg, r1, 0,
                                SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR);
        sqlite3ExprCachePop(pParse);      /* Ticket 2ea2425d34be */
      }else{
        r1 = 0;
      }
#ifndef SQLITE_OMIT_VIRTUALTABLE
      /* Possibly overload the function if the first argument is
87275
87276
87277
87278
87279
87280
87281
87282

87283
87284
87285
87286
87287
87288
87289
87387
87388
87389
87390
87391
87392
87393

87394
87395
87396
87397
87398
87399
87400
87401







-
+







          pTest = aListelem[i].pExpr;
        }
        nextCase = sqlite3VdbeMakeLabel(v);
        testcase( pTest->op==TK_COLUMN );
        sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
        testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
        sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
        sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
        sqlite3VdbeGoto(v, endLabel);
        sqlite3ExprCachePop(pParse);
        sqlite3VdbeResolveLabel(v, nextCase);
      }
      if( (nExpr&1)!=0 ){
        sqlite3ExprCachePush(pParse);
        sqlite3ExprCode(pParse, pEList->a[nExpr-1].pExpr, target);
        sqlite3ExprCachePop(pParse);
87467
87468
87469
87470
87471
87472
87473

87474
87475
87476
87477

87478

87479
87480
87481
87482
87483
87484
87485


87486

87487
87488
87489
87490
87491
87492
87493
87494
87495
87496
87497
87498
87499
87579
87580
87581
87582
87583
87584
87585
87586
87587
87588
87589

87590
87591
87592
87593
87594
87595
87596
87597
87598
87599
87600
87601

87602
87603
87604
87605
87606
87607

87608
87609
87610
87611
87612
87613
87614







+



-
+

+







+
+
-
+





-







** The SQLITE_ECEL_FACTOR argument allows constant arguments to be
** factored out into initialization code.
*/
SQLITE_PRIVATE int sqlite3ExprCodeExprList(
  Parse *pParse,     /* Parsing context */
  ExprList *pList,   /* The expression list to be coded */
  int target,        /* Where to write results */
  int srcReg,        /* Source registers if SQLITE_ECEL_REF */
  u8 flags           /* SQLITE_ECEL_* flags */
){
  struct ExprList_item *pItem;
  int i, n;
  int i, j, n;
  u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy;
  Vdbe *v = pParse->pVdbe;
  assert( pList!=0 );
  assert( target>0 );
  assert( pParse->pVdbe!=0 );  /* Never gets this far otherwise */
  n = pList->nExpr;
  if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
  for(pItem=pList->a, i=0; i<n; i++, pItem++){
    Expr *pExpr = pItem->pExpr;
    if( (flags & SQLITE_ECEL_REF)!=0 && (j = pList->a[i].u.x.iOrderByCol)>0 ){
      sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
    if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
    }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
      sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
    }else{
      int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
      if( inReg!=target+i ){
        VdbeOp *pOp;
        Vdbe *v = pParse->pVdbe;
        if( copyOp==OP_Copy
         && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
         && pOp->p1+pOp->p3+1==inReg
         && pOp->p2+pOp->p3+1==target+i
        ){
          pOp->p3++;
        }else{
87662
87663
87664
87665
87666
87667
87668
87669

87670
87671
87672
87673
87674
87675
87676

87677
87678
87679
87680
87681
87682
87683
87777
87778
87779
87780
87781
87782
87783

87784
87785
87786
87787
87788
87789
87790

87791
87792
87793
87794
87795
87796
87797
87798







-
+






-
+







      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case TK_IN: {
      int destIfFalse = sqlite3VdbeMakeLabel(v);
      int destIfNull = jumpIfNull ? dest : destIfFalse;
      sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
      sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
      sqlite3VdbeGoto(v, dest);
      sqlite3VdbeResolveLabel(v, destIfFalse);
      break;
    }
#endif
    default: {
      if( exprAlwaysTrue(pExpr) ){
        sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
        sqlite3VdbeGoto(v, dest);
      }else if( exprAlwaysFalse(pExpr) ){
        /* No-op */
      }else{
        r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
        sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
        VdbeCoverage(v);
        testcase( regFree1==0 );
87825
87826
87827
87828
87829
87830
87831
87832

87833
87834
87835
87836
87837
87838
87839
87940
87941
87942
87943
87944
87945
87946

87947
87948
87949
87950
87951
87952
87953
87954







-
+







        sqlite3VdbeResolveLabel(v, destIfNull);
      }
      break;
    }
#endif
    default: {
      if( exprAlwaysFalse(pExpr) ){
        sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
        sqlite3VdbeGoto(v, dest);
      }else if( exprAlwaysTrue(pExpr) ){
        /* no-op */
      }else{
        r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
        sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
        VdbeCoverage(v);
        testcase( regFree1==0 );
87901
87902
87903
87904
87905
87906
87907


87908

87909
87910
87911
87912
87913
87914
87915
88016
88017
88018
88019
88020
88021
88022
88023
88024

88025
88026
88027
88028
88029
88030
88031
88032







+
+
-
+







    }
    if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft, iTab)<2 ){
      return 1;
    }
    return 2;
  }
  if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){
    if( pA->op==TK_FUNCTION ){
      if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
    if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
    }else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
      return pA->op==TK_COLLATE ? 1 : 2;
    }
  }
  if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
  if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
    if( combinedFlags & EP_xIsSelect ) return 2;
    if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
88809
88810
88811
88812
88813
88814
88815
88816

88817
88818
88819
88820
88821
88822
88823
88926
88927
88928
88929
88930
88931
88932

88933
88934
88935
88936
88937
88938
88939
88940







-
+







  ** one is defined. The xRename() callback will modify the names
  ** of any resources used by the v-table implementation (including other
  ** SQLite tables) that are identified by the name of the virtual table.
  */
#ifndef SQLITE_OMIT_VIRTUALTABLE
  if( pVTab ){
    int i = ++pParse->nMem;
    sqlite3VdbeAddOp4(v, OP_String8, 0, i, 0, zName, 0);
    sqlite3VdbeLoadString(v, i, zName);
    sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
    sqlite3MayAbort(pParse);
  }
#endif

  /* figure out how many UTF-8 characters are in zName */
  zTabName = pTab->zName;
90167
90168
90169
90170
90171
90172
90173
90174

90175
90176
90177
90178
90179
90180
90181
90284
90285
90286
90287
90288
90289
90290

90291
90292
90293
90294
90295
90296
90297
90298







-
+







  ** to use for scanning indexes (iIdxCur). No index cursor is opened at
  ** this time though.  */
  sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
  iTabCur = iTab++;
  iIdxCur = iTab++;
  pParse->nTab = MAX(pParse->nTab, iTab);
  sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
  sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
  sqlite3VdbeLoadString(v, regTabname, pTab->zName);

  for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
    int nCol;                     /* Number of columns in pIdx. "N" */
    int addrRewind;               /* Address of "OP_Rewind iIdxCur" */
    int addrNextRow;              /* Address of "next_row:" */
    const char *zIdxName;         /* Name of the index */
    int nColTest;                 /* Number of columns to test for changes */
90189
90190
90191
90192
90193
90194
90195
90196

90197
90198
90199
90200
90201
90202
90203
90306
90307
90308
90309
90310
90311
90312

90313
90314
90315
90316
90317
90318
90319
90320







-
+







    }else{
      nCol = pIdx->nColumn;
      zIdxName = pIdx->zName;
      nColTest = pIdx->uniqNotNull ? pIdx->nKeyCol-1 : nCol-1;
    }

    /* Populate the register containing the index name. */
    sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
    sqlite3VdbeLoadString(v, regIdxname, zIdxName);
    VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));

    /*
    ** Pseudo-code for loop that calls stat_push():
    **
    **   Rewind csr
    **   if eof(csr) goto end_of_scan;
90303
90304
90305
90306
90307
90308
90309
90310

90311
90312
90313
90314
90315
90316
90317
90420
90421
90422
90423
90424
90425
90426

90427
90428
90429
90430
90431
90432
90433
90434







-
+







        sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
        aGotoChng[i] = 
        sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
        sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
        VdbeCoverage(v);
      }
      sqlite3VdbeAddOp2(v, OP_Integer, nColTest, regChng);
      sqlite3VdbeAddOp2(v, OP_Goto, 0, endDistinctTest);
      sqlite3VdbeGoto(v, endDistinctTest);
  
  
      /*
      **  chng_addr_0:
      **   regPrev(0) = idx(0)
      **  chng_addr_1:
      **   regPrev(1) = idx(1)
90339
90340
90341
90342
90343
90344
90345

90346
90347
90348
90349
90350
90351
90352
90456
90457
90458
90459
90460
90461
90462
90463
90464
90465
90466
90467
90468
90469
90470







+







      sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid);
    }else{
      Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
      int j, k, regKey;
      regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
      for(j=0; j<pPk->nKeyCol; j++){
        k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
        assert( k>=0 && k<pTab->nCol );
        sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
        VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName));
      }
      sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
      sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
    }
#endif
90388
90389
90390
90391
90392
90393
90394
90395

90396
90397
90398
90399
90400

90401
90402
90403
90404
90405
90406
90407
90506
90507
90508
90509
90510
90511
90512

90513

90514
90515


90516
90517
90518
90519
90520
90521
90522
90523







-
+
-


-
-
+







      callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
      sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
      /* We know that the regSampleRowid row exists because it was read by
      ** the previous loop.  Thus the not-found jump of seekOp will never
      ** be taken */
      VdbeCoverageNeverTaken(v);
#ifdef SQLITE_ENABLE_STAT3
      sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, 
      sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, 0, regSample);
                                      pIdx->aiColumn[0], regSample);
#else
      for(i=0; i<nCol; i++){
        i16 iCol = pIdx->aiColumn[i];
        sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
        sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, i, regCol+i);
      }
      sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol, regSample);
#endif
      sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
      sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
      sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
      sqlite3VdbeAddOp2(v, OP_Goto, 1, addrNext); /* P1==1 for end-of-loop */
92119
92120
92121
92122
92123
92124
92125
92126

92127
92128
92129
92130
92131
92132
92133
92235
92236
92237
92238
92239
92240
92241

92242
92243
92244
92245
92246
92247
92248
92249







-
+







        pParse->okConstFactor = 0;
        for(i=0; i<pEL->nExpr; i++){
          sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
        }
      }

      /* Finally, jump back to the beginning of the executable code. */
      sqlite3VdbeAddOp2(v, OP_Goto, 0, 1);
      sqlite3VdbeGoto(v, 1);
    }
  }


  /* Get the VDBE program ready for execution
  */
  if( v && pParse->nErr==0 && !db->mallocFailed ){
92254
92255
92256
92257
92258
92259
92260











92261
92262
92263
92264
92265
92266
92267
92370
92371
92372
92373
92374
92375
92376
92377
92378
92379
92380
92381
92382
92383
92384
92385
92386
92387
92388
92389
92390
92391
92392
92393
92394







+
+
+
+
+
+
+
+
+
+
+







  if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
    return 0;
  }

  p = sqlite3FindTable(pParse->db, zName, zDbase);
  if( p==0 ){
    const char *zMsg = isView ? "no such view" : "no such table";
#ifndef SQLITE_OMIT_VIRTUALTABLE
    if( sqlite3FindDbName(pParse->db, zDbase)<1 ){
      /* If zName is the not the name of a table in the schema created using
      ** CREATE, then check to see if it is the name of an virtual table that
      ** can be an eponymous virtual table. */
      Module *pMod = (Module*)sqlite3HashFind(&pParse->db->aModule, zName);
      if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
        return pMod->pEpoTab;
      }
    }
#endif
    if( zDbase ){
      sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
    }else{
      sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
    }
    pParse->checkSchema = 1;
  }
92332
92333
92334
92335
92336
92337
92338

92339
92340
92341
92342
92343
92344
92345
92459
92460
92461
92462
92463
92464
92465
92466
92467
92468
92469
92470
92471
92472
92473







+







** Reclaim the memory used by an index
*/
static void freeIndex(sqlite3 *db, Index *p){
#ifndef SQLITE_OMIT_ANALYZE
  sqlite3DeleteIndexSamples(db, p);
#endif
  sqlite3ExprDelete(db, p->pPartIdxWhere);
  sqlite3ExprListDelete(db, p->aColExpr);
  sqlite3DbFree(db, p->zColAff);
  if( p->isResized ) sqlite3DbFree(db, p->azColl);
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  sqlite3_free(p->aiRowEst);
#endif
  sqlite3DbFree(db, p);
}
92458
92459
92460
92461
92462
92463
92464
92465

92466
92467
92468
92469
92470
92471
92472
92586
92587
92588
92589
92590
92591
92592

92593
92594
92595
92596
92597
92598
92599
92600







-
+







  db->flags &= ~SQLITE_InternChanges;
}

/*
** Delete memory allocated for the column names of a table or view (the
** Table.aCol[] array).
*/
static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
  int i;
  Column *pCol;
  assert( pTable!=0 );
  if( (pCol = pTable->aCol)!=0 ){
    for(i=0; i<pTable->nCol; i++, pCol++){
      sqlite3DbFree(db, pCol->zName);
      sqlite3ExprDelete(db, pCol->pDflt);
92525
92526
92527
92528
92529
92530
92531
92532

92533
92534
92535
92536
92537
92538
92539
92540
92541
92542
92543
92544
92545
92653
92654
92655
92656
92657
92658
92659

92660
92661
92662
92663

92664

92665
92666
92667
92668
92669
92670
92671







-
+



-

-







  }

  /* Delete any foreign keys attached to this table. */
  sqlite3FkDelete(db, pTable);

  /* Delete the Table structure itself.
  */
  sqliteDeleteColumnNames(db, pTable);
  sqlite3DeleteColumnNames(db, pTable);
  sqlite3DbFree(db, pTable->zName);
  sqlite3DbFree(db, pTable->zColAff);
  sqlite3SelectDelete(db, pTable->pSelect);
#ifndef SQLITE_OMIT_CHECK
  sqlite3ExprListDelete(db, pTable->pCheck);
#endif
#ifndef SQLITE_OMIT_VIRTUALTABLE
  sqlite3VtabClear(db, pTable);
#endif
  sqlite3DbFree(db, pTable);

  /* Verify that no lookaside memory was used by schema tables */
  assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
92874
92875
92876
92877
92878
92879
92880


92881
92882
92883
92884
92885
92886
92887
93000
93001
93002
93003
93004
93005
93006
93007
93008
93009
93010
93011
93012
93013
93014
93015







+
+







  ** indices.  Hence, the record number for the table must be allocated
  ** now.
  */
  if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
    int j1;
    int fileFormat;
    int reg1, reg2, reg3;
    /* nullRow[] is an OP_Record encoding of a row containing 5 NULLs */
    static const char nullRow[] = { 6, 0, 0, 0, 0, 0 };
    sqlite3BeginWriteOperation(pParse, 1, iDb);

#ifndef SQLITE_OMIT_VIRTUALTABLE
    if( isVirtual ){
      sqlite3VdbeAddOp0(v, OP_VBegin);
    }
#endif
92918
92919
92920
92921
92922
92923
92924
92925

92926
92927
92928
92929
92930
92931
92932
93046
93047
93048
93049
93050
93051
93052

93053
93054
93055
93056
93057
93058
93059
93060







-
+







    }else
#endif
    {
      pParse->addrCrTab = sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2);
    }
    sqlite3OpenMasterTable(pParse, iDb);
    sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
    sqlite3VdbeAddOp2(v, OP_Null, 0, reg3);
    sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
    sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
    sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
    sqlite3VdbeAddOp0(v, OP_Close);
  }

  /* Normal (non-error) return. */
  return;
93199
93200
93201
93202
93203
93204
93205




93206
93207
93208
93209
93210






93211
93212
93213
93214
93215
93216
93217

93218
93219
93220
93221
93222
93223
93224
93327
93328
93329
93330
93331
93332
93333
93334
93335
93336
93337





93338
93339
93340
93341
93342
93343
93344
93345
93346
93347
93348
93349

93350
93351
93352
93353
93354
93355
93356
93357







+
+
+
+
-
-
-
-
-
+
+
+
+
+
+






-
+







    iCol = pTab->nCol - 1;
    pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
    zType = pTab->aCol[iCol].zType;
    nTerm = 1;
  }else{
    nTerm = pList->nExpr;
    for(i=0; i<nTerm; i++){
      Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
      assert( pCExpr!=0 );
      if( pCExpr->op==TK_ID ){
        const char *zCName = pCExpr->u.zToken;
      for(iCol=0; iCol<pTab->nCol; iCol++){
        if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
          pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
          zType = pTab->aCol[iCol].zType;
          break;
        for(iCol=0; iCol<pTab->nCol; iCol++){
          if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
            pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
            zType = pTab->aCol[iCol].zType;
            break;
          }
        }
      }
    }
  }
  if( nTerm==1
   && zType && sqlite3StrICmp(zType, "INTEGER")==0
   && sortOrder==SQLITE_SO_ASC
   && sortOrder!=SQLITE_SO_DESC
  ){
    pTab->iPKey = iCol;
    pTab->keyConf = (u8)onError;
    assert( autoInc==0 || autoInc==1 );
    pTab->tabFlags |= autoInc*TF_Autoincrement;
    if( pList ) pParse->iPkSortOrder = pList->a[0].sortOrder;
  }else if( autoInc ){
93577
93578
93579
93580
93581
93582
93583
93584

93585
93586
93587
93588
93589
93590
93591



93592


93593
93594
93595
93596
93597
93598
93599
93600
93601
93602
93603
93604
93605
93606
93607
93608
93609
93610
93611

93612
93613
93614
93615
93616
93617
93618
93710
93711
93712
93713
93714
93715
93716

93717
93718
93719
93720
93721
93722
93723
93724
93725
93726
93727

93728
93729
93730


93731
93732
93733
93734
93735
93736
93737
93738
93739
93740
93741
93742
93743
93744
93745

93746
93747
93748
93749
93750
93751
93752
93753







-
+







+
+
+
-
+
+

-
-















-
+








  /* Convert the OP_CreateTable opcode that would normally create the
  ** root-page for the table into an OP_CreateIndex opcode.  The index
  ** created will become the PRIMARY KEY index.
  */
  if( pParse->addrCrTab ){
    assert( v );
    sqlite3VdbeGetOp(v, pParse->addrCrTab)->opcode = OP_CreateIndex;
    sqlite3VdbeChangeOpcode(v, pParse->addrCrTab, OP_CreateIndex);
  }

  /* Locate the PRIMARY KEY index.  Or, if this table was originally
  ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index. 
  */
  if( pTab->iPKey>=0 ){
    ExprList *pList;
    Token ipkToken;
    ipkToken.z = pTab->aCol[pTab->iPKey].zName;
    ipkToken.n = sqlite3Strlen30(ipkToken.z);
    pList = sqlite3ExprListAppend(pParse, 0, 0);
    pList = sqlite3ExprListAppend(pParse, 0, 
                  sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
    if( pList==0 ) return;
    pList->a[0].zName = sqlite3DbStrDup(pParse->db,
                                        pTab->aCol[pTab->iPKey].zName);
    pList->a[0].sortOrder = pParse->iPkSortOrder;
    assert( pParse->pNewTable==pTab );
    pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
    if( pPk==0 ) return;
    pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
    pTab->iPKey = -1;
  }else{
    pPk = sqlite3PrimaryKeyIndex(pTab);

    /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
    ** table entry. This is only required if currently generating VDBE
    ** code for a CREATE TABLE (not when parsing one as part of reading
    ** a database schema).  */
    if( v ){
      assert( db->init.busy==0 );
      sqlite3VdbeGetOp(v, pPk->tnum)->opcode = OP_Goto;
      sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
    }

    /*
    ** Remove all redundant columns from the PRIMARY KEY.  For example, change
    ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)".  Later
    ** code assumes the PRIMARY KEY contains no repeated columns.
    */
93714
93715
93716
93717
93718
93719
93720
93721

93722
93723

93724
93725
93726
93727
93728
93729
93730
93849
93850
93851
93852
93853
93854
93855

93856
93857
93858
93859
93860
93861
93862
93863
93864
93865
93866







-
+


+







  Select *pSelect         /* Select from a "CREATE ... AS SELECT" */
){
  Table *p;                 /* The new table */
  sqlite3 *db = pParse->db; /* The database connection */
  int iDb;                  /* Database in which the table lives */
  Index *pIdx;              /* An implied index of the table */

  if( (pEnd==0 && pSelect==0) || db->mallocFailed ){
  if( pEnd==0 && pSelect==0 ){
    return;
  }
  assert( !db->mallocFailed );
  p = pParse->pNewTable;
  if( p==0 ) return;

  assert( !db->init.busy || !pSelect );

  /* If the db->init.busy is 1 it means we are reading the SQL off the
  ** "sqlite_master" or "sqlite_temp_master" table on the disk.
93847
93848
93849
93850
93851
93852
93853
93854

93855
93856
93857
93858
93859
93860
93861
93983
93984
93985
93986
93987
93988
93989

93990
93991
93992
93993
93994
93995
93996
93997







-
+







      sqlite3DeleteTable(db, pSelTab);
      addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
      VdbeCoverage(v);
      sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
      sqlite3TableAffinity(v, p, 0);
      sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
      sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid);
      sqlite3VdbeAddOp2(v, OP_Goto, 0, addrInsLoop);
      sqlite3VdbeGoto(v, addrInsLoop);
      sqlite3VdbeJumpHere(v, addrInsLoop);
      sqlite3VdbeAddOp1(v, OP_Close, 1);
    }

    /* Compute the complete text of the CREATE statement */
    if( pSelect ){
      zStmt = createTableStmt(db, p);
93944
93945
93946
93947
93948
93949
93950

93951
93952
93953
93954
93955
93956
93957
93958
93959
93960
93961
93962
93963
93964
93965
93966
93967
93968
93969
93970
93971

93972
93973
93974
93975
93976
93977
93978

93979
93980
93981
93982
93983
93984
93985
93986
93987
93988
93989
93990


93991
93992
93993
93994
93995
93996
93997
93998
93999
94000

94001

94002
94003
94004
94005

94006
94007

94008
94009
94010
94011
94012




94013
94014
94015
94016
94017
94018
94019
94020
94021
94022
94023
94024
94025
94026
94027
94028
94029

94030
94031
94032
94033
94034
94035
94036
94080
94081
94082
94083
94084
94085
94086
94087
94088
94089
94090
94091
94092
94093
94094
94095
94096
94097
94098
94099
94100
94101
94102
94103
94104
94105
94106
94107

94108



94109
94110
94111

94112



94113
94114
94115
94116
94117
94118
94119


94120
94121





94122
94123
94124
94125
94126
94127

94128
94129
94130
94131
94132
94133
94134

94135
94136
94137
94138
94139
94140
94141
94142
94143
94144
94145
94146
94147
94148
94149
94150
94151
94152
94153
94154
94155
94156
94157
94158
94159
94160
94161
94162
94163
94164
94165
94166
94167
94168
94169







+




















-
+
-
-
-



-
+
-
-
-







-
-
+
+
-
-
-
-
-





+
-
+




+

-
+





+
+
+
+

















+







** The parser calls this routine in order to create a new VIEW
*/
SQLITE_PRIVATE void sqlite3CreateView(
  Parse *pParse,     /* The parsing context */
  Token *pBegin,     /* The CREATE token that begins the statement */
  Token *pName1,     /* The token that holds the name of the view */
  Token *pName2,     /* The token that holds the name of the view */
  ExprList *pCNames, /* Optional list of view column names */
  Select *pSelect,   /* A SELECT statement that will become the new view */
  int isTemp,        /* TRUE for a TEMPORARY view */
  int noErr          /* Suppress error messages if VIEW already exists */
){
  Table *p;
  int n;
  const char *z;
  Token sEnd;
  DbFixer sFix;
  Token *pName = 0;
  int iDb;
  sqlite3 *db = pParse->db;

  if( pParse->nVar>0 ){
    sqlite3ErrorMsg(pParse, "parameters are not allowed in views");
    sqlite3SelectDelete(db, pSelect);
    return;
  }
  sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
  p = pParse->pNewTable;
  if( p==0 || pParse->nErr ){
  if( p==0 || pParse->nErr ) goto create_view_fail;
    sqlite3SelectDelete(db, pSelect);
    return;
  }
  sqlite3TwoPartName(pParse, pName1, pName2, &pName);
  iDb = sqlite3SchemaToIndex(db, p->pSchema);
  sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
  if( sqlite3FixSelect(&sFix, pSelect) ){
  if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail;
    sqlite3SelectDelete(db, pSelect);
    return;
  }

  /* Make a copy of the entire SELECT statement that defines the view.
  ** This will force all the Expr.token.z values to be dynamically
  ** allocated rather than point to the input string - which means that
  ** they will persist after the current sqlite3_exec() call returns.
  */
  p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
  sqlite3SelectDelete(db, pSelect);
  if( db->mallocFailed ){
  p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE);
  if( db->mallocFailed ) goto create_view_fail;
    return;
  }
  if( !db->init.busy ){
    sqlite3ViewGetColumnNames(pParse, p);
  }

  /* Locate the end of the CREATE VIEW statement.  Make sEnd point to
  ** the end.
  */
  sEnd = pParse->sLastToken;
  assert( sEnd.z[0]!=0 );
  if( ALWAYS(sEnd.z[0]!=0) && sEnd.z[0]!=';' ){
  if( sEnd.z[0]!=';' ){
    sEnd.z += sEnd.n;
  }
  sEnd.n = 0;
  n = (int)(sEnd.z - pBegin->z);
  assert( n>0 );
  z = pBegin->z;
  while( ALWAYS(n>0) && sqlite3Isspace(z[n-1]) ){ n--; }
  while( sqlite3Isspace(z[n-1]) ){ n--; }
  sEnd.z = &z[n-1];
  sEnd.n = 1;

  /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
  sqlite3EndTable(pParse, 0, &sEnd, 0, 0);

create_view_fail:
  sqlite3SelectDelete(db, pSelect);
  sqlite3ExprListDelete(db, pCNames);
  return;
}
#endif /* SQLITE_OMIT_VIEW */

#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
/*
** The Table structure pTable is really a VIEW.  Fill in the names of
** the columns of the view in the pTable structure.  Return the number
** of errors.  If an error is seen leave an error message in pParse->zErrMsg.
*/
SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
  Table *pSelTab;   /* A fake table from which we get the result set */
  Select *pSel;     /* Copy of the SELECT that implements the view */
  int nErr = 0;     /* Number of errors encountered */
  int n;            /* Temporarily holds the number of cursors assigned */
  sqlite3 *db = pParse->db;  /* Database connection for malloc errors */
  sqlite3_xauth xAuth;       /* Saved xAuth pointer */
  u8 bEnabledLA;             /* Saved db->lookaside.bEnabled state */

  assert( pTable );

#ifndef SQLITE_OMIT_VIRTUALTABLE
  if( sqlite3VtabCallConnect(pParse, pTable) ){
    return SQLITE_ERROR;
  }
94068
94069
94070
94071
94072
94073
94074






94075
94076


94077
94078
94079
94080
94081




94082
94083
94084
94085
94086




94087
94088

94089
94090
94091
94092
94093
94094
94095
94096
94097
94098
94099









94100
94101
94102
94103
94104
94105
94106
94107
94108











94109
94110
94111
94112
94113
94114
94115
94116
94117
94118
94119
94120
94121
94122
94123
94124
94125

94126
94127
94128
94129
94130
94131
94132
94201
94202
94203
94204
94205
94206
94207
94208
94209
94210
94211
94212
94213


94214
94215





94216
94217
94218
94219
94220




94221
94222
94223
94224
94225

94226
94227










94228
94229
94230
94231
94232
94233
94234
94235
94236









94237
94238
94239
94240
94241
94242
94243
94244
94245
94246
94247
94248
94249
94250
94251
94252
94253
94254
94255
94256
94257
94258
94259
94260
94261
94262
94263

94264
94265
94266
94267
94268
94269
94270
94271







+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
















-
+







  ** Note that the call to sqlite3ResultSetOfSelect() will expand any
  ** "*" elements in the results set of the view and will assign cursors
  ** to the elements of the FROM clause.  But we do not want these changes
  ** to be permanent.  So the computation is done on a copy of the SELECT
  ** statement that defines the view.
  */
  assert( pTable->pSelect );
  bEnabledLA = db->lookaside.bEnabled;
  if( pTable->pCheck ){
    db->lookaside.bEnabled = 0;
    sqlite3ColumnsFromExprList(pParse, pTable->pCheck, 
                               &pTable->nCol, &pTable->aCol);
  }else{
  pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
  if( pSel ){
    pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
    if( pSel ){
    u8 enableLookaside = db->lookaside.bEnabled;
    n = pParse->nTab;
    sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
    pTable->nCol = -1;
    db->lookaside.bEnabled = 0;
      n = pParse->nTab;
      sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
      pTable->nCol = -1;
      db->lookaside.bEnabled = 0;
#ifndef SQLITE_OMIT_AUTHORIZATION
    xAuth = db->xAuth;
    db->xAuth = 0;
    pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
    db->xAuth = xAuth;
      xAuth = db->xAuth;
      db->xAuth = 0;
      pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
      db->xAuth = xAuth;
#else
    pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
      pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
#endif
    db->lookaside.bEnabled = enableLookaside;
    pParse->nTab = n;
    if( pSelTab ){
      assert( pTable->aCol==0 );
      pTable->nCol = pSelTab->nCol;
      pTable->aCol = pSelTab->aCol;
      pSelTab->nCol = 0;
      pSelTab->aCol = 0;
      sqlite3DeleteTable(db, pSelTab);
      assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
      pParse->nTab = n;
      if( pSelTab ){
        assert( pTable->aCol==0 );
        pTable->nCol = pSelTab->nCol;
        pTable->aCol = pSelTab->aCol;
        pSelTab->nCol = 0;
        pSelTab->aCol = 0;
        sqlite3DeleteTable(db, pSelTab);
        assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
      pTable->pSchema->schemaFlags |= DB_UnresetViews;
    }else{
      pTable->nCol = 0;
      nErr++;
    }
    sqlite3SelectDelete(db, pSel);
  } else {
    nErr++;
  }
      }else{
        pTable->nCol = 0;
        nErr++;
      }
      sqlite3SelectDelete(db, pSel);
    } else {
      nErr++;
    }
  }
  db->lookaside.bEnabled = bEnabledLA;
  pTable->pSchema->schemaFlags |= DB_UnresetViews;
#endif /* SQLITE_OMIT_VIEW */
  return nErr;  
}
#endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */

#ifndef SQLITE_OMIT_VIEW
/*
** Clear the column names from every VIEW in database idx.
*/
static void sqliteViewResetAll(sqlite3 *db, int idx){
  HashElem *i;
  assert( sqlite3SchemaMutexHeld(db, idx, 0) );
  if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
  for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
    Table *pTab = sqliteHashData(i);
    if( pTab->pSelect ){
      sqliteDeleteColumnNames(db, pTab);
      sqlite3DeleteColumnNames(db, pTab);
      pTab->aCol = 0;
      pTab->nCol = 0;
    }
  }
  DbClearProperty(db, idx, DB_UnresetViews);
}
#else
94673
94674
94675
94676
94677
94678
94679
94680

94681
94682
94683
94684
94685
94686
94687
94812
94813
94814
94815
94816
94817
94818

94819
94820
94821
94822
94823
94824
94825
94826







-
+







                    (char *)pKey, P4_KEYINFO);
  sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));

  addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
  assert( pKey!=0 || db->mallocFailed || pParse->nErr );
  if( IsUniqueIndex(pIndex) && pKey!=0 ){
    int j2 = sqlite3VdbeCurrentAddr(v) + 3;
    sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
    sqlite3VdbeGoto(v, j2);
    addr2 = sqlite3VdbeCurrentAddr(v);
    sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
                         pIndex->nKeyCol); VdbeCoverage(v);
    sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
  }else{
    addr2 = sqlite3VdbeCurrentAddr(v);
  }
94728
94729
94730
94731
94732
94733
94734
























94735
94736
94737
94738
94739
94740
94741
94867
94868
94869
94870
94871
94872
94873
94874
94875
94876
94877
94878
94879
94880
94881
94882
94883
94884
94885
94886
94887
94888
94889
94890
94891
94892
94893
94894
94895
94896
94897
94898
94899
94900
94901
94902
94903
94904







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    p->aSortOrder = (u8*)pExtra;
    p->nColumn = nCol;
    p->nKeyCol = nCol - 1;
    *ppExtra = ((char*)p) + nByte;
  }
  return p;
}

/*
** Backwards Compatibility Hack:
** 
** Historical versions of SQLite accepted strings as column names in
** indexes and PRIMARY KEY constraints and in UNIQUE constraints.  Example:
**
**     CREATE TABLE xyz(a,b,c,d,e,PRIMARY KEY('a'),UNIQUE('b','c' COLLATE trim)
**     CREATE INDEX abc ON xyz('c','d' DESC,'e' COLLATE nocase DESC);
**
** This is goofy.  But to preserve backwards compatibility we continue to
** accept it.  This routine does the necessary conversion.  It converts
** the expression given in its argument from a TK_STRING into a TK_ID
** if the expression is just a TK_STRING with an optional COLLATE clause.
** If the epxression is anything other than TK_STRING, the expression is
** unchanged.
*/
static void sqlite3StringToId(Expr *p){
  if( p->op==TK_STRING ){
    p->op = TK_ID;
  }else if( p->op==TK_COLLATE && p->pLeft->op==TK_STRING ){
    p->pLeft->op = TK_ID;
  }
}

/*
** Create a new index for an SQL table.  pName1.pName2 is the name of the index 
** and pTblList is the name of the table that is to be indexed.  Both will 
** be NULL for a primary key or an index that is created to satisfy a
** UNIQUE constraint.  If pTable and pIndex are NULL, use pParse->pNewTable
** as the table to be indexed.  pParse->pNewTable is a table that is
94770
94771
94772
94773
94774
94775
94776
94777
94778
94779
94780
94781
94782
94783
94784
94933
94934
94935
94936
94937
94938
94939

94940
94941
94942
94943
94944
94945
94946







-







  DbFixer sFix;        /* For assigning database names to pTable */
  int sortOrderMask;   /* 1 to honor DESC in index.  0 to ignore. */
  sqlite3 *db = pParse->db;
  Db *pDb;             /* The specific table containing the indexed database */
  int iDb;             /* Index of the database that is being written */
  Token *pName = 0;    /* Unqualified name of the index to create */
  struct ExprList_item *pListItem; /* For looping over pList */
  const Column *pTabCol;           /* A column in the table */
  int nExtra = 0;                  /* Space allocated for zExtra[] */
  int nExtraCol;                   /* Number of extra columns needed */
  char *zExtra = 0;                /* Extra space after the Index object */
  Index *pPk = 0;      /* PRIMARY KEY index for WITHOUT ROWID tables */

  if( db->mallocFailed || IN_DECLARE_VTAB || pParse->nErr>0 ){
    goto exit_create_index;
94925
94926
94927
94928
94929
94930
94931



94932


94933
94934

94935
94936



94937
94938
94939
94940
94941
94942
94943
94944
94945


94946
94947
94948
94949
94950
94951
94952
95087
95088
95089
95090
95091
95092
95093
95094
95095
95096

95097
95098
95099

95100


95101
95102
95103
95104
95105
95106
95107
95108
95109
95110


95111
95112
95113
95114
95115
95116
95117
95118
95119







+
+
+
-
+
+

-
+
-
-
+
+
+







-
-
+
+







#endif

  /* If pList==0, it means this routine was called to make a primary
  ** key out of the last column added to the table under construction.
  ** So create a fake list to simulate this.
  */
  if( pList==0 ){
    Token prevCol;
    prevCol.z = pTab->aCol[pTab->nCol-1].zName;
    prevCol.n = sqlite3Strlen30(prevCol.z);
    pList = sqlite3ExprListAppend(pParse, 0, 0);
    pList = sqlite3ExprListAppend(pParse, 0,
              sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
    if( pList==0 ) goto exit_create_index;
    pList->a[0].zName = sqlite3DbStrDup(pParse->db,
    assert( pList->nExpr==1 );
                                        pTab->aCol[pTab->nCol-1].zName);
    pList->a[0].sortOrder = (u8)sortOrder;
    sqlite3ExprListSetSortOrder(pList, sortOrder);
  }else{
    sqlite3ExprListCheckLength(pParse, pList, "index");
  }

  /* Figure out how many bytes of space are required to store explicitly
  ** specified collation sequence names.
  */
  for(i=0; i<pList->nExpr; i++){
    Expr *pExpr = pList->a[i].pExpr;
    if( pExpr ){
      assert( pExpr->op==TK_COLLATE );
    assert( pExpr!=0 );
    if( pExpr->op==TK_COLLATE ){
      nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
    }
  }

  /* 
  ** Allocate the index structure. 
  */
94979
94980
94981
94982
94983
94984
94985
94986
94987
94988




94989
94990

94991
94992
94993
94994


94995
94996
94997
94998


94999
95000





95001
95002
95003
95004
95005
95006
95007











95008
95009
95010
95011
95012

















95013
95014
95015
95016
95017
95018
95019
95020
95021
95022

95023
95024
95025

95026
95027
95028
95029
95030
95031
95032
95033





95034
95035
95036

95037
95038
95039
95040
95041
95042
95043
95146
95147
95148
95149
95150
95151
95152



95153
95154
95155
95156
95157

95158




95159
95160
95161
95162


95163
95164
95165
95166
95167
95168
95169
95170
95171







95172
95173
95174
95175
95176
95177
95178
95179
95180
95181
95182





95183
95184
95185
95186
95187
95188
95189
95190
95191
95192
95193
95194
95195
95196
95197
95198
95199
95200

95201
95202
95203
95204
95205
95206
95207

95208
95209

95210
95211
95212
95213
95214
95215
95216
95217

95218
95219
95220
95221
95222
95223
95224
95225
95226
95227
95228
95229
95230
95231
95232
95233
95234







-
-
-
+
+
+
+

-
+
-
-
-
-
+
+


-
-
+
+


+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-







-
+

-

+






-

+
+
+
+
+



+







  */
  if( pDb->pSchema->file_format>=4 ){
    sortOrderMask = -1;   /* Honor DESC */
  }else{
    sortOrderMask = 0;    /* Ignore DESC */
  }

  /* Scan the names of the columns of the table to be indexed and
  ** load the column indices into the Index structure.  Report an error
  ** if any column is not found.
  /* Analyze the list of expressions that form the terms of the index and
  ** report any errors.  In the common case where the expression is exactly
  ** a table column, store that column in aiColumn[].  For general expressions,
  ** populate pIndex->aColExpr and store -2 in aiColumn[].
  **
  ** TODO:  Add a test to make sure that the same column is not named
  ** TODO: Issue a warning if two or more columns of the index are identical.
  ** more than once within the same index.  Only the first instance of
  ** the column will ever be used by the optimizer.  Note that using the
  ** same column more than once cannot be an error because that would 
  ** break backwards compatibility - it needs to be a warning.
  ** TODO: Issue a warning if the table primary key is used as part of the
  ** index key.
  */
  for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){
    const char *zColName = pListItem->zName;
    int requestedSortOrder;
    Expr *pCExpr;                  /* The i-th index expression */
    int requestedSortOrder;        /* ASC or DESC on the i-th expression */
    char *zColl;                   /* Collation sequence name */

    sqlite3StringToId(pListItem->pExpr);
    sqlite3ResolveSelfReference(pParse, pTab, NC_IdxExpr, pListItem->pExpr, 0);
    if( pParse->nErr ) goto exit_create_index;
    pCExpr = sqlite3ExprSkipCollate(pListItem->pExpr);
    if( pCExpr->op!=TK_COLUMN ){
    for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){
      if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break;
    }
    if( j>=pTab->nCol ){
      sqlite3ErrorMsg(pParse, "table %s has no column named %s",
        pTab->zName, zColName);
      pParse->checkSchema = 1;
      if( pTab==pParse->pNewTable ){
        sqlite3ErrorMsg(pParse, "expressions prohibited in PRIMARY KEY and "
                                "UNIQUE constraints");
        goto exit_create_index;
      }
      if( pIndex->aColExpr==0 ){
        ExprList *pCopy = sqlite3ExprListDup(db, pList, 0);
        pIndex->aColExpr = pCopy;
        if( !db->mallocFailed ){
          assert( pCopy!=0 );
          pListItem = &pCopy->a[i];
      goto exit_create_index;
    }
    assert( j<=0x7fff );
    pIndex->aiColumn[i] = (i16)j;
    if( pListItem->pExpr ){
        }
      }
      j = -2;
      pIndex->aiColumn[i] = -2;
      pIndex->uniqNotNull = 0;
    }else{
      j = pCExpr->iColumn;
      assert( j<=0x7fff );
      if( j<0 ){
        j = pTab->iPKey;
      }else if( pTab->aCol[j].notNull==0 ){
        pIndex->uniqNotNull = 0;
      }
      pIndex->aiColumn[i] = (i16)j;
    }
    zColl = 0;
    if( pListItem->pExpr->op==TK_COLLATE ){
      int nColl;
      assert( pListItem->pExpr->op==TK_COLLATE );
      zColl = pListItem->pExpr->u.zToken;
      nColl = sqlite3Strlen30(zColl) + 1;
      assert( nExtra>=nColl );
      memcpy(zExtra, zColl, nColl);
      zColl = zExtra;
      zExtra += nColl;
      nExtra -= nColl;
    }else{
    }else if( j>=0 ){
      zColl = pTab->aCol[j].zColl;
      if( !zColl ) zColl = "BINARY";
    }
    if( !zColl ) zColl = "BINARY";
    if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
      goto exit_create_index;
    }
    pIndex->azColl[i] = zColl;
    requestedSortOrder = pListItem->sortOrder & sortOrderMask;
    pIndex->aSortOrder[i] = (u8)requestedSortOrder;
    if( pTab->aCol[j].notNull==0 ) pIndex->uniqNotNull = 0;
  }

  /* Append the table key to the end of the index.  For WITHOUT ROWID
  ** tables (when pPk!=0) this will be the declared PRIMARY KEY.  For
  ** normal tables (when pPk==0) this will be the rowid.
  */
  if( pPk ){
    for(j=0; j<pPk->nKeyCol; j++){
      int x = pPk->aiColumn[j];
      assert( x>=0 );
      if( hasColumn(pIndex->aiColumn, pIndex->nKeyCol, x) ){
        pIndex->nColumn--; 
      }else{
        pIndex->aiColumn[i] = x;
        pIndex->azColl[i] = pPk->azColl[j];
        pIndex->aSortOrder[i] = pPk->aSortOrder[j];
        i++;
95080
95081
95082
95083
95084
95085
95086

95087
95088
95089
95090
95091
95092
95093
95271
95272
95273
95274
95275
95276
95277
95278
95279
95280
95281
95282
95283
95284
95285







+







      assert( pIdx->idxType!=SQLITE_IDXTYPE_APPDEF );
      assert( IsUniqueIndex(pIndex) );

      if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
      for(k=0; k<pIdx->nKeyCol; k++){
        const char *z1;
        const char *z2;
        assert( pIdx->aiColumn[k]>=0 );
        if( pIdx->aiColumn[k]!=pIndex->aiColumn[k] ) break;
        z1 = pIdx->azColl[k];
        z2 = pIndex->azColl[k];
        if( z1!=z2 && sqlite3StrICmp(z1, z2) ) break;
      }
      if( k==pIdx->nKeyCol ){
        if( pIdx->onError!=pIndex->onError ){
95111
95112
95113
95114
95115
95116
95117

95118
95119
95120
95121
95122
95123
95124
95303
95304
95305
95306
95307
95308
95309
95310
95311
95312
95313
95314
95315
95316
95317







+







      }
    }
  }

  /* Link the new Index structure to its table and to the other
  ** in-memory database structures. 
  */
  assert( pParse->nErr==0 );
  if( db->init.busy ){
    Index *p;
    assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
    p = sqlite3HashInsert(&pIndex->pSchema->idxHash, 
                          pIndex->zName, pIndex);
    if( p ){
      assert( p==pIndex );  /* Malloc must have failed */
95140
95141
95142
95143
95144
95145
95146
95147

95148
95149
95150
95151
95152
95153
95154
95333
95334
95335
95336
95337
95338
95339

95340
95341
95342
95343
95344
95345
95346
95347







-
+







  ** of a WITHOUT ROWID table.
  **
  ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
  ** or UNIQUE index in a CREATE TABLE statement.  Since the table
  ** has just been created, it contains no data and the index initialization
  ** step can be skipped.
  */
  else if( pParse->nErr==0 && (HasRowid(pTab) || pTblName!=0) ){
  else if( HasRowid(pTab) || pTblName!=0 ){
    Vdbe *v;
    char *zStmt;
    int iMem = ++pParse->nMem;

    v = sqlite3GetVdbe(pParse);
    if( v==0 ) goto exit_create_index;

95600
95601
95602
95603
95604
95605
95606
95607


95608
95609
95610
95611
95612
95613
95614
95793
95794
95795
95796
95797
95798
95799

95800
95801
95802
95803
95804
95805
95806
95807
95808







-
+
+







  int i;
  struct SrcList_item *pItem;
  if( pList==0 ) return;
  for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
    sqlite3DbFree(db, pItem->zDatabase);
    sqlite3DbFree(db, pItem->zName);
    sqlite3DbFree(db, pItem->zAlias);
    sqlite3DbFree(db, pItem->zIndexedBy);
    if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
    if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
    sqlite3DeleteTable(db, pItem->pTab);
    sqlite3SelectDelete(db, pItem->pSelect);
    sqlite3ExprDelete(db, pItem->pOn);
    sqlite3IdListDelete(db, pItem->pUsing);
  }
  sqlite3DbFree(db, pList);
}
95673
95674
95675
95676
95677
95678
95679
95680



95681
95682
95683
95684

95685
95686


95687
95688
95689

















95690
95691
95692
95693
95694
95695
95696
95697
95698
95699
95700
95701
95702
95703
95704
95705
95706
95707
95708
95709
95710

95711
95712

95713
95714
95715
95716
95717
95718
95719
95867
95868
95869
95870
95871
95872
95873

95874
95875
95876
95877
95878
95879

95880
95881

95882
95883
95884
95885
95886
95887
95888
95889
95890
95891
95892
95893
95894
95895
95896
95897
95898
95899
95900
95901
95902
95903
95904
95905
95906
95907
95908
95909
95910
95911
95912
95913
95914
95915
95916
95917
95918
95919
95920
95921
95922
95923

95924
95925

95926
95927
95928
95929
95930
95931
95932
95933







-
+
+
+



-
+

-
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




















-
+

-
+







** Add an INDEXED BY or NOT INDEXED clause to the most recently added 
** element of the source-list passed as the second argument.
*/
SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
  assert( pIndexedBy!=0 );
  if( p && ALWAYS(p->nSrc>0) ){
    struct SrcList_item *pItem = &p->a[p->nSrc-1];
    assert( pItem->notIndexed==0 && pItem->zIndexedBy==0 );
    assert( pItem->fg.notIndexed==0 );
    assert( pItem->fg.isIndexedBy==0 );
    assert( pItem->fg.isTabFunc==0 );
    if( pIndexedBy->n==1 && !pIndexedBy->z ){
      /* A "NOT INDEXED" clause was supplied. See parse.y 
      ** construct "indexed_opt" for details. */
      pItem->notIndexed = 1;
      pItem->fg.notIndexed = 1;
    }else{
      pItem->zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
      pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
      pItem->fg.isIndexedBy = (pItem->u1.zIndexedBy!=0);
    }
  }
}

/*
** Add the list of function arguments to the SrcList entry for a
** table-valued-function.
*/
SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse *pParse, SrcList *p, ExprList *pList){
  if( p && pList ){
    struct SrcList_item *pItem = &p->a[p->nSrc-1];
    assert( pItem->fg.notIndexed==0 );
    assert( pItem->fg.isIndexedBy==0 );
    assert( pItem->fg.isTabFunc==0 );
    pItem->u1.pFuncArg = pList;
    pItem->fg.isTabFunc = 1;
  }else{
    sqlite3ExprListDelete(pParse->db, pList);
  }
}

/*
** When building up a FROM clause in the parser, the join operator
** is initially attached to the left operand.  But the code generator
** expects the join operator to be on the right operand.  This routine
** Shifts all join operators from left to right for an entire FROM
** clause.
**
** Example: Suppose the join is like this:
**
**           A natural cross join B
**
** The operator is "natural cross join".  The A and B operands are stored
** in p->a[0] and p->a[1], respectively.  The parser initially stores the
** operator with A.  This routine shifts that operator over to B.
*/
SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
  if( p ){
    int i;
    for(i=p->nSrc-1; i>0; i--){
      p->a[i].jointype = p->a[i-1].jointype;
      p->a[i].fg.jointype = p->a[i-1].fg.jointype;
    }
    p->a[0].jointype = 0;
    p->a[0].fg.jointype = 0;
  }
}

/*
** Begin a transaction
*/
SQLITE_PRIVATE void sqlite3BeginTransaction(Parse *pParse, int type){
95949
95950
95951
95952
95953
95954
95955



95956
95957
95958
95959






95960
95961

95962
95963
95964
95965
95966
95967
95968
96163
96164
96165
96166
96167
96168
96169
96170
96171
96172




96173
96174
96175
96176
96177
96178


96179
96180
96181
96182
96183
96184
96185
96186







+
+
+
-
-
-
-
+
+
+
+
+
+
-
-
+







){
  char *zErr;
  int j;
  StrAccum errMsg;
  Table *pTab = pIdx->pTable;

  sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
  if( pIdx->aColExpr ){
    sqlite3XPrintf(&errMsg, 0, "index '%q'", pIdx->zName);
  }else{
  for(j=0; j<pIdx->nKeyCol; j++){
    char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
    if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
    sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
    for(j=0; j<pIdx->nKeyCol; j++){
      char *zCol;
      assert( pIdx->aiColumn[j]>=0 );
      zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
      if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
      sqlite3XPrintf(&errMsg, 0, "%s.%s", pTab->zName, zCol);
    sqlite3StrAccumAppend(&errMsg, ".", 1);
    sqlite3StrAccumAppendAll(&errMsg, zCol);
    }
  }
  zErr = sqlite3StrAccumFinish(&errMsg);
  sqlite3HaltConstraint(pParse, 
    IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY 
                            : SQLITE_CONSTRAINT_UNIQUE,
    onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
}
96199
96200
96201
96202
96203
96204
96205
96206

96207
96208
96209
96210
96211
96212
96213
96417
96418
96419
96420
96421
96422
96423

96424
96425
96426
96427
96428
96429
96430
96431







-
+







    sqlite3SelectDelete(db, pQuery);
    sqlite3DbFree(db, zName);
    pNew = pWith;
  }else{
    pNew->a[pNew->nCte].pSelect = pQuery;
    pNew->a[pNew->nCte].pCols = pArglist;
    pNew->a[pNew->nCte].zName = zName;
    pNew->a[pNew->nCte].zErr = 0;
    pNew->a[pNew->nCte].zCteErr = 0;
    pNew->nCte++;
  }

  return pNew;
}

/*
97118
97119
97120
97121
97122
97123
97124

97125
97126
97127
97128
97129
97130
97131
97336
97337
97338
97339
97340
97341
97342
97343
97344
97345
97346
97347
97348
97349
97350







+







    if( db->flags & SQLITE_CountRows ){
      sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
    }
  
    /* Extract the rowid or primary key for the current row */
    if( pPk ){
      for(i=0; i<nPk; i++){
        assert( pPk->aiColumn[i]>=(-1) );
        sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
                                        pPk->aiColumn[i], iPk+i);
      }
      iKey = iPk;
    }else{
      iKey = pParse->nMem + 1;
      iKey = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iTabCur, iKey, 0);
97150
97151
97152
97153
97154
97155
97156
97157

97158
97159
97160
97161
97162
97163
97164
97165
97166
97167
97168
97169
97170

97171
97172
97173
97174
97175
97176
97177
97369
97370
97371
97372
97373
97374
97375

97376
97377
97378
97379
97380
97381
97382
97383
97384
97385
97386
97387
97388

97389
97390
97391
97392
97393
97394
97395
97396







-
+












-
+







      if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen);
      addrDelete = sqlite3VdbeAddOp0(v, OP_Goto); /* Jump to DELETE logic */
    }else if( pPk ){
      /* Construct a composite key for the row to be deleted and remember it */
      iKey = ++pParse->nMem;
      nKey = 0;   /* Zero tells OP_Found to use a composite key */
      sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
                        sqlite3IndexAffinityStr(v, pPk), nPk);
                        sqlite3IndexAffinityStr(pParse->db, pPk), nPk);
      sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
    }else{
      /* Get the rowid of the row to be deleted and remember it in the RowSet */
      nKey = 1;  /* OP_Seek always uses a single rowid */
      sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
    }
  
    /* End of the WHERE loop */
    sqlite3WhereEnd(pWInfo);
    if( okOnePass ){
      /* Bypass the delete logic below if the WHERE loop found zero rows */
      addrBypass = sqlite3VdbeMakeLabel(v);
      sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBypass);
      sqlite3VdbeGoto(v, addrBypass);
      sqlite3VdbeJumpHere(v, addrDelete);
    }
  
    /* Unless this is a view, open cursors for the table we are 
    ** deleting from and all its indices. If this is a view, then the
    ** only effect this statement has is to fire the INSTEAD OF 
    ** triggers.
97225
97226
97227
97228
97229
97230
97231
97232

97233
97234
97235
97236
97237
97238
97239
97444
97445
97446
97447
97448
97449
97450

97451
97452
97453
97454
97455
97456
97457
97458







-
+







    /* End of the loop over all rowids/primary-keys. */
    if( okOnePass ){
      sqlite3VdbeResolveLabel(v, addrBypass);
    }else if( pPk ){
      sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
      sqlite3VdbeJumpHere(v, addrLoop);
    }else{
      sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
      sqlite3VdbeGoto(v, addrLoop);
      sqlite3VdbeJumpHere(v, addrLoop);
    }     
  
    /* Close the cursors open on the table and its indexes. */
    if( !isView && !IsVirtual(pTab) ){
      if( !pPk ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
      for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
97496
97497
97498
97499
97500
97501
97502
97503
97504
97505
97506
97507
97508
97509
97510

97511
97512
97513
97514
97515
97516
97517
97518
97519
97520
97521

97522
97523
97524







97525
97526
97527
97528
97529
97530
97531
97715
97716
97717
97718
97719
97720
97721

97722
97723
97724
97725
97726
97727

97728
97729
97730
97731
97732
97733
97734
97735
97736
97737
97738
97739
97740



97741
97742
97743
97744
97745
97746
97747
97748
97749
97750
97751
97752
97753
97754







-






-
+











+
-
-
-
+
+
+
+
+
+
+







  int prefixOnly,      /* Compute only a unique prefix of the key */
  int *piPartIdxLabel, /* OUT: Jump to this label to skip partial index */
  Index *pPrior,       /* Previously generated index key */
  int regPrior         /* Register holding previous generated key */
){
  Vdbe *v = pParse->pVdbe;
  int j;
  Table *pTab = pIdx->pTable;
  int regBase;
  int nCol;

  if( piPartIdxLabel ){
    if( pIdx->pPartIdxWhere ){
      *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
      pParse->iPartIdxTab = iDataCur;
      pParse->iSelfTab = iDataCur;
      sqlite3ExprCachePush(pParse);
      sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel, 
                            SQLITE_JUMPIFNULL);
    }else{
      *piPartIdxLabel = 0;
    }
  }
  nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
  regBase = sqlite3GetTempRange(pParse, nCol);
  if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
  for(j=0; j<nCol; j++){
    if( pPrior
    if( pPrior && pPrior->aiColumn[j]==pIdx->aiColumn[j] ) continue;
    sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j],
                                    regBase+j);
     && pPrior->aiColumn[j]==pIdx->aiColumn[j]
     && pPrior->aiColumn[j]>=(-1)
    ){
      /* This column was already computed by the previous index */
      continue;
    }
    sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j);
    /* If the column affinity is REAL but the number is an integer, then it
    ** might be stored in the table as an integer (using a compact
    ** representation) then converted to REAL by an OP_RealAffinity opcode.
    ** But we are getting ready to store this value back into an index, where
    ** it should be converted by to INTEGER again.  So omit the OP_RealAffinity
    ** opcode if it is present */
    sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity);
99286
99287
99288
99289
99290
99291
99292
99293
99294


99295
99296
99297
99298
99299
99300
99301


99302
99303
99304
99305
99306
99307
99308
99309
99310
99311
99312
99313
99314


99315
99316
99317
99318
99319
99320
99321
99509
99510
99511
99512
99513
99514
99515


99516
99517
99518
99519
99520
99521
99522


99523
99524
99525
99526
99527
99528
99529
99530
99531
99532
99533
99534
99535


99536
99537
99538
99539
99540
99541
99542
99543
99544







-
-
+
+





-
-
+
+











-
-
+
+







    FUNCTION2(ifnull,            2, 0, 0, noopFunc,  SQLITE_FUNC_COALESCE),
    FUNCTION2(unlikely,          1, 0, 0, noopFunc,  SQLITE_FUNC_UNLIKELY),
    FUNCTION2(likelihood,        2, 0, 0, noopFunc,  SQLITE_FUNC_UNLIKELY),
    FUNCTION2(likely,            1, 0, 0, noopFunc,  SQLITE_FUNC_UNLIKELY),
    VFUNCTION(random,            0, 0, 0, randomFunc       ),
    VFUNCTION(randomblob,        1, 0, 0, randomBlob       ),
    FUNCTION(nullif,             2, 0, 1, nullifFunc       ),
    FUNCTION(sqlite_version,     0, 0, 0, versionFunc      ),
    FUNCTION(sqlite_source_id,   0, 0, 0, sourceidFunc     ),
    DFUNCTION(sqlite_version,    0, 0, 0, versionFunc      ),
    DFUNCTION(sqlite_source_id,  0, 0, 0, sourceidFunc     ),
    FUNCTION(sqlite_log,         2, 0, 0, errlogFunc       ),
#if SQLITE_USER_AUTHENTICATION
    FUNCTION(sqlite_crypt,       2, 0, 0, sqlite3CryptFunc ),
#endif
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
    FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc  ),
    FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc  ),
    DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc  ),
    DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc  ),
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
    FUNCTION(quote,              1, 0, 0, quoteFunc        ),
    VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
    VFUNCTION(changes,           0, 0, 0, changes          ),
    VFUNCTION(total_changes,     0, 0, 0, total_changes    ),
    FUNCTION(replace,            3, 0, 0, replaceFunc      ),
    FUNCTION(zeroblob,           1, 0, 0, zeroblobFunc     ),
  #ifdef SQLITE_SOUNDEX
    FUNCTION(soundex,            1, 0, 0, soundexFunc      ),
  #endif
  #ifndef SQLITE_OMIT_LOAD_EXTENSION
    FUNCTION(load_extension,     1, 0, 0, loadExt          ),
    FUNCTION(load_extension,     2, 0, 0, loadExt          ),
    VFUNCTION(load_extension,    1, 0, 0, loadExt          ),
    VFUNCTION(load_extension,    2, 0, 0, loadExt          ),
  #endif
    AGGREGATE(sum,               1, 0, 0, sumStep,         sumFinalize    ),
    AGGREGATE(total,             1, 0, 0, sumStep,         totalFinalize    ),
    AGGREGATE(avg,               1, 0, 0, sumStep,         avgFinalize    ),
    AGGREGATE2(count,            0, 0, 0, countStep,       countFinalize,
               SQLITE_FUNC_COUNT  ),
    AGGREGATE(count,             1, 0, 0, countStep,       countFinalize  ),
99722
99723
99724
99725
99726
99727
99728
99729

99730
99731
99732
99733
99734
99735
99736
99945
99946
99947
99948
99949
99950
99951

99952
99953
99954
99955
99956
99957
99958
99959







-
+







      if( pTab==pFKey->pFrom && nIncr==1 ){
        sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); VdbeCoverage(v);
        sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
      }
  
      sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
      sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
      sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
      sqlite3VdbeGoto(v, iOk);
      sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
      sqlite3VdbeJumpHere(v, iMustBeInt);
      sqlite3ReleaseTempReg(pParse, regTemp);
    }else{
      int nCol = pFKey->nCol;
      int regTemp = sqlite3GetTempRange(pParse, nCol);
      int regRec = sqlite3GetTempReg(pParse);
99760
99761
99762
99763
99764
99765
99766
99767

99768
99769
99770
99771

99772
99773
99774
99775
99776
99777
99778
99983
99984
99985
99986
99987
99988
99989

99990
99991
99992
99993

99994
99995
99996
99997
99998
99999
100000
100001







-
+



-
+







          if( pIdx->aiColumn[i]==pTab->iPKey ){
            /* The parent key is a composite key that includes the IPK column */
            iParent = regData;
          }
          sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v);
          sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
        }
        sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
        sqlite3VdbeGoto(v, iOk);
      }
  
      sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
                        sqlite3IndexAffinityStr(v,pIdx), nCol);
                        sqlite3IndexAffinityStr(pParse->db,pIdx), nCol);
      sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
  
      sqlite3ReleaseTempReg(pParse, regRec);
      sqlite3ReleaseTempRange(pParse, regTemp, nCol);
    }
  }

100821
100822
100823
100824
100825
100826
100827
100828

100829
100830
100831
100832
100833
100834
100835
100836
100837
100838
100839
100840
100841
100842
100843
100844
100845
100846
100847










100848


100849
100850
100851
100852
100853
100854
100855
101044
101045
101046
101047
101048
101049
101050

101051
101052
101053
101054
101055
101056
101057
101058
101059
101060
101061
101062

101063
101064
101065
101066
101067
101068
101069
101070
101071
101072
101073
101074
101075
101076
101077
101078
101079

101080
101081
101082
101083
101084
101085
101086
101087
101088







-
+











-







+
+
+
+
+
+
+
+
+
+
-
+
+







** An extra 'D' is appended to the end of the string to cover the
** rowid that appears as the last column in every index.
**
** Memory for the buffer containing the column index affinity string
** is managed along with the rest of the Index structure. It will be
** released when sqlite3DeleteIndex() is called.
*/
SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){
  if( !pIdx->zColAff ){
    /* The first time a column affinity string for a particular index is
    ** required, it is allocated and populated here. It is then stored as
    ** a member of the Index structure for subsequent use.
    **
    ** The column affinity string will eventually be deleted by
    ** sqliteDeleteIndex() when the Index structure itself is cleaned
    ** up.
    */
    int n;
    Table *pTab = pIdx->pTable;
    sqlite3 *db = sqlite3VdbeDb(v);
    pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
    if( !pIdx->zColAff ){
      db->mallocFailed = 1;
      return 0;
    }
    for(n=0; n<pIdx->nColumn; n++){
      i16 x = pIdx->aiColumn[n];
      if( x>=0 ){
        pIdx->zColAff[n] = pTab->aCol[x].affinity;
      }else if( x==(-1) ){
        pIdx->zColAff[n] = SQLITE_AFF_INTEGER;
      }else{
        char aff;
        assert( x==(-2) );
        assert( pIdx->aColExpr!=0 );
        aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr);
        if( aff==0 ) aff = SQLITE_AFF_BLOB;
      pIdx->zColAff[n] = x<0 ? SQLITE_AFF_INTEGER : pTab->aCol[x].affinity;
        pIdx->zColAff[n] = aff;
      }
    }
    pIdx->zColAff[n] = 0;
  }
 
  return pIdx->zColAff;
}

101012
101013
101014
101015
101016
101017
101018
101019

101020
101021
101022
101023
101024
101025
101026

101027
101028
101029
101030
101031
101032
101033
101245
101246
101247
101248
101249
101250
101251

101252
101253
101254
101255
101256
101257
101258

101259
101260
101261
101262
101263
101264
101265
101266







-
+






-
+







  for(p = pParse->pAinc; p; p = p->pNext){
    pDb = &db->aDb[p->iDb];
    memId = p->regCtr;
    assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
    sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
    sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
    addr = sqlite3VdbeCurrentAddr(v);
    sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
    sqlite3VdbeLoadString(v, memId-1, p->pTab->zName);
    sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); VdbeCoverage(v);
    sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
    sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); VdbeCoverage(v);
    sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
    sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
    sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
    sqlite3VdbeGoto(v, addr+9);
    sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); VdbeCoverage(v);
    sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
    sqlite3VdbeAddOp0(v, OP_Close);
  }
}

/*
101443
101444
101445
101446
101447
101448
101449
101450

101451
101452
101453
101454
101455
101456
101457
101458
101459
101460
101461
101462
101463

101464

101465
101466

101467
101468


101469
101470
101471
101472
101473
101474
101475
101676
101677
101678
101679
101680
101681
101682

101683
101684
101685
101686
101687
101688
101689
101690
101691
101692
101693
101694
101695
101696
101697

101698


101699
101700
101701
101702
101703
101704
101705
101706
101707
101708
101709
101710







-
+













+
-
+
-
-
+


+
+







      regRec = sqlite3GetTempReg(pParse);
      regTempRowid = sqlite3GetTempReg(pParse);
      sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
      addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v);
      sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
      sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
      sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
      sqlite3VdbeAddOp2(v, OP_Goto, 0, addrL);
      sqlite3VdbeGoto(v, addrL);
      sqlite3VdbeJumpHere(v, addrL);
      sqlite3ReleaseTempReg(pParse, regRec);
      sqlite3ReleaseTempReg(pParse, regTempRowid);
    }
  }else{
    /* This is the case if the data for the INSERT is coming from a 
    ** single-row VALUES clause
    */
    NameContext sNC;
    memset(&sNC, 0, sizeof(sNC));
    sNC.pParse = pParse;
    srcTab = -1;
    assert( useTempTable==0 );
    if( pList ){
    nColumn = pList ? pList->nExpr : 0;
      nColumn = pList->nExpr;
    for(i=0; i<nColumn; i++){
      if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
      if( sqlite3ResolveExprListNames(&sNC, pList) ){
        goto insert_cleanup;
      }
    }else{
      nColumn = 0;
    }
  }

  /* If there is no IDLIST term but the table has an integer primary
  ** key, the set the ipkColumn variable to the integer primary key 
  ** column index in the original table definition.
  */
101742
101743
101744
101745
101746
101747
101748
101749

101750
101751
101752
101753
101754
101755
101756
101977
101978
101979
101980
101981
101982
101983

101984
101985
101986
101987
101988
101989
101990
101991







-
+







  */
  sqlite3VdbeResolveLabel(v, endOfLoop);
  if( useTempTable ){
    sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
    sqlite3VdbeJumpHere(v, addrInsTop);
    sqlite3VdbeAddOp1(v, OP_Close, srcTab);
  }else if( pSelect ){
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont);
    sqlite3VdbeGoto(v, addrCont);
    sqlite3VdbeJumpHere(v, addrInsTop);
  }

  if( !IsVirtual(pTab) && !isView ){
    /* Close all tables opened */
    if( iDataCur<iIdxCur ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
    for(idx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
101989
101990
101991
101992
101993
101994
101995
101996

101997
101998
101999
102000
102001
102002
102003
102224
102225
102226
102227
102228
102229
102230

102231
102232
102233
102234
102235
102236
102237
102238







-
+







    ExprList *pCheck = pTab->pCheck;
    pParse->ckBase = regNewData+1;
    onError = overrideError!=OE_Default ? overrideError : OE_Abort;
    for(i=0; i<pCheck->nExpr; i++){
      int allOk = sqlite3VdbeMakeLabel(v);
      sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL);
      if( onError==OE_Ignore ){
        sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
        sqlite3VdbeGoto(v, ignoreDest);
      }else{
        char *zName = pCheck->a[i].zName;
        if( zName==0 ) zName = pTab->zName;
        if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */
        sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
                              onError, zName, P4_TRANSIENT,
                              P5_ConstraintCheck);
102097
102098
102099
102100
102101
102102
102103
102104

102105
102106
102107
102108
102109
102110
102111
102332
102333
102334
102335
102336
102337
102338

102339
102340
102341
102342
102343
102344
102345
102346







-
+







          sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0);
        }
        seenReplace = 1;
        break;
      }
      case OE_Ignore: {
        /*assert( seenReplace==0 );*/
        sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
        sqlite3VdbeGoto(v, ignoreDest);
        break;
      }
    }
    sqlite3VdbeResolveLabel(v, addrRowidOk);
    if( ipkTop ){
      ipkBottom = sqlite3VdbeAddOp0(v, OP_Goto);
      sqlite3VdbeJumpHere(v, ipkTop);
102145
102146
102147
102148
102149
102150
102151






102152
102153
102154
102155
102156
102157
102158
102159
102160










102161
102162
102163
102164
102165
102166
102167
102380
102381
102382
102383
102384
102385
102386
102387
102388
102389
102390
102391
102392









102393
102394
102395
102396
102397
102398
102399
102400
102401
102402
102403
102404
102405
102406
102407
102408
102409







+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







    /* Create a record for this index entry as it should appear after
    ** the insert or update.  Store that record in the aRegIdx[ix] register
    */
    regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
    for(i=0; i<pIdx->nColumn; i++){
      int iField = pIdx->aiColumn[i];
      int x;
      if( iField==(-2) ){
        pParse->ckBase = regNewData+1;
        sqlite3ExprCode(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
        pParse->ckBase = 0;
        VdbeComment((v, "%s column %d", pIdx->zName, i));
      }else{
      if( iField<0 || iField==pTab->iPKey ){
        if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
        x = regNewData;
        regRowid =  pIdx->pPartIdxWhere ? -1 : regIdx+i;
      }else{
        x = iField + regNewData + 1;
      }
      sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
      VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
        if( iField==(-1) || iField==pTab->iPKey ){
          if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
          x = regNewData;
          regRowid =  pIdx->pPartIdxWhere ? -1 : regIdx+i;
        }else{
          x = iField + regNewData + 1;
        }
        sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
        VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
      }
    }
    sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
    VdbeComment((v, "for %s", pIdx->zName));
    sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);

    /* In an UPDATE operation, if this index is the PRIMARY KEY index 
    ** of a WITHOUT ROWID table and there has been no change the
102250
102251
102252
102253
102254
102255
102256
102257

102258
102259
102260
102261
102262
102263
102264
102265
102266
102267
102268
102269
102270
102271
102272
102273
102274
102275
102276
102277
102278

102279
102280
102281
102282
102283
102284
102285
102492
102493
102494
102495
102496
102497
102498

102499
102500
102501
102502
102503
102504
102505
102506
102507
102508
102509
102510
102511
102512
102513
102514
102515
102516
102517
102518
102519

102520
102521
102522
102523
102524
102525
102526
102527







-
+




















-
+







      case OE_Rollback:
      case OE_Abort:
      case OE_Fail: {
        sqlite3UniqueConstraint(pParse, onError, pIdx);
        break;
      }
      case OE_Ignore: {
        sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
        sqlite3VdbeGoto(v, ignoreDest);
        break;
      }
      default: {
        Trigger *pTrigger = 0;
        assert( onError==OE_Replace );
        sqlite3MultiWrite(pParse);
        if( db->flags&SQLITE_RecTriggers ){
          pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
        }
        sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
                                 regR, nPkField, 0, OE_Replace, pIdx==pPk);
        seenReplace = 1;
        break;
      }
    }
    sqlite3VdbeResolveLabel(v, addrUniqueOk);
    sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
    if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
  }
  if( ipkTop ){
    sqlite3VdbeAddOp2(v, OP_Goto, 0, ipkTop+1);
    sqlite3VdbeGoto(v, ipkTop+1);
    sqlite3VdbeJumpHere(v, ipkBottom);
  }
  
  *pbMayReplace = seenReplace;
  VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace));
}

102473
102474
102475
102476
102477
102478
102479







102480
102481
102482
102483
102484
102485
102486
102715
102716
102717
102718
102719
102720
102721
102722
102723
102724
102725
102726
102727
102728
102729
102730
102731
102732
102733
102734
102735







+
+
+
+
+
+
+







  }
  if( pDest->onError!=pSrc->onError ){
    return 0;   /* Different conflict resolution strategies */
  }
  for(i=0; i<pSrc->nKeyCol; i++){
    if( pSrc->aiColumn[i]!=pDest->aiColumn[i] ){
      return 0;   /* Different columns indexed */
    }
    if( pSrc->aiColumn[i]==(-2) ){
      assert( pSrc->aColExpr!=0 && pDest->aColExpr!=0 );
      if( sqlite3ExprCompare(pSrc->aColExpr->a[i].pExpr,
                             pDest->aColExpr->a[i].pExpr, -1)!=0 ){
        return 0;   /* Different expressions in the index */
      }
    }
    if( pSrc->aSortOrder[i]!=pDest->aSortOrder[i] ){
      return 0;   /* Different sort orders */
    }
    if( !xferCompatibleCollation(pSrc->azColl[i],pDest->azColl[i]) ){
      return 0;   /* Different collating sequences */
    }
102717
102718
102719
102720
102721
102722
102723
102724

102725
102726
102727
102728
102729
102730
102731
102966
102967
102968
102969
102970
102971
102972

102973
102974
102975
102976
102977
102978
102979
102980







-
+







    **
    ** (2) The destination has a unique index.  (The xfer optimization 
    **     is unable to test uniqueness.)
    **
    ** (3) onError is something other than OE_Abort and OE_Rollback.
    */
    addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
    emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
    emptyDestTest = sqlite3VdbeAddOp0(v, OP_Goto);
    sqlite3VdbeJumpHere(v, addr1);
  }
  if( HasRowid(pSrc) ){
    sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
    emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
    if( pDest->iPKey>=0 ){
      addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
103394
103395
103396
103397
103398
103399
103400

103401
103402
103403
103404
103405
103406
103407
103643
103644
103645
103646
103647
103648
103649
103650
103651
103652
103653
103654
103655
103656
103657







+







#define sqlite3_value_numeric_type     sqlite3_api->value_numeric_type
#define sqlite3_value_text             sqlite3_api->value_text
#define sqlite3_value_text16           sqlite3_api->value_text16
#define sqlite3_value_text16be         sqlite3_api->value_text16be
#define sqlite3_value_text16le         sqlite3_api->value_text16le
#define sqlite3_value_type             sqlite3_api->value_type
#define sqlite3_vmprintf               sqlite3_api->vmprintf
#define sqlite3_vsnprintf              sqlite3_api->vsnprintf
#define sqlite3_overload_function      sqlite3_api->overload_function
#define sqlite3_prepare_v2             sqlite3_api->prepare_v2
#define sqlite3_prepare16_v2           sqlite3_api->prepare16_v2
#define sqlite3_clear_bindings         sqlite3_api->clear_bindings
#define sqlite3_bind_zeroblob          sqlite3_api->bind_zeroblob
#define sqlite3_blob_bytes             sqlite3_api->blob_bytes
#define sqlite3_blob_close             sqlite3_api->blob_close
104896
104897
104898
104899
104900
104901
104902
104903
104904


















104905
104906
104907
104908


104909
104910


104911
104912
104913
104914
104915
104916
104917















104918
104919
104920
104921
104922
104923
104924
105146
105147
105148
105149
105150
105151
105152
105153
105154
105155
105156
105157
105158
105159
105160
105161
105162
105163
105164
105165
105166
105167
105168
105169
105170
105171
105172
105173
105174


105175
105176


105177
105178







105179
105180
105181
105182
105183
105184
105185
105186
105187
105188
105189
105190
105191
105192
105193
105194
105195
105196
105197
105198
105199
105200









+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  if( invalidateTempStorage( pParse ) != SQLITE_OK ){
    return SQLITE_ERROR;
  }
  db->temp_store = (u8)ts;
  return SQLITE_OK;
}
#endif /* SQLITE_PAGER_PRAGMAS */

/*
** Set the names of the first N columns to the values in azCol[]
*/
static void setAllColumnNames(
  Vdbe *v,               /* The query under construction */
  int N,                 /* Number of columns */
  const char **azCol     /* Names of columns */
){
  int i;
  sqlite3VdbeSetNumCols(v, N);
  for(i=0; i<N; i++){
    sqlite3VdbeSetColName(v, i, COLNAME_NAME, azCol[i], SQLITE_STATIC);
  }
}
static void setOneColumnName(Vdbe *v, const char *z){
  setAllColumnNames(v, 1, &z);
}

/*
** Generate code to return a single integer value.
*/
static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
  Vdbe *v = sqlite3GetVdbe(pParse);
static void returnSingleInt(Vdbe *v, const char *zLabel, i64 value){
  sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
  int nMem = ++pParse->nMem;
  i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
  setOneColumnName(v, zLabel);
  sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
  if( pI64 ){
    memcpy(pI64, &value, sizeof(value));
  }
  sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64);
  sqlite3VdbeSetNumCols(v, 1);
  sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
  sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
}

/*
** Generate code to return a single text value.
*/
static void returnSingleText(
  Vdbe *v,                /* Prepared statement under construction */
  const char *zLabel,     /* Name of the result column */
  const char *zValue      /* Value to be returned */
){
  if( zValue ){
    sqlite3VdbeLoadString(v, 1, (const char*)zValue);
    setOneColumnName(v, zLabel);
    sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
  }
}


/*
** Set the safety_level and pager flags for pager iDb.  Or if iDb<0
** set these values for all pagers.
*/
105074
105075
105076
105077
105078
105079
105080
105081

105082
105083
105084
105085
105086
105087

105088
105089
105090
105091
105092
105093
105094
105095
105350
105351
105352
105353
105354
105355
105356

105357






105358

105359
105360
105361
105362
105363
105364
105365







-
+
-
-
-
-
-
-
+
-







  aFcntl[0] = 0;
  aFcntl[1] = zLeft;
  aFcntl[2] = zRight;
  aFcntl[3] = 0;
  db->busyHandler.nBusy = 0;
  rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
  if( rc==SQLITE_OK ){
    if( aFcntl[0] ){
    returnSingleText(v, "result", aFcntl[0]);
      int nMem = ++pParse->nMem;
      sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0);
      sqlite3VdbeSetNumCols(v, 1);
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
      sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
      sqlite3_free(aFcntl[0]);
    sqlite3_free(aFcntl[0]);
    }
    goto pragma_out;
  }
  if( rc!=SQLITE_NOTFOUND ){
    if( aFcntl[0] ){
      sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
      sqlite3_free(aFcntl[0]);
    }
105151
105152
105153
105154
105155
105156
105157
105158
105159

105160
105161
105162
105163
105164
105165
105166
105421
105422
105423
105424
105425
105426
105427


105428
105429
105430
105431
105432
105433
105434
105435







-
-
+







      { OP_Integer,     0, 1,        0},                         /* 6 */
      { OP_Noop,        0, 0,        0},
      { OP_ResultRow,   1, 1,        0},
    };
    int addr;
    sqlite3VdbeUsesBtree(v, iDb);
    if( !zRight ){
      sqlite3VdbeSetNumCols(v, 1);
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
      setOneColumnName(v, "cache_size");
      pParse->nMem += 2;
      addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
      sqlite3VdbeChangeP1(v, addr, iDb);
      sqlite3VdbeChangeP1(v, addr+1, iDb);
      sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
    }else{
      int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
105186
105187
105188
105189
105190
105191
105192
105193

105194
105195
105196
105197
105198
105199
105200
105455
105456
105457
105458
105459
105460
105461

105462
105463
105464
105465
105466
105467
105468
105469







-
+







  ** the database has not yet been created.
  */
  case PragTyp_PAGE_SIZE: {
    Btree *pBt = pDb->pBt;
    assert( pBt!=0 );
    if( !zRight ){
      int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
      returnSingleInt(pParse, "page_size", size);
      returnSingleInt(v, "page_size", size);
    }else{
      /* Malloc may fail when setting the page-size, as there is an internal
      ** buffer that the pager module resizes using sqlite3_realloc().
      */
      db->nextPagesize = sqlite3Atoi(zRight);
      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
        db->mallocFailed = 1;
105221
105222
105223
105224
105225
105226
105227
105228

105229
105230
105231
105232
105233
105234
105235
105490
105491
105492
105493
105494
105495
105496

105497
105498
105499
105500
105501
105502
105503
105504







-
+







    if( pId2->n==0 && b>=0 ){
      int ii;
      for(ii=0; ii<db->nDb; ii++){
        sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
      }
    }
    b = sqlite3BtreeSecureDelete(pBt, b);
    returnSingleInt(pParse, "secure_delete", b);
    returnSingleInt(v, "secure_delete", b);
    break;
  }

  /*
  **  PRAGMA [database.]max_page_count
  **  PRAGMA [database.]max_page_count=N
  **
105300
105301
105302
105303
105304
105305
105306
105307
105308

105309
105310
105311
105312
105313
105314
105315
105316
105317
105318
105319
105320
105321
105322
105323
105324
105325

105326
105327
105328
105329
105330
105331
105332
105569
105570
105571
105572
105573
105574
105575


105576


105577
105578
105579
105580
105581
105582
105583
105584
105585
105586
105587
105588



105589
105590
105591
105592
105593
105594
105595
105596







-
-
+
-
-












-
-
-
+







    }

    assert( eMode==PAGER_LOCKINGMODE_NORMAL
            || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
    if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
      zRet = "exclusive";
    }
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
    returnSingleText(v, "locking_mode", zRet);
    sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
    sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
    break;
  }

  /*
  **  PRAGMA [database.]journal_mode
  **  PRAGMA [database.]journal_mode =
  **                      (delete|persist|off|truncate|memory|wal|off)
  */
  case PragTyp_JOURNAL_MODE: {
    int eMode;        /* One of the PAGER_JOURNALMODE_XXX symbols */
    int ii;           /* Loop counter */

    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);

    setOneColumnName(v, "journal_mode");
    if( zRight==0 ){
      /* If there is no "=MODE" part of the pragma, do a query for the
      ** current mode */
      eMode = PAGER_JOURNALMODE_QUERY;
    }else{
      const char *zMode;
      int n = sqlite3Strlen30(zRight);
105364
105365
105366
105367
105368
105369
105370
105371

105372
105373
105374
105375
105376
105377
105378
105379
105380
105381
105382
105383
105384
105385
105386
105387
105388
105389

105390
105391
105392
105393
105394
105395
105396
105628
105629
105630
105631
105632
105633
105634

105635
105636
105637
105638
105639
105640
105641
105642
105643
105644
105645
105646
105647
105648
105649
105650
105651
105652

105653
105654
105655
105656
105657
105658
105659
105660







-
+

















-
+







    Pager *pPager = sqlite3BtreePager(pDb->pBt);
    i64 iLimit = -2;
    if( zRight ){
      sqlite3DecOrHexToI64(zRight, &iLimit);
      if( iLimit<-1 ) iLimit = -1;
    }
    iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
    returnSingleInt(pParse, "journal_size_limit", iLimit);
    returnSingleInt(v, "journal_size_limit", iLimit);
    break;
  }

#endif /* SQLITE_OMIT_PAGER_PRAGMAS */

  /*
  **  PRAGMA [database.]auto_vacuum
  **  PRAGMA [database.]auto_vacuum=N
  **
  ** Get or set the value of the database 'auto-vacuum' parameter.
  ** The value is one of:  0 NONE 1 FULL 2 INCREMENTAL
  */
#ifndef SQLITE_OMIT_AUTOVACUUM
  case PragTyp_AUTO_VACUUM: {
    Btree *pBt = pDb->pBt;
    assert( pBt!=0 );
    if( !zRight ){
      returnSingleInt(pParse, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
      returnSingleInt(v, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
    }else{
      int eAuto = getAutoVacuum(zRight);
      assert( eAuto>=0 && eAuto<=2 );
      db->nextAutovac = (u8)eAuto;
      /* Call SetAutoVacuum() to set initialize the internal auto and
      ** incr-vacuum flags. This is required in case this connection
      ** creates the database file. It is important that it is created
105460
105461
105462
105463
105464
105465
105466
105467

105468
105469
105470
105471
105472
105473
105474
105724
105725
105726
105727
105728
105729
105730

105731
105732
105733
105734
105735
105736
105737
105738







-
+







  ** number of pages is adjusted so that the cache uses -N kibibytes
  ** of memory.
  */
  case PragTyp_CACHE_SIZE: {
    assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
    if( !zRight ){
      if( sqlite3ReadSchema(pParse) ) goto pragma_out;
      returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
      returnSingleInt(v, "cache_size", pDb->pSchema->cache_size);
    }else{
      int size = sqlite3Atoi(zRight);
      pDb->pSchema->cache_size = size;
      sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
      if( sqlite3ReadSchema(pParse) ) goto pragma_out;
    }
    break;
105506
105507
105508
105509
105510
105511
105512
105513

105514
105515
105516
105517
105518
105519
105520
105521
105522
105523
105524
105525
105526
105527
105528
105529
105530
105531
105532
105533
105534

105535
105536
105537
105538
105539
105540
105541
105542
105543
105544
105545
105546
105547
105548
105549
105550
105551
105552
105553

105554
105555
105556
105557
105558
105559
105560
105561
105562
105563
105564
105565
105566
105770
105771
105772
105773
105774
105775
105776

105777
105778
105779
105780
105781
105782
105783
105784
105785
105786
105787
105788
105789
105790
105791
105792
105793
105794
105795
105796
105797

105798
105799
105800
105801
105802
105803
105804
105805
105806
105807
105808
105809
105810
105811
105812
105813
105814
105815
105816

105817






105818
105819
105820
105821
105822
105823
105824







-
+




















-
+


















-
+
-
-
-
-
-
-







    sz = -1;
    rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_MMAP_SIZE, &sz);
#else
    sz = 0;
    rc = SQLITE_OK;
#endif
    if( rc==SQLITE_OK ){
      returnSingleInt(pParse, "mmap_size", sz);
      returnSingleInt(v, "mmap_size", sz);
    }else if( rc!=SQLITE_NOTFOUND ){
      pParse->nErr++;
      pParse->rc = rc;
    }
    break;
  }

  /*
  **   PRAGMA temp_store
  **   PRAGMA temp_store = "default"|"memory"|"file"
  **
  ** Return or set the local value of the temp_store flag.  Changing
  ** the local value does not make changes to the disk file and the default
  ** value will be restored the next time the database is opened.
  **
  ** Note that it is possible for the library compile-time options to
  ** override this setting
  */
  case PragTyp_TEMP_STORE: {
    if( !zRight ){
      returnSingleInt(pParse, "temp_store", db->temp_store);
      returnSingleInt(v, "temp_store", db->temp_store);
    }else{
      changeTempStorage(pParse, zRight);
    }
    break;
  }

  /*
  **   PRAGMA temp_store_directory
  **   PRAGMA temp_store_directory = ""|"directory_name"
  **
  ** Return or set the local value of the temp_store_directory flag.  Changing
  ** the value sets a specific directory to be used for temporary files.
  ** Setting to a null string reverts to the default temporary directory search.
  ** If temporary directory is changed, then invalidateTempStorage.
  **
  */
  case PragTyp_TEMP_STORE_DIRECTORY: {
    if( !zRight ){
      if( sqlite3_temp_directory ){
      returnSingleText(v, "temp_store_directory", sqlite3_temp_directory);
        sqlite3VdbeSetNumCols(v, 1);
        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
            "temp_store_directory", SQLITE_STATIC);
        sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
        sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
      }
    }else{
#ifndef SQLITE_OMIT_WSD
      if( zRight[0] ){
        int res;
        rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
        if( rc!=SQLITE_OK || res==0 ){
          sqlite3ErrorMsg(pParse, "not a writable directory");
105596
105597
105598
105599
105600
105601
105602
105603

105604
105605
105606
105607
105608
105609
105610
105611
105612
105613
105614
105615
105616
105854
105855
105856
105857
105858
105859
105860

105861






105862
105863
105864
105865
105866
105867
105868







-
+
-
-
-
-
-
-







  ** a relative path will probably be based on the current directory for the
  ** process.  Database file specified with an absolute path are not impacted
  ** by this setting, regardless of its value.
  **
  */
  case PragTyp_DATA_STORE_DIRECTORY: {
    if( !zRight ){
      if( sqlite3_data_directory ){
      returnSingleText(v, "data_store_directory", sqlite3_data_directory);
        sqlite3VdbeSetNumCols(v, 1);
        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
            "data_store_directory", SQLITE_STATIC);
        sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_data_directory, 0);
        sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
      }
    }else{
#ifndef SQLITE_OMIT_WSD
      if( zRight[0] ){
        int res;
        rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
        if( rc!=SQLITE_OK || res==0 ){
          sqlite3ErrorMsg(pParse, "not a writable directory");
105641
105642
105643
105644
105645
105646
105647
105648
105649
105650
105651
105652

105653
105654
105655
105656
105657
105658
105659
105660
105661
105662
105893
105894
105895
105896
105897
105898
105899





105900



105901
105902
105903
105904
105905
105906
105907







-
-
-
-
-
+
-
-
-







  case PragTyp_LOCK_PROXY_FILE: {
    if( !zRight ){
      Pager *pPager = sqlite3BtreePager(pDb->pBt);
      char *proxy_file_path = NULL;
      sqlite3_file *pFile = sqlite3PagerFile(pPager);
      sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE, 
                           &proxy_file_path);
      
      if( proxy_file_path ){
        sqlite3VdbeSetNumCols(v, 1);
        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
                              "lock_proxy_file", SQLITE_STATIC);
      returnSingleText(v, "lock_proxy_file", proxy_file_path);
        sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, proxy_file_path, 0);
        sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
      }
    }else{
      Pager *pPager = sqlite3BtreePager(pDb->pBt);
      sqlite3_file *pFile = sqlite3PagerFile(pPager);
      int res;
      if( zRight[0] ){
        res=sqlite3OsFileControl(pFile, SQLITE_SET_LOCKPROXYFILE, 
                                     zRight);
105680
105681
105682
105683
105684
105685
105686
105687

105688
105689
105690
105691
105692
105693
105694
105695
105696
105697
105698
105699
105700
105701
105702
105703
105704
105705
105706

105707
105708
105709
105710
105711
105712
105713
105925
105926
105927
105928
105929
105930
105931

105932
105933
105934
105935
105936
105937
105938
105939
105940
105941
105942
105943
105944
105945
105946
105947
105948
105949
105950

105951
105952
105953
105954
105955
105956
105957
105958







-
+


















-
+







  ** Return or set the local value of the synchronous flag.  Changing
  ** the local value does not make changes to the disk file and the
  ** default value will be restored the next time the database is
  ** opened.
  */
  case PragTyp_SYNCHRONOUS: {
    if( !zRight ){
      returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
      returnSingleInt(v, "synchronous", pDb->safety_level-1);
    }else{
      if( !db->autoCommit ){
        sqlite3ErrorMsg(pParse, 
            "Safety level may not be changed inside a transaction");
      }else{
        int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK;
        if( iLevel==0 ) iLevel = 1;
        pDb->safety_level = iLevel;
        setAllPagerFlags(db);
      }
    }
    break;
  }
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */

#ifndef SQLITE_OMIT_FLAG_PRAGMAS
  case PragTyp_FLAG: {
    if( zRight==0 ){
      returnSingleInt(pParse, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
      returnSingleInt(v, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
    }else{
      int mask = pPragma->iArg;    /* Mask of bits to set or clear. */
      if( db->autoCommit==0 ){
        /* Foreign key support may not be enabled or disabled while not
        ** in auto-commit mode.  */
        mask &= ~(SQLITE_ForeignKeys);
      }
105749
105750
105751
105752
105753
105754
105755



105756
105757
105758
105759
105760
105761
105762
105763
105764
105765
105766
105767
105768

105769
105770
105771
105772
105773
105774
105775
105776
105777
105778
105779
105780
105781
105782
105783
105784
105785
105786
105787
105788
105789
105790
105791
105792







105793
105794
105795
105796
105797
105798
105799

105800
105801
105802
105803
105804
105805
105806
105807
105808
105809

105810
105811

105812
105813


105814
105815

105816
105817

105818
105819
105820
105821
105822



105823
105824

105825
105826
105827
105828
105829
105830
105831
105832
105833
105834
105835



105836
105837
105838
105839
105840
105841
105842
105843
105844
105845
105846
105847
105848
105849
105850
105851
105852
105853

105854
105855
105856
105857

105858
105859
105860

105861
105862
105863
105864
105865

105866
105867

105868
105869
105870



105871
105872
105873
105874
105875
105876
105877
105878
105879
105880
105881
105882
105883



105884
105885
105886
105887
105888
105889
105890

105891
105892
105893
105894
105895
105896
105897
105898
105899






105900
105901
105902
105903
105904
105905
105906

105907
105908
105909
105910

105911
105912
105913
105914
105915
105916
105917



105918
105919

105920
105921
105922
105923
105924
105925

105926
105927
105928
105929
105930

105931
105932
105933
105934

105935
105936
105937
105938
105939
105940
105941
105942
105943
105944
105945
105946
105947
105948
105949
105950




105951
105952
105953
105954
105955
105956
105957
105958

105959
105960
105961
105962
105963
105964
105965





105966
105967
105968



105969
105970
105971
105972
105973
105974
105975
105976
105977

105978
105979
105980
105981
105982
105983
105984
105994
105995
105996
105997
105998
105999
106000
106001
106002
106003
106004
106005
106006
106007

106008
106009






106010
106011
106012
106013
106014
106015
106016










106017
106018
106019
106020
106021
106022
106023

106024
106025
106026
106027
106028
106029
106030
106031
106032
106033
106034
106035
106036
106037
106038
106039
106040
106041

106042
106043




106044
106045
106046
106047


106048
106049


106050


106051
106052
106053



106054
106055
106056


106057
106058
106059
106060
106061
106062
106063
106064
106065
106066
106067
106068
106069
106070
106071
106072
106073
106074
106075
106076
106077
106078
106079
106080
106081
106082
106083

106084




106085




106086
106087
106088

106089





106090

106091
106092



106093
106094
106095
106096
106097
106098
106099
106100
106101
106102
106103
106104
106105
106106
106107
106108
106109
106110
106111
106112

106113
106114



106115


106116
106117





106118
106119
106120
106121
106122
106123
106124
106125
106126
106127
106128
106129
106130
106131
106132

106133

106134


106135
106136
106137


106138
106139
106140


106141
106142
106143
106144
106145
106146
106147
106148
106149
106150

106151

106152

106153
106154

106155

106156
106157
106158
106159
106160
106161
106162
106163
106164
106165
106166
106167
106168
106169
106170
106171
106172
106173
106174
106175

106176
106177




106178




106179
106180
106181
106182
106183
106184
106185
106186



106187
106188
106189









106190
106191
106192
106193
106194
106195
106196
106197







+
+
+




-


-
-
-
-
-
-
+






-
-
-
-
-
-
-
-
-
-







-
+
+
+
+
+
+
+







+



-


-
-
-
-
+


+
-
-
+
+
-
-
+
-
-
+


-
-
-
+
+
+
-
-
+











+
+
+












-

-
-
-
-
+
-
-
-
-
+


-
+
-
-
-
-
-
+
-

+
-
-
-
+
+
+













+
+
+

-


-
-
-
+
-
-


-
-
-
-
-
+
+
+
+
+
+







+

-

-
+
-
-



-
-
+
+
+
-
-
+






+


-

-
+
-


-
+
-















+
+
+
+

-


-
-
-
-
+
-
-
-
-



+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
+







  ** notnull:    True if 'NOT NULL' is part of column declaration
  ** dflt_value: The default value for the column, if any.
  */
  case PragTyp_TABLE_INFO: if( zRight ){
    Table *pTab;
    pTab = sqlite3FindTable(db, zRight, zDb);
    if( pTab ){
      static const char *azCol[] = {
         "cid", "name", "type", "notnull", "dflt_value", "pk"
      };
      int i, k;
      int nHidden = 0;
      Column *pCol;
      Index *pPk = sqlite3PrimaryKeyIndex(pTab);
      sqlite3VdbeSetNumCols(v, 6);
      pParse->nMem = 6;
      sqlite3CodeVerifySchema(pParse, iDb);
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
      sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
      sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
      sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC);
      setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) );
      sqlite3ViewGetColumnNames(pParse, pTab);
      for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
        if( IsHiddenColumn(pCol) ){
          nHidden++;
          continue;
        }
        sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1);
        sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
        sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
           pCol->zType ? pCol->zType : "", 0);
        sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
        if( pCol->zDflt ){
          sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
        }else{
          sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
        }
        if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
          k = 0;
        }else if( pPk==0 ){
          k = 1;
        }else{
          for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
        }
        sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
        sqlite3VdbeMultiLoad(v, 1, "issisi",
               i-nHidden,
               pCol->zName,
               pCol->zType ? pCol->zType : "",
               pCol->notNull ? 1 : 0,
               pCol->zDflt,
               k);
        sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
      }
    }
  }
  break;

  case PragTyp_STATS: {
    static const char *azCol[] = { "table", "index", "width", "height" };
    Index *pIdx;
    HashElem *i;
    v = sqlite3GetVdbe(pParse);
    sqlite3VdbeSetNumCols(v, 4);
    pParse->nMem = 4;
    sqlite3CodeVerifySchema(pParse, iDb);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "index", SQLITE_STATIC);
    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "width", SQLITE_STATIC);
    sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "height", SQLITE_STATIC);
    setAllColumnNames(v, 4, azCol);  assert( 4==ArraySize(azCol) );
    for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
      Table *pTab = sqliteHashData(i);
      sqlite3VdbeMultiLoad(v, 1, "ssii",
      sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, pTab->zName, 0);
      sqlite3VdbeAddOp2(v, OP_Null, 0, 2);
           pTab->zName,
           0,
      sqlite3VdbeAddOp2(v, OP_Integer,
                           (int)sqlite3LogEstToInt(pTab->szTabRow), 3);
           (int)sqlite3LogEstToInt(pTab->szTabRow),
      sqlite3VdbeAddOp2(v, OP_Integer, 
          (int)sqlite3LogEstToInt(pTab->nRowLogEst), 4);
           (int)sqlite3LogEstToInt(pTab->nRowLogEst));
      sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
      for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
        sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
        sqlite3VdbeAddOp2(v, OP_Integer,
                             (int)sqlite3LogEstToInt(pIdx->szIdxRow), 3);
        sqlite3VdbeMultiLoad(v, 2, "sii",
           pIdx->zName,
           (int)sqlite3LogEstToInt(pIdx->szIdxRow),
        sqlite3VdbeAddOp2(v, OP_Integer, 
            (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0]), 4);
           (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0]));
        sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
      }
    }
  }
  break;

  case PragTyp_INDEX_INFO: if( zRight ){
    Index *pIdx;
    Table *pTab;
    pIdx = sqlite3FindIndex(db, zRight, zDb);
    if( pIdx ){
      static const char *azCol[] = {
         "seqno", "cid", "name", "desc", "coll", "key"
      };
      int i;
      int mx;
      if( pPragma->iArg ){
        /* PRAGMA index_xinfo (newer version with more rows and columns) */
        mx = pIdx->nColumn;
        pParse->nMem = 6;
      }else{
        /* PRAGMA index_info (legacy version) */
        mx = pIdx->nKeyCol;
        pParse->nMem = 3;
      }
      pTab = pIdx->pTable;
      sqlite3VdbeSetNumCols(v, pParse->nMem);
      sqlite3CodeVerifySchema(pParse, iDb);
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
      if( pPragma->iArg ){
      assert( pParse->nMem<=ArraySize(azCol) );
        sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "desc", SQLITE_STATIC);
        sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "coll", SQLITE_STATIC);
        sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "key", SQLITE_STATIC);
      }
      setAllColumnNames(v, pParse->nMem, azCol);
      for(i=0; i<mx; i++){
        i16 cnum = pIdx->aiColumn[i];
        sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
        sqlite3VdbeMultiLoad(v, 1, "iis", i, cnum,
        sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
        if( cnum<0 ){
          sqlite3VdbeAddOp2(v, OP_Null, 0, 3);
        }else{
          sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
                             cnum<0 ? 0 : pTab->aCol[cnum].zName);
        }
        if( pPragma->iArg ){
          sqlite3VdbeMultiLoad(v, 4, "isi",
          sqlite3VdbeAddOp2(v, OP_Integer, pIdx->aSortOrder[i], 4);
          sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, pIdx->azColl[i], 0);
          sqlite3VdbeAddOp2(v, OP_Integer, i<pIdx->nKeyCol, 6);
            pIdx->aSortOrder[i],
            pIdx->azColl[i],
            i<pIdx->nKeyCol);
        }
        sqlite3VdbeAddOp2(v, OP_ResultRow, 1, pParse->nMem);
      }
    }
  }
  break;

  case PragTyp_INDEX_LIST: if( zRight ){
    Index *pIdx;
    Table *pTab;
    int i;
    pTab = sqlite3FindTable(db, zRight, zDb);
    if( pTab ){
      static const char *azCol[] = {
        "seq", "name", "unique", "origin", "partial"
      };
      v = sqlite3GetVdbe(pParse);
      sqlite3VdbeSetNumCols(v, 5);
      pParse->nMem = 5;
      sqlite3CodeVerifySchema(pParse, iDb);
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
      setAllColumnNames(v, 5, azCol);  assert( 5==ArraySize(azCol) );
      sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "origin", SQLITE_STATIC);
      sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "partial", SQLITE_STATIC);
      for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
        const char *azOrigin[] = { "c", "u", "pk" };
        sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
        sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
        sqlite3VdbeAddOp2(v, OP_Integer, IsUniqueIndex(pIdx), 3);
        sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, azOrigin[pIdx->idxType], 0);
        sqlite3VdbeAddOp2(v, OP_Integer, pIdx->pPartIdxWhere!=0, 5);
        sqlite3VdbeMultiLoad(v, 1, "isisi",
           i,
           pIdx->zName,
           IsUniqueIndex(pIdx),
           azOrigin[pIdx->idxType],
           pIdx->pPartIdxWhere!=0);
        sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
      }
    }
  }
  break;

  case PragTyp_DATABASE_LIST: {
    static const char *azCol[] = { "seq", "name", "file" };
    int i;
    sqlite3VdbeSetNumCols(v, 3);
    pParse->nMem = 3;
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
    setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
    for(i=0; i<db->nDb; i++){
      if( db->aDb[i].pBt==0 ) continue;
      assert( db->aDb[i].zName!=0 );
      sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
      sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
      sqlite3VdbeMultiLoad(v, 1, "iss",
         i,
         db->aDb[i].zName,
      sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
           sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
         sqlite3BtreeGetFilename(db->aDb[i].pBt));
      sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
    }
  }
  break;

  case PragTyp_COLLATION_LIST: {
    static const char *azCol[] = { "seq", "name" };
    int i = 0;
    HashElem *p;
    sqlite3VdbeSetNumCols(v, 2);
    pParse->nMem = 2;
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
    setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
    for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
      CollSeq *pColl = (CollSeq *)sqliteHashData(p);
      sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
      sqlite3VdbeMultiLoad(v, 1, "is", i++, pColl->zName);
      sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
      sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
    }
  }
  break;
#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */

#ifndef SQLITE_OMIT_FOREIGN_KEY
  case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
    FKey *pFK;
    Table *pTab;
    pTab = sqlite3FindTable(db, zRight, zDb);
    if( pTab ){
      v = sqlite3GetVdbe(pParse);
      pFK = pTab->pFKey;
      if( pFK ){
        static const char *azCol[] = {
           "id", "seq", "table", "from", "to", "on_update", "on_delete",
           "match"
        };
        int i = 0; 
        sqlite3VdbeSetNumCols(v, 8);
        pParse->nMem = 8;
        sqlite3CodeVerifySchema(pParse, iDb);
        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC);
        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC);
        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
        sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC);
        setAllColumnNames(v, 8, azCol); assert( 8==ArraySize(azCol) );
        sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC);
        sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC);
        sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC);
        sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC);
        while(pFK){
          int j;
          for(j=0; j<pFK->nCol; j++){
            sqlite3VdbeMultiLoad(v, 1, "iissssss",
                   i,
                   j,
                   pFK->zTo,
                   pTab->aCol[pFK->aCol[j].iFrom].zName,
            char *zCol = pFK->aCol[j].zCol;
            char *zOnDelete = (char *)actionName(pFK->aAction[0]);
            char *zOnUpdate = (char *)actionName(pFK->aAction[1]);
                   pFK->aCol[j].zCol,
                   actionName(pFK->aAction[1]),  /* ON UPDATE */
                   actionName(pFK->aAction[0]),  /* ON DELETE */
            sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
            sqlite3VdbeAddOp2(v, OP_Integer, j, 2);
            sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0);
            sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
                              pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
            sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0);
            sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0);
            sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0);
            sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0);
                   "NONE");
            sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8);
          }
          ++i;
          pFK = pFK->pNextFrom;
        }
      }
    }
105999
106000
106001
106002
106003
106004
106005

106006
106007
106008
106009
106010
106011
106012

106013
106014
106015
106016
106017
106018
106019
106020
106021
106022
106023
106024
106025
106026
106027
106028
106029
106030
106031

106032
106033
106034
106035
106036
106037
106038
106039
106212
106213
106214
106215
106216
106217
106218
106219
106220
106221
106222
106223
106224
106225

106226




106227
106228
106229
106230
106231
106232
106233
106234
106235
106236
106237
106238
106239
106240

106241

106242
106243
106244
106245
106246
106247
106248







+






-
+
-
-
-
-














-
+
-







    int x;                 /* result variable */
    int regResult;         /* 3 registers to hold a result row */
    int regKey;            /* Register to hold key for checking the FK */
    int regRow;            /* Registers to hold a row from pTab */
    int addrTop;           /* Top of a loop checking foreign keys */
    int addrOk;            /* Jump here if the key is OK */
    int *aiCols;           /* child to parent column mapping */
    static const char *azCol[] = { "table", "rowid", "parent", "fkid" };

    regResult = pParse->nMem+1;
    pParse->nMem += 4;
    regKey = ++pParse->nMem;
    regRow = ++pParse->nMem;
    v = sqlite3GetVdbe(pParse);
    sqlite3VdbeSetNumCols(v, 4);
    setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "rowid", SQLITE_STATIC);
    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "parent", SQLITE_STATIC);
    sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "fkid", SQLITE_STATIC);
    sqlite3CodeVerifySchema(pParse, iDb);
    k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
    while( k ){
      if( zRight ){
        pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
        k = 0;
      }else{
        pTab = (Table*)sqliteHashData(k);
        k = sqliteHashNext(k);
      }
      if( pTab==0 || pTab->pFKey==0 ) continue;
      sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
      if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
      sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
      sqlite3VdbeAddOp4(v, OP_String8, 0, regResult, 0, pTab->zName,
      sqlite3VdbeLoadString(v, regResult, pTab->zName);
                        P4_TRANSIENT);
      for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
        pParent = sqlite3FindTable(db, pFK->zTo, zDb);
        if( pParent==0 ) continue;
        pIdx = 0;
        sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
        x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
        if( x==0 ){
106070
106071
106072
106073
106074
106075
106076
106077

106078
106079
106080
106081
106082
106083
106084
106085
106086
106087

106088
106089
106090
106091
106092
106093

106094
106095
106096
106097
106098
106099
106100
106101
106102
106279
106280
106281
106282
106283
106284
106285

106286
106287
106288
106289
106290
106291
106292
106293
106294
106295

106296
106297
106298
106299
106300
106301

106302


106303
106304
106305
106306
106307
106308
106309







-
+









-
+





-
+
-
-







            sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
            sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow, 
               sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
          }else{
            sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
          }
          sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
          sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
          sqlite3VdbeGoto(v, addrOk);
          sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
        }else{
          for(j=0; j<pFK->nCol; j++){
            sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
                            aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
            sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
          }
          if( pParent ){
            sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
                              sqlite3IndexAffinityStr(v,pIdx), pFK->nCol);
                              sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
            sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
            VdbeCoverage(v);
          }
        }
        sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
        sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0, 
        sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
                          pFK->zTo, P4_TRANSIENT);
        sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
        sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
        sqlite3VdbeResolveLabel(v, addrOk);
        sqlite3DbFree(db, aiCols);
      }
      sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
      sqlite3VdbeJumpHere(v, addrTop);
    }
106164
106165
106166
106167
106168
106169
106170
106171
106172

106173
106174
106175
106176
106177
106178
106179
106371
106372
106373
106374
106375
106376
106377


106378
106379
106380
106381
106382
106383
106384
106385







-
-
+







    ** of all attached databases.  */
    assert( iDb>=0 );
    assert( iDb==0 || pId2->z );
    if( pId2->z==0 ) iDb = -1;

    /* Initialize the VDBE program */
    pParse->nMem = 6;
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC);
    setOneColumnName(v, "integrity_check");

    /* Set the maximum error count */
    mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
    if( zRight ){
      sqlite3GetInt32(zRight, &mxErr);
      if( mxErr<=0 ){
        mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
106287
106288
106289
106290
106291
106292
106293
106294

106295
106296
106297

106298
106299

106300
106301
106302
106303
106304
106305
106306
106307
106308
106309
106310
106311
106312
106313
106314
106315
106316
106317
106318
106319
106320
106321

106322
106323
106324
106325
106326
106327
106328


106329
106330
106331
106332
106333
106334
106335
106336
106337
106338

106339
106340
106341
106342
106343
106344
106345
106346
106347
106348

106349
106350
106351
106352
106353
106354
106355
106493
106494
106495
106496
106497
106498
106499

106500
106501


106502
106503

106504

106505
106506
106507
106508
106509
106510
106511
106512
106513
106514
106515
106516
106517
106518
106519
106520
106521
106522
106523
106524

106525
106526
106527
106528
106529



106530
106531
106532
106533
106534
106535
106536
106537
106538
106539


106540
106541
106542
106543
106544
106545
106546
106547
106548
106549

106550
106551
106552
106553
106554
106555
106556
106557







-
+

-
-
+

-
+
-




















-
+




-
-
-
+
+








-
-
+









-
+







                                       pPrior, r1);
          pPrior = pIdx;
          sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);  /* increment entry count */
          /* Verify that an index entry exists for the current table row */
          jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
                                      pIdx->nColumn); VdbeCoverage(v);
          sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
          sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
          sqlite3VdbeLoadString(v, 3, "row ");
          sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
          sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, 
                            " missing from index ", P4_STATIC);
          sqlite3VdbeLoadString(v, 4, " missing from index ");
          sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
          jmp5 = sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
          jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
                                   pIdx->zName, P4_TRANSIENT);
          sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
          sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
          jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
          sqlite3VdbeAddOp0(v, OP_Halt);
          sqlite3VdbeJumpHere(v, jmp2);
          /* For UNIQUE indexes, verify that only one entry exists with the
          ** current key.  The entry is unique if (1) any column is NULL
          ** or (2) the next entry has a different key */
          if( IsUniqueIndex(pIdx) ){
            int uniqOk = sqlite3VdbeMakeLabel(v);
            int jmp6;
            int kk;
            for(kk=0; kk<pIdx->nKeyCol; kk++){
              int iCol = pIdx->aiColumn[kk];
              assert( iCol>=0 && iCol<pTab->nCol );
              if( pTab->aCol[iCol].notNull ) continue;
              sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
              VdbeCoverage(v);
            }
            jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
            sqlite3VdbeAddOp2(v, OP_Goto, 0, uniqOk);
            sqlite3VdbeGoto(v, uniqOk);
            sqlite3VdbeJumpHere(v, jmp6);
            sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
                                 pIdx->nKeyCol); VdbeCoverage(v);
            sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
            sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
                              "non-unique entry in index ", P4_STATIC);
            sqlite3VdbeAddOp2(v, OP_Goto, 0, jmp5);
            sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
            sqlite3VdbeGoto(v, jmp5);
            sqlite3VdbeResolveLabel(v, uniqOk);
          }
          sqlite3VdbeJumpHere(v, jmp4);
          sqlite3ResolvePartIdxLabel(pParse, jmp3);
        }
        sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
        sqlite3VdbeJumpHere(v, loopTop-1);
#ifndef SQLITE_OMIT_BTREECOUNT
        sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, 
                     "wrong # of entries in index ", P4_STATIC);
        sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
        for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
          if( pPk==pIdx ) continue;
          addr = sqlite3VdbeCurrentAddr(v);
          sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
          sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
          sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
          sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
          sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
          sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
          sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
          sqlite3VdbeLoadString(v, 3, pIdx->zName);
          sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
          sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
        }
#endif /* SQLITE_OMIT_BTREECOUNT */
      } 
    }
    addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
106397
106398
106399
106400
106401
106402
106403
106404
106405
106406
106407
106408
106409
106410

106411
106412
106413
106414
106415
106416
106417
106418
106599
106600
106601
106602
106603
106604
106605



106606
106607
106608

106609

106610
106611
106612
106613
106614
106615
106616







-
-
-



-
+
-







      { "UTF-16",   0                  }, /* SQLITE_UTF16NATIVE */
      { "UTF16",    0                  }, /* SQLITE_UTF16NATIVE */
      { 0, 0 }
    };
    const struct EncName *pEnc;
    if( !zRight ){    /* "PRAGMA encoding" */
      if( sqlite3ReadSchema(pParse) ) goto pragma_out;
      sqlite3VdbeSetNumCols(v, 1);
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
      sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
      assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
      assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
      assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
      sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
      returnSingleText(v, "encoding", encnames[ENC(pParse->db)].zName);
      sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
    }else{                        /* "PRAGMA encoding = XXX" */
      /* Only change the value of sqlite.enc if the database handle is not
      ** initialized. If the main database exists, the new sqlite.enc value
      ** will be overwritten when the schema is next loaded. If it does not
      ** already exists, it will be created to use the new encoding value.
      */
      if( 
106505
106506
106507
106508
106509
106510
106511
106512
106513
106514

106515
106516

106517
106518
106519
106520
106521
106522
106523
106524
106525
106526
106527
106528
106529

106530
106531
106532
106533
106534
106535
106536
106537
106538
106539
106540
106541

106542
106543
106544
106545
106546
106547
106548
106549
106550
106551
106552
106553
106554
106555
106556
106557
106558
106559
106560
106561
106562
106563
106564

106565
106566
106567
106568
106569
106570
106571
106703
106704
106705
106706
106707
106708
106709

106710

106711
106712

106713
106714
106715
106716
106717
106718
106719
106720
106721
106722
106723
106724
106725
106726
106727
106728
106729
106730
106731
106732
106733
106734
106735
106736
106737
106738

106739
106740




106741
106742
106743
106744
106745
106746
106747
106748
106749
106750
106751
106752
106753
106754
106755
106756
106757

106758
106759
106760
106761
106762
106763
106764
106765







-

-
+

-
+













+











-
+

-
-
-
-

















-
+







  **
  ** Return the names of all compile-time options used in this build,
  ** one option per row.
  */
  case PragTyp_COMPILE_OPTIONS: {
    int i = 0;
    const char *zOpt;
    sqlite3VdbeSetNumCols(v, 1);
    pParse->nMem = 1;
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC);
    setOneColumnName(v, "compile_option");
    while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
      sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0);
      sqlite3VdbeLoadString(v, 1, zOpt);
      sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
    }
  }
  break;
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */

#ifndef SQLITE_OMIT_WAL
  /*
  **   PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate
  **
  ** Checkpoint the database.
  */
  case PragTyp_WAL_CHECKPOINT: {
    static const char *azCol[] = { "busy", "log", "checkpointed" };
    int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
    int eMode = SQLITE_CHECKPOINT_PASSIVE;
    if( zRight ){
      if( sqlite3StrICmp(zRight, "full")==0 ){
        eMode = SQLITE_CHECKPOINT_FULL;
      }else if( sqlite3StrICmp(zRight, "restart")==0 ){
        eMode = SQLITE_CHECKPOINT_RESTART;
      }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
        eMode = SQLITE_CHECKPOINT_TRUNCATE;
      }
    }
    sqlite3VdbeSetNumCols(v, 3);
    setAllColumnNames(v, 3, azCol);  assert( 3==ArraySize(azCol) );
    pParse->nMem = 3;
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC);
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC);
    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC);

    sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
    sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
  }
  break;

  /*
  **   PRAGMA wal_autocheckpoint
  **   PRAGMA wal_autocheckpoint = N
  **
  ** Configure a database connection to automatically checkpoint a database
  ** after accumulating N frames in the log. Or query for the current value
  ** of N.
  */
  case PragTyp_WAL_AUTOCHECKPOINT: {
    if( zRight ){
      sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
    }
    returnSingleInt(pParse, "wal_autocheckpoint", 
    returnSingleInt(v, "wal_autocheckpoint", 
       db->xWalCallback==sqlite3WalDefaultHook ? 
           SQLITE_PTR_TO_INT(db->pWalArg) : 0);
  }
  break;
#endif

  /*
106590
106591
106592
106593
106594
106595
106596
106597

106598
106599
106600
106601
106602
106603
106604
106605
106606
106607
106608
106609
106610
106611
106612
106613
106614
106615
106616
106617

106618
106619
106620
106621
106622
106623
106624
106625
106626
106627
106628
106629
106630
106631
106632
106633
106634
106635
106636

106637
106638
106639
106640
106641
106642
106643
106644
106645
106646
106647
106648

106649
106650

106651
106652
106653
106654
106655
106656
106657
106658
106659
106660
106661
106662
106663
106664
106665
106666
106667

106668
106669
106670
106671
106672
106673
106674
106784
106785
106786
106787
106788
106789
106790

106791
106792
106793
106794
106795
106796
106797
106798
106799
106800
106801
106802
106803
106804
106805
106806
106807
106808
106809
106810

106811
106812
106813
106814
106815
106816
106817
106818
106819
106820
106821
106822
106823
106824
106825
106826
106827
106828
106829

106830
106831
106832
106833
106834
106835
106836
106837
106838
106839
106840
106841
106842
106843
106844

106845
106846


106847
106848
106849
106850
106851

106852
106853
106854
106855
106856
106857
106858

106859
106860
106861
106862
106863
106864
106865
106866







-
+



















-
+


















-
+












+

-
+

-
-





-







-
+







  ** disables the timeout.
  */
  /*case PragTyp_BUSY_TIMEOUT*/ default: {
    assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
    if( zRight ){
      sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
    }
    returnSingleInt(pParse, "timeout",  db->busyTimeout);
    returnSingleInt(v, "timeout",  db->busyTimeout);
    break;
  }

  /*
  **   PRAGMA soft_heap_limit
  **   PRAGMA soft_heap_limit = N
  **
  ** IMPLEMENTATION-OF: R-26343-45930 This pragma invokes the
  ** sqlite3_soft_heap_limit64() interface with the argument N, if N is
  ** specified and is a non-negative integer.
  ** IMPLEMENTATION-OF: R-64451-07163 The soft_heap_limit pragma always
  ** returns the same integer that would be returned by the
  ** sqlite3_soft_heap_limit64(-1) C-language function.
  */
  case PragTyp_SOFT_HEAP_LIMIT: {
    sqlite3_int64 N;
    if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
      sqlite3_soft_heap_limit64(N);
    }
    returnSingleInt(pParse, "soft_heap_limit",  sqlite3_soft_heap_limit64(-1));
    returnSingleInt(v, "soft_heap_limit",  sqlite3_soft_heap_limit64(-1));
    break;
  }

  /*
  **   PRAGMA threads
  **   PRAGMA threads = N
  **
  ** Configure the maximum number of worker threads.  Return the new
  ** maximum, which might be less than requested.
  */
  case PragTyp_THREADS: {
    sqlite3_int64 N;
    if( zRight
     && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
     && N>=0
    ){
      sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
    }
    returnSingleInt(pParse, "threads",
    returnSingleInt(v, "threads",
                    sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
    break;
  }

#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
  /*
  ** Report the current state of file logs for all databases
  */
  case PragTyp_LOCK_STATUS: {
    static const char *const azLockName[] = {
      "unlocked", "shared", "reserved", "pending", "exclusive"
    };
    static const char *azCol[] = { "database", "status" };
    int i;
    sqlite3VdbeSetNumCols(v, 2);
    setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
    pParse->nMem = 2;
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC);
    for(i=0; i<db->nDb; i++){
      Btree *pBt;
      const char *zState = "unknown";
      int j;
      if( db->aDb[i].zName==0 ) continue;
      sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
      pBt = db->aDb[i].pBt;
      if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
        zState = "closed";
      }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0, 
                                     SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
         zState = azLockName[j];
      }
      sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC);
      sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
      sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
    }
    break;
  }
#endif

#ifdef SQLITE_HAS_CODEC
108025
108026
108027
108028
108029
108030
108031
108032

108033
108034
108035
108036
108037

108038
108039
108040
108041
108042
108043
108044
108217
108218
108219
108220
108221
108222
108223

108224
108225
108226
108227
108228

108229
108230
108231
108232
108233
108234
108235
108236







-
+




-
+







  pRight = &pLeft[1];
  for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
    Table *pLeftTab = pLeft->pTab;
    Table *pRightTab = pRight->pTab;
    int isOuter;

    if( NEVER(pLeftTab==0 || pRightTab==0) ) continue;
    isOuter = (pRight->jointype & JT_OUTER)!=0;
    isOuter = (pRight->fg.jointype & JT_OUTER)!=0;

    /* When the NATURAL keyword is present, add WHERE clause terms for
    ** every column that the two tables have in common.
    */
    if( pRight->jointype & JT_NATURAL ){
    if( pRight->fg.jointype & JT_NATURAL ){
      if( pRight->pOn || pRight->pUsing ){
        sqlite3ErrorMsg(pParse, "a NATURAL join may not have "
           "an ON or USING clause", 0);
        return 1;
      }
      for(j=0; j<pRightTab->nCol; j++){
        char *zName;   /* Name of column in the right table */
108115
108116
108117
108118
108119
108120
108121

108122
108123
108124
108125
108126
108127
108128
108129
108130
108131
108132
108133
108134

108135
108136
108137
108138
108139
108140
108141
108142


108143
108144
108145
108146
108147
108148
108149
108307
108308
108309
108310
108311
108312
108313
108314
108315
108316
108317
108318
108319
108320
108321
108322
108323
108324
108325
108326
108327
108328
108329
108330
108331
108332
108333
108334
108335

108336
108337
108338
108339
108340
108341
108342
108343
108344







+













+







-
+
+







** through regData+nData-1 onto the sorter.
*/
static void pushOntoSorter(
  Parse *pParse,         /* Parser context */
  SortCtx *pSort,        /* Information about the ORDER BY clause */
  Select *pSelect,       /* The whole SELECT statement */
  int regData,           /* First register holding data to be sorted */
  int regOrigData,       /* First register holding data before packing */
  int nData,             /* Number of elements in the data array */
  int nPrefixReg         /* No. of reg prior to regData available for use */
){
  Vdbe *v = pParse->pVdbe;                         /* Stmt under construction */
  int bSeq = ((pSort->sortFlags & SORTFLAG_UseSorter)==0);
  int nExpr = pSort->pOrderBy->nExpr;              /* No. of ORDER BY terms */
  int nBase = nExpr + bSeq + nData;                /* Fields in sorter record */
  int regBase;                                     /* Regs for sorter record */
  int regRecord = ++pParse->nMem;                  /* Assembled sorter record */
  int nOBSat = pSort->nOBSat;                      /* ORDER BY terms to skip */
  int op;                            /* Opcode to add sorter record to sorter */

  assert( bSeq==0 || bSeq==1 );
  assert( nData==1 || regData==regOrigData );
  if( nPrefixReg ){
    assert( nPrefixReg==nExpr+bSeq );
    regBase = regData - nExpr - bSeq;
  }else{
    regBase = pParse->nMem + 1;
    pParse->nMem += nBase;
  }
  sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, SQLITE_ECEL_DUP);
  sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
                          SQLITE_ECEL_DUP|SQLITE_ECEL_REF);
  if( bSeq ){
    sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
  }
  if( nPrefixReg==0 ){
    sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
  }

108213
108214
108215
108216
108217
108218
108219
108220

108221
108222
108223
108224
108225
108226
108227
108408
108409
108410
108411
108412
108413
108414

108415
108416
108417
108418
108419
108420
108421
108422







-
+







  Vdbe *v,          /* Generate code into this VM */
  int iOffset,      /* Register holding the offset counter */
  int iContinue     /* Jump here to skip the current record */
){
  if( iOffset>0 ){
    int addr;
    addr = sqlite3VdbeAddOp3(v, OP_IfNeg, iOffset, 0, -1); VdbeCoverage(v);
    sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
    sqlite3VdbeGoto(v, iContinue);
    VdbeComment((v, "skip OFFSET records"));
    sqlite3VdbeJumpHere(v, addr);
  }
}

/*
** Add code that will check to make sure the N registers starting at iMem
108345
108346
108347
108348
108349
108350
108351
108352

108353
108354
108355
108356
108357
108358
108359
108540
108541
108542
108543
108544
108545
108546

108547
108548
108549
108550
108551
108552
108553
108554







-
+







    */
    u8 ecelFlags;
    if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){
      ecelFlags = SQLITE_ECEL_DUP;
    }else{
      ecelFlags = 0;
    }
    sqlite3ExprCodeExprList(pParse, pEList, regResult, ecelFlags);
    sqlite3ExprCodeExprList(pParse, pEList, regResult, 0, ecelFlags);
  }

  /* If the DISTINCT keyword was present on the SELECT statement
  ** and this row has been seen before, then do not make this row
  ** part of the result.
  */
  if( hasDistinct ){
108461
108462
108463
108464
108465
108466
108467
108468

108469
108470
108471
108472
108473
108474
108475
108656
108657
108658
108659
108660
108661
108662

108663
108664
108665
108666
108667
108668
108669
108670







-
+







        sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
        VdbeCoverage(v);
        sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
        assert( pSort==0 );
      }
#endif
      if( pSort ){
        pushOntoSorter(pParse, pSort, p, r1+nPrefixReg, 1, nPrefixReg);
        pushOntoSorter(pParse, pSort, p, r1+nPrefixReg,regResult,1,nPrefixReg);
      }else{
        int r2 = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, r2);
        sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, r2);
        sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
        sqlite3ReleaseTempReg(pParse, r2);
      }
108487
108488
108489
108490
108491
108492
108493
108494

108495
108496
108497
108498
108499
108500
108501
108682
108683
108684
108685
108686
108687
108688

108689
108690
108691
108692
108693
108694
108695
108696







-
+







      pDest->affSdst =
                  sqlite3CompareAffinity(pEList->a[0].pExpr, pDest->affSdst);
      if( pSort ){
        /* At first glance you would think we could optimize out the
        ** ORDER BY in this case since the order of entries in the set
        ** does not matter.  But there might be a LIMIT clause, in which
        ** case the order does matter */
        pushOntoSorter(pParse, pSort, p, regResult, 1, nPrefixReg);
        pushOntoSorter(pParse, pSort, p, regResult, regResult, 1, nPrefixReg);
      }else{
        int r1 = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult,1,r1, &pDest->affSdst, 1);
        sqlite3ExprCacheAffinityChange(pParse, regResult, 1);
        sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
        sqlite3ReleaseTempReg(pParse, r1);
      }
108513
108514
108515
108516
108517
108518
108519
108520

108521
108522
108523
108524
108525
108526
108527
108528
108529
108530
108531
108532
108533
108534


108535
108536
108537
108538
108539
108540
108541
108708
108709
108710
108711
108712
108713
108714

108715
108716
108717
108718
108719
108720
108721
108722
108723
108724
108725
108726
108727
108728

108729
108730
108731
108732
108733
108734
108735
108736
108737







-
+













-
+
+







    /* If this is a scalar select that is part of an expression, then
    ** store the results in the appropriate memory cell and break out
    ** of the scan loop.
    */
    case SRT_Mem: {
      assert( nResultCol==1 );
      if( pSort ){
        pushOntoSorter(pParse, pSort, p, regResult, 1, nPrefixReg);
        pushOntoSorter(pParse, pSort, p, regResult, regResult, 1, nPrefixReg);
      }else{
        assert( regResult==iParm );
        /* The LIMIT clause will jump out of the loop for us */
      }
      break;
    }
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */

    case SRT_Coroutine:       /* Send data to a co-routine */
    case SRT_Output: {        /* Return the results */
      testcase( eDest==SRT_Coroutine );
      testcase( eDest==SRT_Output );
      if( pSort ){
        pushOntoSorter(pParse, pSort, p, regResult, nResultCol, nPrefixReg);
        pushOntoSorter(pParse, pSort, p, regResult, regResult, nResultCol,
                       nPrefixReg);
      }else if( eDest==SRT_Coroutine ){
        sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
      }else{
        sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);
        sqlite3ExprCacheAffinityChange(pParse, regResult, nResultCol);
      }
      break;
108821
108822
108823
108824
108825
108826
108827
108828

108829
108830
108831
108832
108833
108834
108835
109017
109018
109019
109020
109021
109022
109023

109024
109025
109026
109027
109028
109029
109030
109031







-
+







  int bSeq;                       /* True if sorter record includes seq. no. */
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
  struct ExprList_item *aOutEx = p->pEList->a;
#endif

  if( pSort->labelBkOut ){
    sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBreak);
    sqlite3VdbeGoto(v, addrBreak);
    sqlite3VdbeResolveLabel(v, pSort->labelBkOut);
  }
  iTab = pSort->iECursor;
  if( eDest==SRT_Output || eDest==SRT_Coroutine ){
    regRowid = 0;
    regRow = pDest->iSdst;
    nSortData = nColumn;
109206
109207
109208
109209
109210
109211
109212
109213

109214
109215
109216
109217
109218
109219
109220
109402
109403
109404
109405
109406
109407
109408

109409
109410
109411
109412
109413
109414
109415
109416







-
+







**
** Only the column names are computed.  Column.zType, Column.zColl,
** and other fields of Column are zeroed.
**
** Return SQLITE_OK on success.  If a memory allocation error occurs,
** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
*/
static int selectColumnsFromExprList(
SQLITE_PRIVATE int sqlite3ColumnsFromExprList(
  Parse *pParse,          /* Parsing context */
  ExprList *pEList,       /* Expr list from which to derive column names */
  i16 *pnCol,             /* Write the number of columns here */
  Column **paCol          /* Write the new column list here */
){
  sqlite3 *db = pParse->db;   /* Database connection */
  int i, j;                   /* Loop counters */
109373
109374
109375
109376
109377
109378
109379
109380

109381
109382
109383
109384
109385
109386
109387
109569
109570
109571
109572
109573
109574
109575

109576
109577
109578
109579
109580
109581
109582
109583







-
+







  }
  /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
  ** is disabled */
  assert( db->lookaside.bEnabled==0 );
  pTab->nRef = 1;
  pTab->zName = 0;
  pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
  selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
  sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
  selectAddColumnTypeAndCollation(pParse, pTab, pSelect);
  pTab->iPKey = -1;
  if( db->mallocFailed ){
    sqlite3DeleteTable(db, pTab);
    return 0;
  }
  return pTab;
109449
109450
109451
109452
109453
109454
109455
109456

109457
109458
109459
109460
109461
109462
109463
109645
109646
109647
109648
109649
109650
109651

109652
109653
109654
109655
109656
109657
109658
109659







-
+







    p->iLimit = iLimit = ++pParse->nMem;
    v = sqlite3GetVdbe(pParse);
    assert( v!=0 );
    if( sqlite3ExprIsInteger(p->pLimit, &n) ){
      sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
      VdbeComment((v, "LIMIT counter"));
      if( n==0 ){
        sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
        sqlite3VdbeGoto(v, iBreak);
      }else if( n>=0 && p->nSelectRow>(u64)n ){
        p->nSelectRow = n;
      }
    }else{
      sqlite3ExprCode(pParse, p->pLimit, iLimit);
      sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
      VdbeComment((v, "LIMIT counter"));
109552
109553
109554
109555
109556
109557
109558
109559

109560
109561
109562
109563
109564
109565
109566
109748
109749
109750
109751
109752
109753
109754

109755
109756
109757
109758
109759
109760
109761
109762







-
+







**
**   <recursive-table> AS (<setup-query> UNION [ALL] <recursive-query>)
**                         \___________/             \_______________/
**                           p->pPrior                      p
**
**
** There is exactly one reference to the recursive-table in the FROM clause
** of recursive-query, marked with the SrcList->a[].isRecursive flag.
** of recursive-query, marked with the SrcList->a[].fg.isRecursive flag.
**
** The setup-query runs once to generate an initial set of rows that go
** into a Queue table.  Rows are extracted from the Queue table one by
** one.  Each row extracted from Queue is output to pDest.  Then the single
** extracted row (now in the iCurrent table) becomes the content of the
** recursive-table for a recursive-query run.  The output of the recursive-query
** is added back into the Queue table.  Then another row is extracted from Queue
109617
109618
109619
109620
109621
109622
109623
109624

109625
109626
109627
109628
109629
109630
109631
109813
109814
109815
109816
109817
109818
109819

109820
109821
109822
109823
109824
109825
109826
109827







-
+







  regOffset = p->iOffset;
  p->pLimit = p->pOffset = 0;
  p->iLimit = p->iOffset = 0;
  pOrderBy = p->pOrderBy;

  /* Locate the cursor number of the Current table */
  for(i=0; ALWAYS(i<pSrc->nSrc); i++){
    if( pSrc->a[i].isRecursive ){
    if( pSrc->a[i].fg.isRecursive ){
      iCurrent = pSrc->a[i].iCursor;
      break;
    }
  }

  /* Allocate cursors numbers for Queue and Distinct.  The cursor number for
  ** the Distinct table must be exactly one greater than Queue in order
109697
109698
109699
109700
109701
109702
109703
109704

109705
109706
109707
109708
109709
109710
109711
109893
109894
109895
109896
109897
109898
109899

109900
109901
109902
109903
109904
109905
109906
109907







-
+







    p->pPrior = 0;
    sqlite3Select(pParse, p, &destQueue);
    assert( p->pPrior==0 );
    p->pPrior = pSetup;
  }

  /* Keep running the loop until the Queue is empty */
  sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
  sqlite3VdbeGoto(v, addrTop);
  sqlite3VdbeResolveLabel(v, addrBreak);

end_of_recursive_query:
  sqlite3ExprListDelete(pParse->db, p->pOrderBy);
  p->pOrderBy = pOrderBy;
  p->pLimit = pLimit;
  p->pOffset = pOffset;
110606
110607
110608
110609
110610
110611
110612
110613

110614
110615
110616
110617
110618
110619
110620
110621
110622
110623
110624
110625
110626
110627

110628
110629
110630
110631
110632
110633
110634
110635

110636
110637
110638
110639
110640
110641
110642
110643
110644
110645
110646
110647
110648

110649
110650
110651
110652
110653
110654
110655
110656
110657
110658
110659

110660
110661
110662
110663
110664
110665
110666
110802
110803
110804
110805
110806
110807
110808

110809
110810
110811
110812
110813
110814
110815
110816
110817
110818
110819
110820
110821
110822

110823
110824
110825
110826
110827
110828
110829
110830

110831
110832
110833
110834
110835
110836
110837
110838
110839
110840
110841
110842
110843

110844
110845
110846
110847
110848
110849
110850
110851
110852
110853
110854

110855
110856
110857
110858
110859
110860
110861
110862







-
+













-
+







-
+












-
+










-
+







  if( op==TK_EXCEPT || op==TK_INTERSECT ){
    addrEofA_noB = addrEofA = labelEnd;
  }else{  
    VdbeNoopComment((v, "eof-A subroutine"));
    addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
    addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
                                     VdbeCoverage(v);
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA);
    sqlite3VdbeGoto(v, addrEofA);
    p->nSelectRow += pPrior->nSelectRow;
  }

  /* Generate a subroutine to run when the results from select B
  ** are exhausted and only data in select A remains.
  */
  if( op==TK_INTERSECT ){
    addrEofB = addrEofA;
    if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
  }else{  
    VdbeNoopComment((v, "eof-B subroutine"));
    addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
    sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB);
    sqlite3VdbeGoto(v, addrEofB);
  }

  /* Generate code to handle the case of A<B
  */
  VdbeNoopComment((v, "A-lt-B subroutine"));
  addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
  sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
  sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
  sqlite3VdbeGoto(v, labelCmpr);

  /* Generate code to handle the case of A==B
  */
  if( op==TK_ALL ){
    addrAeqB = addrAltB;
  }else if( op==TK_INTERSECT ){
    addrAeqB = addrAltB;
    addrAltB++;
  }else{
    VdbeNoopComment((v, "A-eq-B subroutine"));
    addrAeqB =
    sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
    sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
    sqlite3VdbeGoto(v, labelCmpr);
  }

  /* Generate code to handle the case of A>B
  */
  VdbeNoopComment((v, "A-gt-B subroutine"));
  addrAgtB = sqlite3VdbeCurrentAddr(v);
  if( op==TK_ALL || op==TK_UNION ){
    sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
  }
  sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
  sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
  sqlite3VdbeGoto(v, labelCmpr);

  /* This code runs once to initialize everything.
  */
  sqlite3VdbeJumpHere(v, j1);
  sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
  sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);

111032
111033
111034
111035
111036
111037
111038
111039

111040
111041
111042
111043
111044
111045
111046
111228
111229
111230
111231
111232
111233
111234

111235
111236
111237
111238
111239
111240
111241
111242







-
+







  ** effectively converts the OUTER JOIN into an INNER JOIN.
  **
  ** THIS OVERRIDES OBSOLETE COMMENTS 1 AND 2 ABOVE:
  ** Ticket #3300 shows that flattening the right term of a LEFT JOIN
  ** is fraught with danger.  Best to avoid the whole thing.  If the
  ** subquery is the right term of a LEFT JOIN, then do not flatten.
  */
  if( (pSubitem->jointype & JT_OUTER)!=0 ){
  if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
    return 0;
  }

  /* Restriction 17: If the sub-query is a compound SELECT, then it must
  ** use only the UNION ALL operator. And none of the simple select queries
  ** that make up the compound SELECT are allowed to be aggregate or distinct
  ** queries.
111203
111204
111205
111206
111207
111208
111209
111210

111211
111212
111213
111214
111215
111216
111217
111399
111400
111401
111402
111403
111404
111405

111406
111407
111408
111409
111410
111411
111412
111413







-
+







    u8 jointype = 0;
    pSubSrc = pSub->pSrc;     /* FROM clause of subquery */
    nSubSrc = pSubSrc->nSrc;  /* Number of terms in subquery FROM clause */
    pSrc = pParent->pSrc;     /* FROM clause of the outer query */

    if( pSrc ){
      assert( pParent==p );  /* First time through the loop */
      jointype = pSubitem->jointype;
      jointype = pSubitem->fg.jointype;
    }else{
      assert( pParent!=p );  /* 2nd and subsequent times through the loop */
      pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
      if( pSrc==0 ){
        assert( db->mallocFailed );
        break;
      }
111243
111244
111245
111246
111247
111248
111249
111250

111251
111252
111253
111254
111255
111256
111257
111439
111440
111441
111442
111443
111444
111445

111446
111447
111448
111449
111450
111451
111452
111453







-
+







    ** outer query.
    */
    for(i=0; i<nSubSrc; i++){
      sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
      pSrc->a[i+iFrom] = pSubSrc->a[i];
      memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
    }
    pSrc->a[iFrom].jointype = jointype;
    pSrc->a[iFrom].fg.jointype = jointype;
  
    /* Now begin substituting subquery result set expressions for 
    ** references to the iParent in the outer query.
    ** 
    ** Example:
    **
    **   SELECT a+5, b*10 FROM (SELECT x*3 AS a, y+10 AS b FROM t1) WHERE a>b;
111375
111376
111377
111378
111379
111380
111381



111382
111383
111384
111385
111386
111387
111388
111571
111572
111573
111574
111575
111576
111577
111578
111579
111580
111581
111582
111583
111584
111585
111586
111587







+
+
+







**
**   (3) The inner query has a LIMIT clause (since the changes to the WHERE
**       close would change the meaning of the LIMIT).
**
**   (4) The inner query is the right operand of a LEFT JOIN.  (The caller
**       enforces this restriction since this routine does not have enough
**       information to know.)
**
**   (5) The WHERE clause expression originates in the ON or USING clause
**       of a LEFT JOIN.
**
** Return 0 if no changes are made and non-zero if one or more WHERE clause
** terms are duplicated into the subquery.
*/
static int pushDownWhereTerms(
  sqlite3 *db,          /* The database connection (for malloc()) */
  Select *pSubq,        /* The subquery whose WHERE clause is to be augmented */
111398
111399
111400
111401
111402
111403
111404

111405
111406
111407
111408
111409
111410
111411
111597
111598
111599
111600
111601
111602
111603
111604
111605
111606
111607
111608
111609
111610
111611







+







  if( pSubq->pLimit!=0 ){
     return 0; /* restriction (3) */
  }
  while( pWhere->op==TK_AND ){
    nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
    pWhere = pWhere->pLeft;
  }
  if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
  if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
    nChng++;
    while( pSubq ){
      pNew = sqlite3ExprDup(db, pWhere, 0);
      pNew = substExpr(db, pNew, iCursor, pSubq->pEList);
      pSubq->pWhere = sqlite3ExprAnd(db, pSubq->pWhere, pNew);
      pSubq = pSubq->pPrior;
111494
111495
111496
111497
111498
111499
111500
111501

111502
111503

111504
111505
111506
111507
111508
111509
111510
111511
111512
111513
111514

111515
111516
111517
111518
111519
111520
111521
111694
111695
111696
111697
111698
111699
111700

111701
111702

111703
111704
111705
111706
111707
111708
111709
111710
111711
111712
111713

111714
111715
111716
111717
111718
111719
111720
111721







-
+

-
+










-
+







** If the source-list item passed as an argument was augmented with an
** INDEXED BY clause, then try to locate the specified index. If there
** was such a clause and the named index cannot be found, return 
** SQLITE_ERROR and leave an error in pParse. Otherwise, populate 
** pFrom->pIndex and return SQLITE_OK.
*/
SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *pParse, struct SrcList_item *pFrom){
  if( pFrom->pTab && pFrom->zIndexedBy ){
  if( pFrom->pTab && pFrom->fg.isIndexedBy ){
    Table *pTab = pFrom->pTab;
    char *zIndexedBy = pFrom->zIndexedBy;
    char *zIndexedBy = pFrom->u1.zIndexedBy;
    Index *pIdx;
    for(pIdx=pTab->pIndex; 
        pIdx && sqlite3StrICmp(pIdx->zName, zIndexedBy); 
        pIdx=pIdx->pNext
    );
    if( !pIdx ){
      sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
      pParse->checkSchema = 1;
      return SQLITE_ERROR;
    }
    pFrom->pIndex = pIdx;
    pFrom->pIBIndex = pIdx;
  }
  return SQLITE_OK;
}
/*
** Detect compound SELECT statements that use an ORDER BY clause with 
** an alternative collating sequence.
**
111668
111669
111670
111671
111672
111673
111674
111675

111676
111677

111678
111679
111680


111681
111682
111683
111684
111685
111686
111687
111868
111869
111870
111871
111872
111873
111874

111875
111876

111877
111878


111879
111880
111881
111882
111883
111884
111885
111886
111887







-
+

-
+

-
-
+
+







    Table *pTab;
    ExprList *pEList;
    Select *pSel;
    Select *pLeft;                /* Left-most SELECT statement */
    int bMayRecursive;            /* True if compound joined by UNION [ALL] */
    With *pSavedWith;             /* Initial value of pParse->pWith */

    /* If pCte->zErr is non-NULL at this point, then this is an illegal
    /* If pCte->zCteErr is non-NULL at this point, then this is an illegal
    ** recursive reference to CTE pCte. Leave an error in pParse and return
    ** early. If pCte->zErr is NULL, then this is not a recursive reference.
    ** early. If pCte->zCteErr is NULL, then this is not a recursive reference.
    ** In this case, proceed.  */
    if( pCte->zErr ){
      sqlite3ErrorMsg(pParse, pCte->zErr, pCte->zName);
    if( pCte->zCteErr ){
      sqlite3ErrorMsg(pParse, pCte->zCteErr, pCte->zName);
      return SQLITE_ERROR;
    }

    assert( pFrom->pTab==0 );
    pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
    if( pTab==0 ) return WRC_Abort;
    pTab->nRef = 1;
111702
111703
111704
111705
111706
111707
111708
111709

111710
111711
111712
111713
111714
111715
111716
111717
111718
111719
111720
111721
111722
111723
111724
111725

111726
111727
111728
111729
111730
111731
111732
111733
111734
111735
111736
111737
111738
111739
111740
111741
111742
111743

111744
111745
111746

111747
111748

111749
111750
111751
111752

111753
111754
111755
111756
111757
111758
111759
111902
111903
111904
111905
111906
111907
111908

111909
111910
111911
111912
111913
111914
111915
111916
111917
111918
111919
111920
111921
111922
111923
111924

111925
111926
111927
111928
111929
111930
111931
111932
111933
111934
111935
111936
111937
111938
111939
111940
111941
111942

111943
111944
111945

111946
111947

111948
111949
111950
111951

111952
111953
111954
111955
111956
111957
111958
111959







-
+















-
+

















-
+


-
+

-
+



-
+







      for(i=0; i<pSrc->nSrc; i++){
        struct SrcList_item *pItem = &pSrc->a[i];
        if( pItem->zDatabase==0 
         && pItem->zName!=0 
         && 0==sqlite3StrICmp(pItem->zName, pCte->zName)
          ){
          pItem->pTab = pTab;
          pItem->isRecursive = 1;
          pItem->fg.isRecursive = 1;
          pTab->nRef++;
          pSel->selFlags |= SF_Recursive;
        }
      }
    }

    /* Only one recursive reference is permitted. */ 
    if( pTab->nRef>2 ){
      sqlite3ErrorMsg(
          pParse, "multiple references to recursive table: %s", pCte->zName
      );
      return SQLITE_ERROR;
    }
    assert( pTab->nRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nRef==2 ));

    pCte->zErr = "circular reference: %s";
    pCte->zCteErr = "circular reference: %s";
    pSavedWith = pParse->pWith;
    pParse->pWith = pWith;
    sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);

    for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
    pEList = pLeft->pEList;
    if( pCte->pCols ){
      if( pEList && pEList->nExpr!=pCte->pCols->nExpr ){
        sqlite3ErrorMsg(pParse, "table %s has %d values for %d columns",
            pCte->zName, pEList->nExpr, pCte->pCols->nExpr
        );
        pParse->pWith = pSavedWith;
        return SQLITE_ERROR;
      }
      pEList = pCte->pCols;
    }

    selectColumnsFromExprList(pParse, pEList, &pTab->nCol, &pTab->aCol);
    sqlite3ColumnsFromExprList(pParse, pEList, &pTab->nCol, &pTab->aCol);
    if( bMayRecursive ){
      if( pSel->selFlags & SF_Recursive ){
        pCte->zErr = "multiple recursive references: %s";
        pCte->zCteErr = "multiple recursive references: %s";
      }else{
        pCte->zErr = "recursive reference in a subquery: %s";
        pCte->zCteErr = "recursive reference in a subquery: %s";
      }
      sqlite3WalkSelect(pWalker, pSel);
    }
    pCte->zErr = 0;
    pCte->zCteErr = 0;
    pParse->pWith = pSavedWith;
  }

  return SQLITE_OK;
}
#endif

111832
111833
111834
111835
111836
111837
111838
111839
111840


111841
111842
111843
111844
111845
111846
111847
112032
112033
112034
112035
112036
112037
112038


112039
112040
112041
112042
112043
112044
112045
112046
112047







-
-
+
+








  /* Look up every table named in the FROM clause of the select.  If
  ** an entry of the FROM clause is a subquery instead of a table or view,
  ** then create a transient table structure to describe the subquery.
  */
  for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
    Table *pTab;
    assert( pFrom->isRecursive==0 || pFrom->pTab );
    if( pFrom->isRecursive ) continue;
    assert( pFrom->fg.isRecursive==0 || pFrom->pTab );
    if( pFrom->fg.isRecursive ) continue;
    if( pFrom->pTab!=0 ){
      /* This statement has already been prepared.  There is no need
      ** to go further. */
      assert( i==0 );
#ifndef SQLITE_OMIT_CTE
      selectPopWith(pWalker, p);
#endif
111859
111860
111861
111862
111863
111864
111865
111866

111867
111868
111869
111870
111871
111872
111873
112059
112060
112061
112062
112063
112064
112065

112066
112067
112068
112069
112070
112071
112072
112073







-
+







      assert( pFrom->pTab==0 );
      if( sqlite3WalkSelect(pWalker, pSel) ) return WRC_Abort;
      pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
      if( pTab==0 ) return WRC_Abort;
      pTab->nRef = 1;
      pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
      while( pSel->pPrior ){ pSel = pSel->pPrior; }
      selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol);
      sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
      pTab->iPKey = -1;
      pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
      pTab->tabFlags |= TF_Ephemeral;
#endif
    }else{
      /* An ordinary table or view name in the FROM clause */
      assert( pFrom->pTab==0 );
111996
111997
111998
111999
112000
112001
112002
112003

112004
112005
112006
112007
112008
112009
112010
112196
112197
112198
112199
112200
112201
112202

112203
112204
112205
112206
112207
112208
112209
112210







-
+







            if( IsHiddenColumn(&pTab->aCol[j]) ){
              assert(IsVirtual(pTab));
              continue;
            }
            tableSeen = 1;

            if( i>0 && zTName==0 ){
              if( (pFrom->jointype & JT_NATURAL)!=0
              if( (pFrom->fg.jointype & JT_NATURAL)!=0
                && tableAndColumnIndex(pTabList, i, zName, 0, 0)
              ){
                /* In a NATURAL join, omit the join columns from the 
                ** table to the right of the join */
                continue;
              }
              if( sqlite3IdListIndex(pFrom->pUsing, zName)>=0 ){
112282
112283
112284
112285
112286
112287
112288
112289

112290
112291
112292
112293
112294
112295
112296
112482
112483
112484
112485
112486
112487
112488

112489
112490
112491
112492
112493
112494
112495
112496







-
+







    int addrNext = 0;
    int regAgg;
    ExprList *pList = pF->pExpr->x.pList;
    assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
    if( pList ){
      nArg = pList->nExpr;
      regAgg = sqlite3GetTempRange(pParse, nArg);
      sqlite3ExprCodeExprList(pParse, pList, regAgg, SQLITE_ECEL_DUP);
      sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
    }else{
      nArg = 0;
      regAgg = 0;
    }
    if( pF->iDistinct>=0 ){
      addrNext = sqlite3VdbeMakeLabel(v);
      testcase( nArg==0 );  /* Error condition */
112523
112524
112525
112526
112527
112528
112529
112530

112531
112532
112533
112534
112535
112536
112537
112538
112539
112540
112541
112542
112543
112544
112545
112546
112547
112548

112549
112550
112551
112552
112553
112554
112555
112723
112724
112725
112726
112727
112728
112729

112730
112731
112732
112733
112734
112735
112736
112737
112738
112739
112740
112741
112742
112743
112744
112745
112746
112747

112748
112749
112750
112751
112752
112753
112754
112755







-
+

















-
+







    /* Sometimes the code for a subquery will be generated more than
    ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
    ** for example.  In that case, do not regenerate the code to manifest
    ** a view or the co-routine to implement a view.  The first instance
    ** is sufficient, though the subroutine to manifest the view does need
    ** to be invoked again. */
    if( pItem->addrFillSub ){
      if( pItem->viaCoroutine==0 ){
      if( pItem->fg.viaCoroutine==0 ){
        sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
      }
      continue;
    }

    /* Increment Parse.nHeight by the height of the largest expression
    ** tree referred to by this, the parent select. The child select
    ** may contain expression trees of at most
    ** (SQLITE_MAX_EXPR_DEPTH-Parse.nHeight) height. This is a bit
    ** more conservative than necessary, but much easier than enforcing
    ** an exact limit.
    */
    pParse->nHeight += sqlite3SelectExprHeight(p);

    /* Make copies of constant WHERE-clause terms in the outer query down
    ** inside the subquery.  This can help the subquery to run more efficiently.
    */
    if( (pItem->jointype & JT_OUTER)==0
    if( (pItem->fg.jointype & JT_OUTER)==0
     && pushDownWhereTerms(db, pSub, p->pWhere, pItem->iCursor)
    ){
#if SELECTTRACE_ENABLED
      if( sqlite3SelectTrace & 0x100 ){
        SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
        sqlite3TreeViewSelect(0, p, 0);
      }
112570
112571
112572
112573
112574
112575
112576
112577

112578
112579
112580
112581
112582
112583
112584
112585
112586
112587
112588
112589
112590
112591
112592
112593
112594
112595

112596
112597
112598
112599
112600
112601
112602
112770
112771
112772
112773
112774
112775
112776

112777
112778
112779
112780
112781
112782
112783
112784
112785
112786
112787
112788
112789
112790
112791
112792
112793
112794

112795
112796
112797
112798
112799
112800
112801
112802







-
+

















-
+







      sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
      VdbeComment((v, "%s", pItem->pTab->zName));
      pItem->addrFillSub = addrTop;
      sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
      explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
      sqlite3Select(pParse, pSub, &dest);
      pItem->pTab->nRowLogEst = sqlite3LogEst(pSub->nSelectRow);
      pItem->viaCoroutine = 1;
      pItem->fg.viaCoroutine = 1;
      pItem->regResult = dest.iSdst;
      sqlite3VdbeAddOp1(v, OP_EndCoroutine, pItem->regReturn);
      sqlite3VdbeJumpHere(v, addrTop-1);
      sqlite3ClearTempRegCache(pParse);
    }else{
      /* Generate a subroutine that will fill an ephemeral table with
      ** the content of this subquery.  pItem->addrFillSub will point
      ** to the address of the generated subroutine.  pItem->regReturn
      ** is a register allocated to hold the subroutine return address
      */
      int topAddr;
      int onceAddr = 0;
      int retAddr;
      assert( pItem->addrFillSub==0 );
      pItem->regReturn = ++pParse->nMem;
      topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
      pItem->addrFillSub = topAddr+1;
      if( pItem->isCorrelated==0 ){
      if( pItem->fg.isCorrelated==0 ){
        /* If the subquery is not correlated and if we are not inside of
        ** a trigger, then we only need to compute the value of the subquery
        ** once. */
        onceAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
        VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
      }else{
        VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
112686
112687
112688
112689
112690
112691
112692
112693

112694
112695
112696
112697
112698
112699
112700
112886
112887
112888
112889
112890
112891
112892

112893
112894
112895
112896
112897
112898
112899
112900







-
+








  /* Set the limiter.
  */
  iEnd = sqlite3VdbeMakeLabel(v);
  p->nSelectRow = LARGEST_INT64;
  computeLimitRegisters(pParse, p, iEnd);
  if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
    sqlite3VdbeGetOp(v, sSort.addrSortIndex)->opcode = OP_SorterOpen;
    sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
    sSort.sortFlags |= SORTFLAG_UseSorter;
  }

  /* Open an ephemeral index to use for the distinct set.
  */
  if( p->selFlags & SF_Distinct ){
    sDistinct.tabTnct = pParse->nTab++;
112902
112903
112904
112905
112906
112907
112908
112909

112910
112911
112912
112913
112914
112915
112916
113102
113103
113104
113105
113106
113107
113108

113109
113110
113111
113112
113113
113114
113115
113116







-
+







          if( sAggInfo.aCol[i].iSorterColumn>=j ){
            nCol++;
            j++;
          }
        }
        regBase = sqlite3GetTempRange(pParse, nCol);
        sqlite3ExprCacheClear(pParse);
        sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0);
        sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
        j = nGroupBy;
        for(i=0; i<sAggInfo.nColumn; i++){
          struct AggInfo_col *pCol = &sAggInfo.aCol[i];
          if( pCol->iSorterColumn>=j ){
            int r1 = j + regBase;
            int r2;

113014
113015
113016
113017
113018
113019
113020
113021

113022
113023
113024
113025
113026
113027
113028
113214
113215
113216
113217
113218
113219
113220

113221
113222
113223
113224
113225
113226
113227
113228







-
+







      /* Output the final row of result
      */
      sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
      VdbeComment((v, "output final row"));

      /* Jump over the subroutines
      */
      sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEnd);
      sqlite3VdbeGoto(v, addrEnd);

      /* Generate a subroutine that outputs a single row of the result
      ** set.  This subroutine first looks at the iUseFlag.  If iUseFlag
      ** is less than or equal to zero, the subroutine is a no-op.  If
      ** the processing calls for the query to abort, this subroutine
      ** increments the iAbortFlag memory location before returning in
      ** order to signal the caller to abort.
113168
113169
113170
113171
113172
113173
113174
113175

113176
113177
113178
113179
113180
113181
113182
113368
113369
113370
113371
113372
113373
113374

113375
113376
113377
113378
113379
113380
113381
113382







-
+







        if( pWInfo==0 ){
          sqlite3ExprListDelete(db, pDel);
          goto select_end;
        }
        updateAccumulator(pParse, &sAggInfo);
        assert( pMinMax==0 || pMinMax->nExpr==1 );
        if( sqlite3WhereIsOrdered(pWInfo)>0 ){
          sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3WhereBreakLabel(pWInfo));
          sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo));
          VdbeComment((v, "%s() by index",
                (flag==WHERE_ORDERBY_MIN?"min":"max")));
        }
        sqlite3WhereEnd(pWInfo);
        finalizeAggFunctions(pParse, &sAggInfo);
      }

114829
114830
114831
114832
114833
114834
114835
114836



114837
114838
114839
114840
114841
114842
114843
114844
114845


114846
114847
114848
114849
114850
114851
114852
115029
115030
115031
115032
115033
115034
115035

115036
115037
115038
115039
115040
115041
115042
115043
115044
115045
115046

115047
115048
115049
115050
115051
115052
115053
115054
115055







-
+
+
+








-
+
+







  */
  pTabList->a[0].colUsed = 0;

  hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);

  /* There is one entry in the aRegIdx[] array for each index on the table
  ** being updated.  Fill in aRegIdx[] with a register number that will hold
  ** the key for accessing each index.  
  ** the key for accessing each index.
  **
  ** FIXME:  Be smarter about omitting indexes that use expressions.
  */
  for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
    int reg;
    if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
      reg = ++pParse->nMem;
    }else{
      reg = 0;
      for(i=0; i<pIdx->nKeyCol; i++){
        if( aXRef[pIdx->aiColumn[i]]>=0 ){
        i16 iIdxCol = pIdx->aiColumn[i];
        if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
          reg = ++pParse->nMem;
          break;
        }
      }
    }
    if( reg==0 ) aToOpen[j+1] = 0;
    aRegIdx[j] = reg;
114938
114939
114940
114941
114942
114943
114944

114945
114946
114947
114948
114949
114950
114951
114952
114953
114954

114955
114956
114957
114958
114959
114960
114961
115141
115142
115143
115144
115145
115146
115147
115148
115149
115150
115151
115152
115153
115154
115155
115156
115157

115158
115159
115160
115161
115162
115163
115164
115165







+









-
+







    addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
    sqlite3VdbeSetP4KeyInfo(pParse, pPk);
    pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, 
                               WHERE_ONEPASS_DESIRED, iIdxCur);
    if( pWInfo==0 ) goto update_cleanup;
    okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
    for(i=0; i<nPk; i++){
      assert( pPk->aiColumn[i]>=(-1) );
      sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i],
                                      iPk+i);
    }
    if( okOnePass ){
      sqlite3VdbeChangeToNoop(v, addrOpen);
      nKey = nPk;
      regKey = iPk;
    }else{
      sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
                        sqlite3IndexAffinityStr(v, pPk), nPk);
                        sqlite3IndexAffinityStr(db, pPk), nPk);
      sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
    }
    sqlite3WhereEnd(pWInfo);
  }

  /* Initialize the count of updated rows
  */
115184
115185
115186
115187
115188
115189
115190
115191

115192
115193
115194
115195
115196
115197
115198
115388
115389
115390
115391
115392
115393
115394

115395
115396
115397
115398
115399
115400
115401
115402







-
+







  */
  if( okOnePass ){
    /* Nothing to do at end-of-loop for a single-pass */
  }else if( pPk ){
    sqlite3VdbeResolveLabel(v, labelContinue);
    sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
  }else{
    sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
    sqlite3VdbeGoto(v, labelContinue);
  }
  sqlite3VdbeResolveLabel(v, labelBreak);

  /* Close all tables */
  for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
    assert( aRegIdx );
    if( aToOpen[i+1] ){
115766
115767
115768
115769
115770
115771
115772

115773
115774
115775
115776
115777
115778
115779
115970
115971
115972
115973
115974
115975
115976
115977
115978
115979
115980
115981
115982
115983
115984







+







      Module *pDel;
      char *zCopy = (char *)(&pMod[1]);
      memcpy(zCopy, zName, nName+1);
      pMod->zName = zCopy;
      pMod->pModule = pModule;
      pMod->pAux = pAux;
      pMod->xDestroy = xDestroy;
      pMod->pEpoTab = 0;
      pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
      assert( pDel==0 || pDel==pMod );
      if( pDel ){
        db->mallocFailed = 1;
        sqlite3DbFree(db, pDel);
      }
    }
115993
115994
115995
115996
115997
115998
115999
116000
116001

116002
116003
116004
116005
116006
116007
116008
116009
116010
116011
116012

116013
116014
116015
116016


116017
116018
116019
116020
116021
116022
116023
116198
116199
116200
116201
116202
116203
116204


116205
116206
116207
116208




116209


116210
116211
116212
116213


116214
116215
116216
116217
116218
116219
116220
116221
116222







-
-
+



-
-
-
-

-
-

+


-
-
+
+







/*
** Add a new module argument to pTable->azModuleArg[].
** The string is not copied - the pointer is stored.  The
** string will be freed automatically when the table is
** deleted.
*/
static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
  int i = pTable->nModuleArg++;
  int nBytes = sizeof(char *)*(1+pTable->nModuleArg);
  int nBytes = sizeof(char *)*(2+pTable->nModuleArg);
  char **azModuleArg;
  azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
  if( azModuleArg==0 ){
    int j;
    for(j=0; j<i; j++){
      sqlite3DbFree(db, pTable->azModuleArg[j]);
    }
    sqlite3DbFree(db, zArg);
    sqlite3DbFree(db, pTable->azModuleArg);
    pTable->nModuleArg = 0;
  }else{
    int i = pTable->nModuleArg++;
    azModuleArg[i] = zArg;
    azModuleArg[i+1] = 0;
  }
  pTable->azModuleArg = azModuleArg;
    pTable->azModuleArg = azModuleArg;
  }
}

/*
** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
** statement.  The module name has been parsed, but the optional list
** of parameters that follow the module name are still pending.
*/
116136
116137
116138
116139
116140
116141
116142
116143

116144
116145
116146
116147
116148
116149
116150
116335
116336
116337
116338
116339
116340
116341

116342
116343
116344
116345
116346
116347
116348
116349







-
+







    sqlite3ChangeCookie(pParse, iDb);

    sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
    zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
    sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);

    iReg = ++pParse->nMem;
    sqlite3VdbeAddOp4(v, OP_String8, 0, iReg, 0, pTab->zName, 0);
    sqlite3VdbeLoadString(v, iReg, pTab->zName);
    sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
  }

  /* If we are rereading the sqlite_master table create the in-memory
  ** record of the table. The xConnect() method is not called until
  ** the first time the virtual table is used in an SQL statement. This
  ** allows a schema that contains virtual tables to be loaded before
116412
116413
116414
116415
116416
116417
116418
116419

116420
116421
116422
116423
116424
116425
116426
116611
116612
116613
116614
116615
116616
116617

116618
116619
116620
116621
116622
116623
116624
116625







-
+







  zMod = pTab->azModuleArg[0];
  pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);

  /* If the module has been registered and includes a Create method, 
  ** invoke it now. If the module has not been registered, return an 
  ** error. Otherwise, do nothing.
  */
  if( !pMod ){
  if( pMod==0 || pMod->pModule->xCreate==0 || pMod->pModule->xDestroy==0 ){
    *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
    rc = SQLITE_ERROR;
  }else{
    rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
  }

  /* Justification of ALWAYS():  The xConstructor method is required to
116514
116515
116516
116517
116518
116519
116520

116521
116522
116523
116524
116525
116526
116527
116528



116529
116530
116531
116532
116533
116534
116535
116713
116714
116715
116716
116717
116718
116719
116720
116721
116722
116723
116724
116725
116726
116727

116728
116729
116730
116731
116732
116733
116734
116735
116736
116737







+







-
+
+
+







SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
  int rc = SQLITE_OK;
  Table *pTab;

  pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
  if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){
    VTable *p;
    int (*xDestroy)(sqlite3_vtab *);
    for(p=pTab->pVTable; p; p=p->pNext){
      assert( p->pVtab );
      if( p->pVtab->nRef>0 ){
        return SQLITE_LOCKED;
      }
    }
    p = vtabDisconnectAll(db, pTab);
    rc = p->pMod->pModule->xDestroy(p->pVtab);
    xDestroy = p->pMod->pModule->xDestroy;
    assert( xDestroy!=0 );  /* Checked before the virtual table is created */
    rc = xDestroy(p->pVtab);
    /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
    if( rc==SQLITE_OK ){
      assert( pTab->pVTable==p && p->pNext==0 );
      p->pVtab = 0;
      pTab->pVTable = 0;
      sqlite3VtabUnlock(p);
    }
116799
116800
116801
116802
116803
116804
116805





























































116806
116807
116808
116809
116810
116811
116812
117001
117002
117003
117004
117005
117006
117007
117008
117009
117010
117011
117012
117013
117014
117015
117016
117017
117018
117019
117020
117021
117022
117023
117024
117025
117026
117027
117028
117029
117030
117031
117032
117033
117034
117035
117036
117037
117038
117039
117040
117041
117042
117043
117044
117045
117046
117047
117048
117049
117050
117051
117052
117053
117054
117055
117056
117057
117058
117059
117060
117061
117062
117063
117064
117065
117066
117067
117068
117069
117070
117071
117072
117073
117074
117075







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  if( apVtabLock ){
    pToplevel->apVtabLock = apVtabLock;
    pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
  }else{
    pToplevel->db->mallocFailed = 1;
  }
}

/*
** Check to see if virtual tale module pMod can be have an eponymous
** virtual table instance.  If it can, create one if one does not already
** exist. Return non-zero if the eponymous virtual table instance exists
** when this routine returns, and return zero if it does not exist.
**
** An eponymous virtual table instance is one that is named after its
** module, and more importantly, does not require a CREATE VIRTUAL TABLE
** statement in order to come into existance.  Eponymous virtual table
** instances always exist.  They cannot be DROP-ed.
**
** Any virtual table module for which xConnect and xCreate are the same
** method can have an eponymous virtual table instance.
*/
SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse *pParse, Module *pMod){
  const sqlite3_module *pModule = pMod->pModule;
  Table *pTab;
  char *zErr = 0;
  int nName;
  int rc;
  sqlite3 *db = pParse->db;
  if( pMod->pEpoTab ) return 1;
  if( pModule->xCreate!=0 && pModule->xCreate!=pModule->xConnect ) return 0;
  nName = sqlite3Strlen30(pMod->zName) + 1;
  pTab = sqlite3DbMallocZero(db, sizeof(Table) + nName);
  if( pTab==0 ) return 0;
  pMod->pEpoTab = pTab;
  pTab->zName = (char*)&pTab[1];
  memcpy(pTab->zName, pMod->zName, nName);
  pTab->nRef = 1;
  pTab->pSchema = db->aDb[0].pSchema;
  pTab->tabFlags |= TF_Virtual;
  pTab->nModuleArg = 0;
  pTab->iPKey = -1;
  addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
  addModuleArgument(db, pTab, 0);
  addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
  rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
  if( rc ){
    sqlite3ErrorMsg(pParse, "%s", zErr);
    sqlite3DbFree(db, zErr);
    sqlite3VtabEponymousTableClear(db, pMod);
    return 0;
  }
  return 1;
}

/*
** Erase the eponymous virtual table instance associated with
** virtual table module pMod, if it exists.
*/
SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3 *db, Module *pMod){
  Table *pTab = pMod->pEpoTab;
  if( (pTab = pMod->pEpoTab)!=0 ){
    sqlite3DeleteColumnNames(db, pTab);
    sqlite3VtabClear(db, pTab);
    sqlite3DbFree(db, pTab);
    pMod->pEpoTab = 0;
  }
}

/*
** Return the ON CONFLICT resolution mode in effect for the virtual
** table update operation currently in progress.
**
** The results of this routine are undefined unless it is called from
** within an xUpdate method.
117170
117171
117172
117173
117174
117175
117176

117177
117178
117179
117180
117181
117182


117183
117184
117185
117186
117187
117188
117189
117433
117434
117435
117436
117437
117438
117439
117440
117441
117442
117443
117444
117445

117446
117447
117448
117449
117450
117451
117452
117453
117454







+





-
+
+







** An instance of the WhereScan object is used as an iterator for locating
** terms in the WHERE clause that are useful to the query planner.
*/
struct WhereScan {
  WhereClause *pOrigWC;      /* Original, innermost WhereClause */
  WhereClause *pWC;          /* WhereClause currently being scanned */
  char *zCollName;           /* Required collating sequence, if not NULL */
  Expr *pIdxExpr;            /* Search for this index expression */
  char idxaff;               /* Must match this affinity, if zCollName!=NULL */
  unsigned char nEquiv;      /* Number of entries in aEquiv[] */
  unsigned char iEquiv;      /* Next unused slot in aEquiv[] */
  u32 opMask;                /* Acceptable operators */
  int k;                     /* Resume scanning at this->pWC->a[this->k] */
  int aEquiv[22];            /* Cursor,Column pairs for equivalence classes */
  int aiCur[11];             /* Cursors in the equivalence class */
  i16 aiColumn[11];          /* Corresponding column number in the eq-class */
};

/*
** An instance of the following structure holds all information about a
** WHERE clause.  Mostly this is a container for one or more WhereTerms.
**
** Explanation of pOuter:  For a WHERE clause of the form
117359
117360
117361
117362
117363
117364
117365

117366
117367
117368
117369
117370
117371
117372
117624
117625
117626
117627
117628
117629
117630
117631
117632
117633
117634
117635
117636
117637
117638







+







/* whereexpr.c: */
SQLITE_PRIVATE void sqlite3WhereClauseInit(WhereClause*,WhereInfo*);
SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause*);
SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause*,Expr*,u8);
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, struct SrcList_item*, WhereClause*);





/*
** Bitmasks for the operators on WhereTerm objects.  These are all
117435
117436
117437
117438
117439
117440
117441










117442
117443
117444
117445
117446
117447
117448
117449
117450
117451
117452
117453
117454
117455
117456
117457
117458
117459
117460
117461
117462
117463
117464
117465
117466
117467
117468

117469
117470
117471
117472
117473


117474
117475
117476
117477
117478
117479

117480
117481
117482
117483

117484
117485
117486
117487
117488
117489
117490
117701
117702
117703
117704
117705
117706
117707
117708
117709
117710
117711
117712
117713
117714
117715
117716
117717
117718
117719
117720
117721
117722
117723
117724
117725
117726
117727
117728
117729
117730
117731
117732
117733
117734
117735
117736
117737


117738
117739
117740
117741

117742





117743
117744

117745
117746
117747
117748

117749
117750
117751
117752

117753
117754
117755
117756
117757
117758
117759
117760







+
+
+
+
+
+
+
+
+
+




















-
-




-
+
-
-
-
-
-
+
+
-




-
+



-
+







  const char *zOp             /* Name of the operator */
){
  if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
  sqlite3StrAccumAppendAll(pStr, zColumn);
  sqlite3StrAccumAppend(pStr, zOp, 1);
  sqlite3StrAccumAppend(pStr, "?", 1);
}

/*
** Return the name of the i-th column of the pIdx index.
*/
static const char *explainIndexColumnName(Index *pIdx, int i){
  i = pIdx->aiColumn[i];
  if( i==(-2) ) return "<expr>";
  if( i==(-1) ) return "rowid";
  return pIdx->pTable->aCol[i].zName;
}

/*
** Argument pLevel describes a strategy for scanning table pTab. This 
** function appends text to pStr that describes the subset of table
** rows scanned by the strategy in the form of an SQL expression.
**
** For example, if the query:
**
**   SELECT * FROM t1 WHERE a=1 AND b>2;
**
** is run and there is an index on (a, b), then this function returns a
** string similar to:
**
**   "a=? AND b>?"
*/
static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
  Index *pIndex = pLoop->u.btree.pIndex;
  u16 nEq = pLoop->u.btree.nEq;
  u16 nSkip = pLoop->nSkip;
  int i, j;
  Column *aCol = pTab->aCol;
  i16 *aiColumn = pIndex->aiColumn;

  if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
  sqlite3StrAccumAppend(pStr, " (", 2);
  for(i=0; i<nEq; i++){
    char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName;
    const char *z = explainIndexColumnName(pIndex, i);
    if( i>=nSkip ){
      explainAppendTerm(pStr, i, z, "=");
    }else{
      if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
      sqlite3XPrintf(pStr, 0, "ANY(%s)", z);
    if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
    sqlite3XPrintf(pStr, 0, i>=nSkip ? "%s=?" : "ANY(%s)", z);
    }
  }

  j = i;
  if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
    char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
    const char *z = explainIndexColumnName(pIndex, i);
    explainAppendTerm(pStr, i++, z, ">");
  }
  if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
    char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
    const char *z = explainIndexColumnName(pIndex, j);
    explainAppendTerm(pStr, i, z, "<");
  }
  sqlite3StrAccumAppend(pStr, ")", 1);
}

/*
** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
117560
117561
117562
117563
117564
117565
117566
117567

117568
117569

117570
117571

117572
117573

117574
117575
117576

117577
117578

117579
117580
117581
117582
117583
117584
117585
117586
117830
117831
117832
117833
117834
117835
117836

117837
117838

117839
117840

117841
117842

117843
117844
117845

117846
117847

117848

117849
117850
117851
117852
117853
117854
117855







-
+

-
+

-
+

-
+


-
+

-
+
-







      }
      if( zFmt ){
        sqlite3StrAccumAppend(&str, " USING ", 7);
        sqlite3XPrintf(&str, 0, zFmt, pIdx->zName);
        explainIndexRange(&str, pLoop, pItem->pTab);
      }
    }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
      const char *zRange;
      const char *zRangeOp;
      if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
        zRange = "(rowid=?)";
        zRangeOp = "=";
      }else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
        zRange = "(rowid>? AND rowid<?)";
        zRangeOp = ">? AND rowid<";
      }else if( flags&WHERE_BTM_LIMIT ){
        zRange = "(rowid>?)";
        zRangeOp = ">";
      }else{
        assert( flags&WHERE_TOP_LIMIT);
        zRange = "(rowid<?)";
        zRangeOp = "<";
      }
      sqlite3StrAccumAppendAll(&str, " USING INTEGER PRIMARY KEY ");
      sqlite3XPrintf(&str, 0, " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp);
      sqlite3StrAccumAppendAll(&str, zRange);
    }
#ifndef SQLITE_OMIT_VIRTUALTABLE
    else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
      sqlite3XPrintf(&str, 0, " VIRTUAL TABLE INDEX %d:%s",
                  pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
    }
#endif
117887
117888
117889
117890
117891
117892
117893
117894

117895
117896
117897
117898
117899
117900
117901
118156
118157
118158
118159
118160
118161
118162

118163
118164
118165
118166
118167
118168
118169
118170







-
+








  /* Figure out how many memory cells we will need then allocate them.
  */
  regBase = pParse->nMem + 1;
  nReg = pLoop->u.btree.nEq + nExtraReg;
  pParse->nMem += nReg;

  zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
  zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
  if( !zAff ){
    pParse->db->mallocFailed = 1;
  }

  if( nSkip ){
    int iIdxCur = pLevel->iIdxCur;
    sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
118041
118042
118043
118044
118045
118046
118047
118048

118049
118050
118051
118052
118053
118054
118055

118056
118057
118058
118059
118060
118061
118062
118310
118311
118312
118313
118314
118315
118316

118317
118318
118319
118320
118321
118322
118323

118324
118325
118326
118327
118328
118329
118330
118331







-
+






-
+







  addrBrk = pLevel->addrBrk = pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
  addrCont = pLevel->addrCont = sqlite3VdbeMakeLabel(v);

  /* If this is the right table of a LEFT OUTER JOIN, allocate and
  ** initialize a memory cell that records if this table matches any
  ** row of the left table of the join.
  */
  if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
  if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
    pLevel->iLeftJoin = ++pParse->nMem;
    sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
    VdbeComment((v, "init LEFT JOIN no-match flag"));
  }

  /* Special case of a FROM clause subquery implemented as a co-routine */
  if( pTabItem->viaCoroutine ){
  if( pTabItem->fg.viaCoroutine ){
    int regYield = pTabItem->regReturn;
    sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
    pLevel->p2 =  sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
    VdbeCoverage(v);
    VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
    pLevel->op = OP_Goto;
  }else
118775
118776
118777
118778
118779
118780
118781
118782

118783
118784
118785
118786
118787
118788
118789
118790
118791
118792
118793
118794
118795
118796
118797

118798
118799
118800
118801
118802
118803
118804
119044
119045
119046
119047
119048
119049
119050

119051
119052
119053
119054
119055
119056
119057
119058
119059
119060
119061
119062
119063
119064
119065

119066
119067
119068
119069
119070
119071
119072
119073







-
+














-
+







    pLevel->u.pCovidx = pCov;
    if( pCov ) pLevel->iIdxCur = iCovCur;
    if( pAndExpr ){
      pAndExpr->pLeft = 0;
      sqlite3ExprDelete(db, pAndExpr);
    }
    sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
    sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk);
    sqlite3VdbeGoto(v, pLevel->addrBrk);
    sqlite3VdbeResolveLabel(v, iLoopBody);

    if( pWInfo->nLevel>1 ) sqlite3StackFree(db, pOrTab);
    if( !untestedTerms ) disableTerm(pLevel, pTerm);
  }else
#endif /* SQLITE_OMIT_OR_OPTIMIZATION */

  {
    /* Case 6:  There is no usable index.  We must do a complete
    **          scan of the entire table.
    */
    static const u8 aStep[] = { OP_Next, OP_Prev };
    static const u8 aStart[] = { OP_Rewind, OP_Last };
    assert( bRev==0 || bRev==1 );
    if( pTabItem->isRecursive ){
    if( pTabItem->fg.isRecursive ){
      /* Tables marked isRecursive have only a single row that is stored in
      ** a pseudo-cursor.  No need to Rewind or Next such cursors. */
      pLevel->op = OP_Noop;
    }else{
      pLevel->op = aStep[bRev];
      pLevel->p1 = iCur;
      pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
119697
119698
119699
119700
119701
119702
119703













































119704
119705
119706
119707
119708
119709
119710
119966
119967
119968
119969
119970
119971
119972
119973
119974
119975
119976
119977
119978
119979
119980
119981
119982
119983
119984
119985
119986
119987
119988
119989
119990
119991
119992
119993
119994
119995
119996
119997
119998
119999
120000
120001
120002
120003
120004
120005
120006
120007
120008
120009
120010
120011
120012
120013
120014
120015
120016
120017
120018
120019
120020
120021
120022
120023
120024







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







        mask |= sqlite3WhereExprUsage(pMaskSet, pSrc->a[i].pOn);
      }
    }
    pS = pS->pPrior;
  }
  return mask;
}

/*
** Expression pExpr is one operand of a comparison operator that might
** be useful for indexing.  This routine checks to see if pExpr appears
** in any index.  Return TRUE (1) if pExpr is an indexed term and return
** FALSE (0) if not.  If TRUE is returned, also set *piCur to the cursor
** number of the table that is indexed and *piColumn to the column number
** of the column that is indexed, or -2 if an expression is being indexed.
**
** If pExpr is a TK_COLUMN column reference, then this routine always returns
** true even if that particular column is not indexed, because the column
** might be added to an automatic index later.
*/
static int exprMightBeIndexed(
  SrcList *pFrom,        /* The FROM clause */
  Bitmask mPrereq,       /* Bitmask of FROM clause terms referenced by pExpr */
  Expr *pExpr,           /* An operand of a comparison operator */
  int *piCur,            /* Write the referenced table cursor number here */
  int *piColumn          /* Write the referenced table column number here */
){
  Index *pIdx;
  int i;
  int iCur;
  if( pExpr->op==TK_COLUMN ){
    *piCur = pExpr->iTable;
    *piColumn = pExpr->iColumn;
    return 1;
  }
  if( mPrereq==0 ) return 0;                 /* No table references */
  if( (mPrereq&(mPrereq-1))!=0 ) return 0;   /* Refs more than one table */
  for(i=0; mPrereq>1; i++, mPrereq>>=1){}
  iCur = pFrom->a[i].iCursor;
  for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
    if( pIdx->aColExpr==0 ) continue;
    for(i=0; i<pIdx->nKeyCol; i++){
      if( pIdx->aiColumn[i]!=(-2) ) continue;
      if( sqlite3ExprCompare(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
        *piCur = iCur;
        *piColumn = -2;
        return 1;
      }
    }
  }
  return 0;
}

/*
** The input to this routine is an WhereTerm structure with only the
** "pExpr" field filled in.  The job of this routine is to analyze the
** subexpression and populate all the other fields of the WhereTerm
** structure.
**
119768
119769
119770
119771
119772
119773
119774

119775
119776
119777
119778
119779
119780



119781
119782
119783
119784



119785
119786
119787
119788
119789
119790
119791
120082
120083
120084
120085
120086
120087
120088
120089
120090
120091
120092



120093
120094
120095
120096
120097
120098

120099
120100
120101
120102
120103
120104
120105
120106
120107
120108







+



-
-
-
+
+
+



-
+
+
+







                       ** on left table of a LEFT JOIN.  Ticket #3015 */
  }
  pTerm->prereqAll = prereqAll;
  pTerm->leftCursor = -1;
  pTerm->iParent = -1;
  pTerm->eOperator = 0;
  if( allowedOp(op) ){
    int iCur, iColumn;
    Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
    Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
    u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
    if( pLeft->op==TK_COLUMN ){
      pTerm->leftCursor = pLeft->iTable;
      pTerm->u.leftColumn = pLeft->iColumn;
    if( exprMightBeIndexed(pSrc, prereqLeft, pLeft, &iCur, &iColumn) ){
      pTerm->leftCursor = iCur;
      pTerm->u.leftColumn = iColumn;
      pTerm->eOperator = operatorMask(op) & opMask;
    }
    if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
    if( pRight && pRight->op==TK_COLUMN ){
    if( pRight 
     && exprMightBeIndexed(pSrc, pTerm->prereqRight, pRight, &iCur, &iColumn)
    ){
      WhereTerm *pNew;
      Expr *pDup;
      u16 eExtraOp = 0;        /* Extra bits for pNew->eOperator */
      if( pTerm->leftCursor>=0 ){
        int idxNew;
        pDup = sqlite3ExprDup(db, pExpr, 0);
        if( db->mallocFailed ){
119806
119807
119808
119809
119810
119811
119812
119813
119814


119815
119816
119817
119818
119819
119820
119821
120123
120124
120125
120126
120127
120128
120129


120130
120131
120132
120133
120134
120135
120136
120137
120138







-
-
+
+







        }
      }else{
        pDup = pExpr;
        pNew = pTerm;
      }
      exprCommute(pParse, pDup);
      pLeft = sqlite3ExprSkipCollate(pDup->pLeft);
      pNew->leftCursor = pLeft->iTable;
      pNew->u.leftColumn = pLeft->iColumn;
      pNew->leftCursor = iCur;
      pNew->u.leftColumn = iColumn;
      testcase( (prereqLeft | extraRight) != prereqLeft );
      pNew->prereqRight = prereqLeft | extraRight;
      pNew->prereqAll = prereqAll;
      pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
    }
  }

120150
120151
120152
120153
120154
120155
120156








































120157
120158
120159
120160
120161
120162
120163
120467
120468
120469
120470
120471
120472
120473
120474
120475
120476
120477
120478
120479
120480
120481
120482
120483
120484
120485
120486
120487
120488
120489
120490
120491
120492
120493
120494
120495
120496
120497
120498
120499
120500
120501
120502
120503
120504
120505
120506
120507
120508
120509
120510
120511
120512
120513
120514
120515
120516
120517
120518
120519
120520







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  WhereClause *pWC         /* the WHERE clause to be analyzed */
){
  int i;
  for(i=pWC->nTerm-1; i>=0; i--){
    exprAnalyze(pTabList, pWC, i);
  }
}

/*
** For table-valued-functions, transform the function arguments into
** new WHERE clause terms.  
**
** Each function argument translates into an equality constraint against
** a HIDDEN column in the table.
*/
SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(
  Parse *pParse,                    /* Parsing context */
  struct SrcList_item *pItem,       /* The FROM clause term to process */
  WhereClause *pWC                  /* Xfer function arguments to here */
){
  Table *pTab;
  int j, k;
  ExprList *pArgs;
  Expr *pColRef;
  Expr *pTerm;
  if( pItem->fg.isTabFunc==0 ) return;
  pTab = pItem->pTab;
  assert( pTab!=0 );
  pArgs = pItem->u1.pFuncArg;
  assert( pArgs!=0 );
  for(j=k=0; j<pArgs->nExpr; j++){
    while( k<pTab->nCol && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN)==0 ){ k++; }
    if( k>=pTab->nCol ){
      sqlite3ErrorMsg(pParse, "too many arguments on %s() - max %d",
                      pTab->zName, j);
      return;
    }
    pColRef = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
    if( pColRef==0 ) return;
    pColRef->iTable = pItem->iCursor;
    pColRef->iColumn = k++;
    pColRef->pTab = pTab;
    pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef,
                         sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
    whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
  }
}

/************** End of whereexpr.c *******************************************/
/************** Begin file where.c *******************************************/
/*
** 2001 September 15
**
** The author disclaims copyright to this source code.  In place of
120326
120327
120328
120329
120330
120331
120332
120333

120334
120335
120336
120337
120338
120339
120340
120341



120342
120343
120344
120345


120346

120347
120348
120349

120350
120351
120352
120353
120354
120355
120356



120357
120358
120359
120360
120361
120362
120363



120364
120365
120366
120367
120368
120369
120370
120683
120684
120685
120686
120687
120688
120689

120690
120691
120692
120693
120694
120695
120696


120697
120698
120699
120700
120701
120702
120703
120704
120705

120706
120707
120708

120709
120710
120711
120712
120713



120714
120715
120716
120717
120718
120719
120720



120721
120722
120723
120724
120725
120726
120727
120728
120729
120730







-
+






-
-
+
+
+




+
+
-
+


-
+




-
-
-
+
+
+




-
-
-
+
+
+







/*
** Advance to the next WhereTerm that matches according to the criteria
** established when the pScan object was initialized by whereScanInit().
** Return NULL if there are no more matching WhereTerms.
*/
static WhereTerm *whereScanNext(WhereScan *pScan){
  int iCur;            /* The cursor on the LHS of the term */
  int iColumn;         /* The column on the LHS of the term.  -1 for IPK */
  i16 iColumn;         /* The column on the LHS of the term.  -1 for IPK */
  Expr *pX;            /* An expression being tested */
  WhereClause *pWC;    /* Shorthand for pScan->pWC */
  WhereTerm *pTerm;    /* The term being tested */
  int k = pScan->k;    /* Where to start scanning */

  while( pScan->iEquiv<=pScan->nEquiv ){
    iCur = pScan->aEquiv[pScan->iEquiv-2];
    iColumn = pScan->aEquiv[pScan->iEquiv-1];
    iCur = pScan->aiCur[pScan->iEquiv-1];
    iColumn = pScan->aiColumn[pScan->iEquiv-1];
    assert( iColumn!=(-2) || pScan->pIdxExpr!=0 );
    while( (pWC = pScan->pWC)!=0 ){
      for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
        if( pTerm->leftCursor==iCur
         && pTerm->u.leftColumn==iColumn
         && (iColumn!=(-2)
               || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0)
         && (pScan->iEquiv<=2 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
         && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
        ){
          if( (pTerm->eOperator & WO_EQUIV)!=0
           && pScan->nEquiv<ArraySize(pScan->aEquiv)
           && pScan->nEquiv<ArraySize(pScan->aiCur)
          ){
            int j;
            pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
            assert( pX->op==TK_COLUMN );
            for(j=0; j<pScan->nEquiv; j+=2){
              if( pScan->aEquiv[j]==pX->iTable
               && pScan->aEquiv[j+1]==pX->iColumn ){
            for(j=0; j<pScan->nEquiv; j++){
              if( pScan->aiCur[j]==pX->iTable
               && pScan->aiColumn[j]==pX->iColumn ){
                  break;
              }
            }
            if( j==pScan->nEquiv ){
              pScan->aEquiv[j] = pX->iTable;
              pScan->aEquiv[j+1] = pX->iColumn;
              pScan->nEquiv += 2;
              pScan->aiCur[j] = pX->iTable;
              pScan->aiColumn[j] = pX->iColumn;
              pScan->nEquiv++;
            }
          }
          if( (pTerm->eOperator & pScan->opMask)!=0 ){
            /* Verify the affinity and collating sequence match */
            if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){
              CollSeq *pColl;
              Parse *pParse = pWC->pWInfo->pParse;
120378
120379
120380
120381
120382
120383
120384
120385
120386


120387
120388
120389
120390
120391
120392
120393
120394
120395
120396
120397
120398
120399
120400
120401

120402
120403
120404
120405
120406
120407
120408
120738
120739
120740
120741
120742
120743
120744


120745
120746
120747
120748
120749
120750
120751
120752
120753
120754
120755
120756
120757
120758
120759
120760

120761
120762
120763
120764
120765
120766
120767
120768







-
-
+
+














-
+







              if( pColl==0 ) pColl = pParse->db->pDfltColl;
              if( sqlite3StrICmp(pColl->zName, pScan->zCollName) ){
                continue;
              }
            }
            if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0
             && (pX = pTerm->pExpr->pRight)->op==TK_COLUMN
             && pX->iTable==pScan->aEquiv[0]
             && pX->iColumn==pScan->aEquiv[1]
             && pX->iTable==pScan->aiCur[0]
             && pX->iColumn==pScan->aiColumn[0]
            ){
              testcase( pTerm->eOperator & WO_IS );
              continue;
            }
            pScan->k = k+1;
            return pTerm;
          }
        }
      }
      pScan->pWC = pScan->pWC->pOuter;
      k = 0;
    }
    pScan->pWC = pScan->pOrigWC;
    k = 0;
    pScan->iEquiv += 2;
    pScan->iEquiv++;
  }
  return 0;
}

/*
** Initialize a WHERE clause scanner object.  Return a pointer to the
** first match.  Return NULL if there are no matches.
120423
120424
120425
120426
120427
120428
120429
120430

120431
120432
120433
120434

120435
120436
120437
120438
120439







120440
120441
120442
120443
120444
120445
120446
120447
120448
120449
120450




120451
120452
120453
120454
120455
120456
120457
120458



120459
120460
120461
120462
120463

120464
120465
120466
120467
120468



120469
120470
120471
120472
120473
120474
120475
120783
120784
120785
120786
120787
120788
120789

120790
120791
120792
120793
120794
120795





120796
120797
120798
120799
120800
120801
120802
120803
120804
120805
120806
120807
120808
120809




120810
120811
120812
120813
120814
120815
120816
120817
120818
120819
120820
120821
120822
120823
120824
120825
120826
120827
120828

120829





120830
120831
120832
120833
120834
120835
120836
120837
120838
120839







-
+




+
-
-
-
-
-
+
+
+
+
+
+
+







-
-
-
-
+
+
+
+








+
+
+




-
+
-
-
-
-
-
+
+
+







  WhereScan *pScan,       /* The WhereScan object being initialized */
  WhereClause *pWC,       /* The WHERE clause to be scanned */
  int iCur,               /* Cursor to scan for */
  int iColumn,            /* Column to scan for */
  u32 opMask,             /* Operator(s) to scan for */
  Index *pIdx             /* Must be compatible with this index */
){
  int j;
  int j = 0;

  /* memset(pScan, 0, sizeof(*pScan)); */
  pScan->pOrigWC = pWC;
  pScan->pWC = pWC;
  pScan->pIdxExpr = 0;
  if( pIdx && iColumn>=0 ){
    pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
    for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
      if( NEVER(j>pIdx->nColumn) ) return 0;
    }
  if( pIdx ){
    j = iColumn;
    iColumn = pIdx->aiColumn[j];
    if( iColumn==(-2) ) pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
  }
  if( pIdx && iColumn>=0 ){
    pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
    pScan->zCollName = pIdx->azColl[j];
  }else{
    pScan->idxaff = 0;
    pScan->zCollName = 0;
  }
  pScan->opMask = opMask;
  pScan->k = 0;
  pScan->aEquiv[0] = iCur;
  pScan->aEquiv[1] = iColumn;
  pScan->nEquiv = 2;
  pScan->iEquiv = 2;
  pScan->aiCur[0] = iCur;
  pScan->aiColumn[0] = iColumn;
  pScan->nEquiv = 1;
  pScan->iEquiv = 1;
  return whereScanNext(pScan);
}

/*
** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
** where X is a reference to the iColumn of table iCur and <op> is one of
** the WO_xx operator codes specified by the op parameter.
** Return a pointer to the term.  Return 0 if not found.
**
** If pIdx!=0 then search for terms matching the iColumn-th column of pIdx
** rather than the iColumn-th column of table iCur.
**
** The term returned might by Y=<expr> if there is another constraint in
** the WHERE clause that specifies that X=Y.  Any such constraints will be
** identified by the WO_EQUIV bit in the pTerm->eOperator field.  The
** aEquiv[] array holds X and all its equivalents, with each SQL variable
** aiCur[]/iaColumn[] arrays hold X and all its equivalents. There are 11
** taking up two slots in aEquiv[].  The first slot is for the cursor number
** and the second is for the column number.  There are 22 slots in aEquiv[]
** so that means we can look for X plus up to 10 other equivalent values.
** Hence a search for X will return <expr> if X=A1 and A1=A2 and A2=A3
** and ... and A9=A10 and A10=<expr>.
** slots in aiCur[]/aiColumn[] so that means we can look for X plus up to 10
** other equivalent values.  Hence a search for X will return <expr> if X=A1
** and A1=A2 and A2=A3 and ... and A9=A10 and A10=<expr>.
**
** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"
** then try for the one with no dependencies on <expr> - in other words where
** <expr> is a constant expression of some kind.  Only return entries of
** the form "X <op> Y" where Y is a column in another table if no terms of
** the form "X <op> <const-expr>" exist.   If no terms with a constant RHS
** exist, try to return a term that does not use WO_EQUIV.
120529
120530
120531
120532
120533
120534
120535



















120536
120537
120538
120539
120540
120541
120542
120893
120894
120895
120896
120897
120898
120899
120900
120901
120902
120903
120904
120905
120906
120907
120908
120909
120910
120911
120912
120913
120914
120915
120916
120917
120918
120919
120920
120921
120922
120923
120924
120925







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







        return i;
      }
    }
  }

  return -1;
}

/*
** Return TRUE if the iCol-th column of index pIdx is NOT NULL
*/
static int indexColumnNotNull(Index *pIdx, int iCol){
  int j;
  assert( pIdx!=0 );
  assert( iCol>=0 && iCol<pIdx->nColumn );
  j = pIdx->aiColumn[iCol];
  if( j>=0 ){
    return pIdx->pTable->aCol[j].notNull;
  }else if( j==(-1) ){
    return 1;
  }else{
    assert( j==(-2) );
    return 0;  /* Assume an indexed expression can always yield a NULL */

  }
}

/*
** Return true if the DISTINCT expression-list passed as the third argument
** is redundant.
**
** A DISTINCT list is redundant if any subset of the columns in the
** DISTINCT list are collectively unique and individually non-null.
120580
120581
120582
120583
120584
120585
120586
120587
120588
120589


120590
120591

120592
120593
120594
120595
120596
120597
120598
120599
120963
120964
120965
120966
120967
120968
120969



120970
120971


120972

120973
120974
120975
120976
120977
120978
120979







-
-
-
+
+
-
-
+
-







  **
  **   3. All of those index columns for which the WHERE clause does not
  **      contain a "col=X" term are subject to a NOT NULL constraint.
  */
  for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
    if( !IsUniqueIndex(pIdx) ) continue;
    for(i=0; i<pIdx->nKeyCol; i++){
      i16 iCol = pIdx->aiColumn[i];
      if( 0==sqlite3WhereFindTerm(pWC, iBase, iCol, ~(Bitmask)0, WO_EQ, pIdx) ){
        int iIdxCol = findIndexCol(pParse, pDistinct, iBase, pIdx, i);
      if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
        if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
        if( iIdxCol<0 || pTab->aCol[iCol].notNull==0 ){
          break;
        if( indexColumnNotNull(pIdx, i)==0 ) break;
        }
      }
    }
    if( i==pIdx->nKeyCol ){
      /* This index implies that the DISTINCT qualifier is redundant. */
      return 1;
    }
  }
120864
120865
120866
120867
120868
120869
120870
120871

120872
120873
120874
120875
120876
120877
120878
120879
120880
120881
120882
120883
120884
120885
120886
120887
120888
120889
120890

120891
120892
120893


120894
120895
120896
120897
120898
120899
120900
121244
121245
121246
121247
121248
121249
121250

121251
121252
121253
121254
121255
121256
121257
121258
121259
121260
121261
121262
121263
121264
121265
121266
121267
121268
121269

121270
121271


121272
121273
121274
121275
121276
121277
121278
121279
121280







-
+


















-
+

-
-
+
+







  sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
  sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
  VdbeComment((v, "for %s", pTable->zName));

  /* Fill the automatic index with content */
  sqlite3ExprCachePush(pParse);
  pTabItem = &pWC->pWInfo->pTabList->a[pLevel->iFrom];
  if( pTabItem->viaCoroutine ){
  if( pTabItem->fg.viaCoroutine ){
    int regYield = pTabItem->regReturn;
    sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
    addrTop =  sqlite3VdbeAddOp1(v, OP_Yield, regYield);
    VdbeCoverage(v);
    VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
  }else{
    addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
  }
  if( pPartial ){
    iContinue = sqlite3VdbeMakeLabel(v);
    sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
    pLoop->wsFlags |= WHERE_PARTIALIDX;
  }
  regRecord = sqlite3GetTempReg(pParse);
  sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
  sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
  sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
  if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
  if( pTabItem->viaCoroutine ){
  if( pTabItem->fg.viaCoroutine ){
    translateColumnToCopy(v, addrTop, pLevel->iTabCur, pTabItem->regResult);
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
    pTabItem->viaCoroutine = 0;
    sqlite3VdbeGoto(v, addrTop);
    pTabItem->fg.viaCoroutine = 0;
  }else{
    sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
  }
  sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
  sqlite3VdbeJumpHere(v, addrTop);
  sqlite3ReleaseTempReg(pParse, regRecord);
  sqlite3ExprCachePop(pParse);
120937
120938
120939
120940
120941
120942
120943

120944
120945
120946
120947
120948
120949
120950
121317
121318
121319
121320
121321
121322
121323
121324
121325
121326
121327
121328
121329
121330
121331







+







    assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
    testcase( pTerm->eOperator & WO_IN );
    testcase( pTerm->eOperator & WO_ISNULL );
    testcase( pTerm->eOperator & WO_IS );
    testcase( pTerm->eOperator & WO_ALL );
    if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
    if( pTerm->wtFlags & TERM_VNULL ) continue;
    assert( pTerm->u.leftColumn>=(-1) );
    nTerm++;
  }

  /* If the ORDER BY clause contains only columns in the current 
  ** virtual table then allocate space for the aOrderBy part of
  ** the sqlite3_index_info structure.
  */
120992
120993
120994
120995
120996
120997
120998

120999
121000
121001
121002
121003
121004
121005
121373
121374
121375
121376
121377
121378
121379
121380
121381
121382
121383
121384
121385
121386
121387







+







    assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
    testcase( pTerm->eOperator & WO_IN );
    testcase( pTerm->eOperator & WO_IS );
    testcase( pTerm->eOperator & WO_ISNULL );
    testcase( pTerm->eOperator & WO_ALL );
    if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
    if( pTerm->wtFlags & TERM_VNULL ) continue;
    assert( pTerm->u.leftColumn>=(-1) );
    pIdxCons[j].iColumn = pTerm->u.leftColumn;
    pIdxCons[j].iTermOffset = i;
    op = (u8)pTerm->eOperator & WO_ALL;
    if( op==WO_IN ) op = WO_EQ;
    pIdxCons[j].op = op;
    /* The direct assignment in the previous line is possible only because
    ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical.  The
121281
121282
121283
121284
121285
121286
121287














121288
121289
121290
121291
121292
121293
121294
121663
121664
121665
121666
121667
121668
121669
121670
121671
121672
121673
121674
121675
121676
121677
121678
121679
121680
121681
121682
121683
121684
121685
121686
121687
121688
121689
121690







+
+
+
+
+
+
+
+
+
+
+
+
+
+







      nRet += pTerm->truthProb;
    }else if( (pTerm->wtFlags & TERM_VNULL)==0 ){
      nRet -= 20;        assert( 20==sqlite3LogEst(4) );
    }
  }
  return nRet;
}


#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
/*
** Return the affinity for a single column of an index.
*/
static char sqlite3IndexColumnAffinity(sqlite3 *db, Index *pIdx, int iCol){
  if( !pIdx->zColAff ){
    if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB;
  }
  return pIdx->zColAff[iCol];
}
#endif


#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
/* 
** This function is called to estimate the number of rows visited by a
** range-scan on a skip-scan index. For example:
**
**   CREATE INDEX i1 ON t1(a, b, c);
121332
121333
121334
121335
121336
121337
121338
121339

121340
121341
121342
121343
121344
121345
121346
121728
121729
121730
121731
121732
121733
121734

121735
121736
121737
121738
121739
121740
121741
121742







-
+







  Index *p = pLoop->u.btree.pIndex;
  int nEq = pLoop->u.btree.nEq;
  sqlite3 *db = pParse->db;
  int nLower = -1;
  int nUpper = p->nSample+1;
  int rc = SQLITE_OK;
  int iCol = p->aiColumn[nEq];
  u8 aff = iCol>=0 ? p->pTable->aCol[iCol].affinity : SQLITE_AFF_INTEGER;
  u8 aff = sqlite3IndexColumnAffinity(db, p, iCol);
  CollSeq *pColl;
  
  sqlite3_value *p1 = 0;          /* Value extracted from pLower */
  sqlite3_value *p2 = 0;          /* Value extracted from pUpper */
  sqlite3_value *pVal = 0;        /* Value extracted from record */

  pColl = sqlite3LocateCollSeq(pParse, p->azColl[nEq]);
121480
121481
121482
121483
121484
121485
121486
121487
121488


121489
121490
121491
121492
121493
121494
121495
121496
121497
121498
121876
121877
121878
121879
121880
121881
121882


121883
121884



121885
121886
121887
121888
121889
121890
121891







-
-
+
+
-
-
-







      int iLwrIdx = -2;   /* aSample[] for the lower bound */
      int iUprIdx = -1;   /* aSample[] for the upper bound */

      if( pRec ){
        testcase( pRec->nField!=pBuilder->nRecValid );
        pRec->nField = pBuilder->nRecValid;
      }
      if( nEq==p->nKeyCol ){
        aff = SQLITE_AFF_INTEGER;
      aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq);
      assert( nEq!=p->nKeyCol || aff==SQLITE_AFF_INTEGER );
      }else{
        aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
      }
      /* Determine iLower and iUpper using ($P) only. */
      if( nEq==0 ){
        iLower = 0;
        iUpper = p->nRowEst0;
      }else{
        /* Note: this call could be optimized away - since the same values must 
        ** have been requested when testing key $P in whereEqualScanEst().  */
121642
121643
121644
121645
121646
121647
121648
121649

121650
121651
121652
121653
121654
121655
121656
122035
122036
122037
122038
122039
122040
122041

122042
122043
122044
122045
122046
122047
122048
122049







-
+







  /* This is an optimization only. The call to sqlite3Stat4ProbeSetValue()
  ** below would return the same value.  */
  if( nEq>=p->nColumn ){
    *pnRow = 1;
    return SQLITE_OK;
  }

  aff = p->pTable->aCol[p->aiColumn[nEq-1]].affinity;
  aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq-1);
  rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq-1, &bOk);
  pBuilder->pRec = pRec;
  if( rc!=SQLITE_OK ) return rc;
  if( bOk==0 ) return SQLITE_NOTFOUND;
  pBuilder->nRecValid = nEq;

  whereKeyStats(pParse, p, pRec, 0, a);
122069
122070
122071
122072
122073
122074
122075

122076
122077
122078


122079
122080

122081
122082
122083
122084
122085
122086




122087

122088
122089
122090
122091
122092
122093
122094
122462
122463
122464
122465
122466
122467
122468
122469
122470


122471
122472
122473

122474
122475
122476




122477
122478
122479
122480
122481
122482
122483
122484
122485
122486
122487
122488
122489







+

-
-
+
+

-
+


-
-
-
-
+
+
+
+

+







  WhereInfo *pWInfo = pBuilder->pWInfo;
  sqlite3 *db = pWInfo->pParse->db;

  /* If pBuilder->pOrSet is defined, then only keep track of the costs
  ** and prereqs.
  */
  if( pBuilder->pOrSet!=0 ){
    if( pTemplate->nLTerm ){
#if WHERETRACE_ENABLED
    u16 n = pBuilder->pOrSet->n;
    int x =
      u16 n = pBuilder->pOrSet->n;
      int x =
#endif
    whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
      whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
                                    pTemplate->nOut);
#if WHERETRACE_ENABLED /* 0x8 */
    if( sqlite3WhereTrace & 0x8 ){
      sqlite3DebugPrintf(x?"   or-%d:  ":"   or-X:  ", n);
      whereLoopPrint(pTemplate, pBuilder->pWC);
    }
      if( sqlite3WhereTrace & 0x8 ){
        sqlite3DebugPrintf(x?"   or-%d:  ":"   or-X:  ", n);
        whereLoopPrint(pTemplate, pBuilder->pWC);
      }
#endif
    }
    return SQLITE_OK;
  }

  /* Look for an existing WhereLoop to replace with pTemplate
  */
  whereLoopAdjustCost(pWInfo->pLoops, pTemplate);
  ppPrev = whereLoopFindLesser(&pWInfo->pLoops, pTemplate);
122270
122271
122272
122273
122274
122275
122276
122277
122278
122279
122280
122281
122282
122283
122284
122285
122286
122287
122288
122289
122290

122291
122292
122293
122294
122295
122296
122297
122298
122299
122300
122301
122302
122303
122304
122305
122306
122307


122308
122309
122310
122311
122312
122313
122314
122315
122316
122317
122318
122319
122320

122321
122322
122323
122324
122325
122326
122327
122665
122666
122667
122668
122669
122670
122671

122672
122673
122674
122675
122676
122677
122678
122679
122680
122681
122682
122683

122684
122685
122686
122687
122688
122689
122690
122691

122692


122693
122694
122695
122696
122697
122698
122699
122700
122701
122702
122703
122704
122705
122706
122707
122708
122709
122710
122711
122712

122713
122714
122715
122716
122717
122718
122719
122720







-












-
+







-

-
-






+
+












-
+







  WhereScan scan;                 /* Iterator for WHERE terms */
  Bitmask saved_prereq;           /* Original value of pNew->prereq */
  u16 saved_nLTerm;               /* Original value of pNew->nLTerm */
  u16 saved_nEq;                  /* Original value of pNew->u.btree.nEq */
  u16 saved_nSkip;                /* Original value of pNew->nSkip */
  u32 saved_wsFlags;              /* Original value of pNew->wsFlags */
  LogEst saved_nOut;              /* Original value of pNew->nOut */
  int iCol;                       /* Index of the column in the table */
  int rc = SQLITE_OK;             /* Return code */
  LogEst rSize;                   /* Number of rows in the table */
  LogEst rLogSize;                /* Logarithm of table size */
  WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */

  pNew = pBuilder->pNew;
  if( db->mallocFailed ) return SQLITE_NOMEM;

  assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
  assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
  if( pNew->wsFlags & WHERE_BTM_LIMIT ){
    opMask = WO_LT|WO_LE;
  }else if( /*pProbe->tnum<=0 ||*/ (pSrc->jointype & JT_LEFT)!=0 ){
  }else if( /*pProbe->tnum<=0 ||*/ (pSrc->fg.jointype & JT_LEFT)!=0 ){
    opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE;
  }else{
    opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
  }
  if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);

  assert( pNew->u.btree.nEq<pProbe->nColumn );
  iCol = pProbe->aiColumn[pNew->u.btree.nEq];

  pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
                        opMask, pProbe);
  saved_nEq = pNew->u.btree.nEq;
  saved_nSkip = pNew->nSkip;
  saved_nLTerm = pNew->nLTerm;
  saved_wsFlags = pNew->wsFlags;
  saved_prereq = pNew->prereq;
  saved_nOut = pNew->nOut;
  pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, saved_nEq,
                        opMask, pProbe);
  pNew->rSetup = 0;
  rSize = pProbe->aiRowLogEst[0];
  rLogSize = estLog(rSize);
  for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
    u16 eOp = pTerm->eOperator;   /* Shorthand for pTerm->eOperator */
    LogEst rCostIdx;
    LogEst nOutUnadjusted;        /* nOut before IN() and WHERE adjustments */
    int nIn = 0;
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
    int nRecValid = pBuilder->nRecValid;
#endif
    if( (eOp==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0)
     && (iCol<0 || pSrc->pTab->aCol[iCol].notNull)
     && indexColumnNotNull(pProbe, saved_nEq)
    ){
      continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */
    }
    if( pTerm->prereqRight & pNew->maskSelf ) continue;

    /* Do not allow the upper bound of a LIKE optimization range constraint
    ** to mix with a lower range bound from some other source */
122350
122351
122352
122353
122354
122355
122356

122357

122358

122359
122360
122361
122362
122363
122364
122365
122743
122744
122745
122746
122747
122748
122749
122750
122751
122752

122753
122754
122755
122756
122757
122758
122759
122760







+

+
-
+







        /* "x IN (value, value, ...)" */
        nIn = sqlite3LogEst(pExpr->x.pList->nExpr);
      }
      assert( nIn>0 );  /* RHS always has 2 or more terms...  The parser
                        ** changes "x IN (?)" into "x=?". */

    }else if( eOp & (WO_EQ|WO_IS) ){
      int iCol = pProbe->aiColumn[saved_nEq];
      pNew->wsFlags |= WHERE_COLUMN_EQ;
      assert( saved_nEq==pNew->u.btree.nEq );
      if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
      if( iCol==(-1) || (iCol>0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1) ){
        if( iCol>=0 && pProbe->uniqNotNull==0 ){
          pNew->wsFlags |= WHERE_UNQ_WANTED;
        }else{
          pNew->wsFlags |= WHERE_ONEROW;
        }
      }
    }else if( eOp & WO_ISNULL ){
122402
122403
122404
122405
122406
122407
122408
122409

122410
122411
122412
122413
122414
122415
122416
122797
122798
122799
122800
122801
122802
122803

122804
122805
122806
122807
122808
122809
122810
122811







-
+







      ** data, using some other estimate.  */
      whereRangeScanEst(pParse, pBuilder, pBtm, pTop, pNew);
    }else{
      int nEq = ++pNew->u.btree.nEq;
      assert( eOp & (WO_ISNULL|WO_EQ|WO_IN|WO_IS) );

      assert( pNew->nOut==saved_nOut );
      if( pTerm->truthProb<=0 && iCol>=0 ){
      if( pTerm->truthProb<=0 && pProbe->aiColumn[saved_nEq]>=0 ){
        assert( (eOp & WO_IN) || nIn==0 );
        testcase( eOp & WO_IN );
        pNew->nOut += pTerm->truthProb;
        pNew->nOut -= nIn;
      }else{
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
        tRowcnt nOut = 0;
122578
122579
122580
122581
122582
122583
122584




122585
122586
122587
122588
122589
122590
122591
122973
122974
122975
122976
122977
122978
122979
122980
122981
122982
122983
122984
122985
122986
122987
122988
122989
122990







+
+
+
+








/* Check to see if a partial index with pPartIndexWhere can be used
** in the current query.  Return true if it can be and false if not.
*/
static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
  int i;
  WhereTerm *pTerm;
  while( pWhere->op==TK_AND ){
    if( !whereUsablePartialIndex(iTab,pWC,pWhere->pLeft) ) return 0;
    pWhere = pWhere->pRight;
  }
  for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
    Expr *pExpr = pTerm->pExpr;
    if( sqlite3ExprImpliesExpr(pExpr, pWhere, iTab) 
     && (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
    ){
      return 1;
    }
122653
122654
122655
122656
122657
122658
122659
122660

122661
122662

122663
122664
122665
122666
122667
122668
122669
122670
122671
122672
122673
122674
122675
122676
122677
122678
122679
122680
122681
122682

122683
122684
122685
122686
122687
122688
122689
122690
122691
122692
122693
122694

122695
122696
122697
122698
122699
122700
122701





122702
122703
122704
122705
122706
122707
122708
123052
123053
123054
123055
123056
123057
123058

123059
123060

123061
123062
123063
123064
123065
123066
123067
123068
123069
123070
123071
123072
123073
123074
123075
123076
123077
123078
123079
123080

123081
123082
123083
123084
123085
123086
123087
123088
123089
123090
123091
123092

123093
123094
123095





123096
123097
123098
123099
123100
123101
123102
123103
123104
123105
123106
123107







-
+

-
+



















-
+











-
+


-
-
-
-
-
+
+
+
+
+







  pWInfo = pBuilder->pWInfo;
  pTabList = pWInfo->pTabList;
  pSrc = pTabList->a + pNew->iTab;
  pTab = pSrc->pTab;
  pWC = pBuilder->pWC;
  assert( !IsVirtual(pSrc->pTab) );

  if( pSrc->pIndex ){
  if( pSrc->pIBIndex ){
    /* An INDEXED BY clause specifies a particular index to use */
    pProbe = pSrc->pIndex;
    pProbe = pSrc->pIBIndex;
  }else if( !HasRowid(pTab) ){
    pProbe = pTab->pIndex;
  }else{
    /* There is no INDEXED BY clause.  Create a fake Index object in local
    ** variable sPk to represent the rowid primary key index.  Make this
    ** fake index the first in a chain of Index objects with all of the real
    ** indices to follow */
    Index *pFirst;                  /* First of real indices on the table */
    memset(&sPk, 0, sizeof(Index));
    sPk.nKeyCol = 1;
    sPk.nColumn = 1;
    sPk.aiColumn = &aiColumnPk;
    sPk.aiRowLogEst = aiRowEstPk;
    sPk.onError = OE_Replace;
    sPk.pTable = pTab;
    sPk.szIdxRow = pTab->szTabRow;
    aiRowEstPk[0] = pTab->nRowLogEst;
    aiRowEstPk[1] = 0;
    pFirst = pSrc->pTab->pIndex;
    if( pSrc->notIndexed==0 ){
    if( pSrc->fg.notIndexed==0 ){
      /* The real indices of the table are only considered if the
      ** NOT INDEXED qualifier is omitted from the FROM clause */
      sPk.pNext = pFirst;
    }
    pProbe = &sPk;
  }
  rSize = pTab->nRowLogEst;
  rLogSize = estLog(rSize);

#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
  /* Automatic indexes */
  if( !pBuilder->pOrSet   /* Not part of an OR optimization */
  if( !pBuilder->pOrSet      /* Not part of an OR optimization */
   && (pWInfo->wctrlFlags & WHERE_NO_AUTOINDEX)==0
   && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
   && pSrc->pIndex==0     /* Has no INDEXED BY clause */
   && !pSrc->notIndexed   /* Has no NOT INDEXED clause */
   && HasRowid(pTab)      /* Is not a WITHOUT ROWID table. (FIXME: Why not?) */
   && !pSrc->isCorrelated /* Not a correlated subquery */
   && !pSrc->isRecursive  /* Not a recursive common table expression. */
   && pSrc->pIBIndex==0      /* Has no INDEXED BY clause */
   && !pSrc->fg.notIndexed   /* Has no NOT INDEXED clause */
   && HasRowid(pTab)         /* Is not a WITHOUT ROWID table. (FIXME: Why not?) */
   && !pSrc->fg.isCorrelated /* Not a correlated subquery */
   && !pSrc->fg.isRecursive  /* Not a recursive common table expression. */
  ){
    /* Generate auto-index WhereLoops */
    WhereTerm *pTerm;
    WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
    for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
      if( pTerm->prereqRight & pNew->maskSelf ) continue;
      if( termCanDriveIndex(pTerm, pSrc, 0) ){
122815
122816
122817
122818
122819
122820
122821
122822

122823
122824
122825
122826
122827
122828
122829
123214
123215
123216
123217
123218
123219
123220

123221
123222
123223
123224
123225
123226
123227
123228







-
+







    sqlite3Stat4ProbeFree(pBuilder->pRec);
    pBuilder->nRecValid = 0;
    pBuilder->pRec = 0;
#endif

    /* If there was an INDEXED BY clause, then only that one index is
    ** considered. */
    if( pSrc->pIndex ) break;
    if( pSrc->pIBIndex ) break;
  }
  return rc;
}

#ifndef SQLITE_OMIT_VIRTUALTABLE
/*
** Add all WhereLoop objects for a table of the join identified by
123161
123162
123163
123164
123165
123166
123167
123168

123169
123170
123171
123172
123173

123174
123175
123176
123177

123178
123179
123180
123181
123182
123183
123184
123560
123561
123562
123563
123564
123565
123566

123567
123568
123569
123570
123571

123572
123573
123574
123575

123576
123577
123578
123579
123580
123581
123582
123583







-
+




-
+



-
+







  /* Loop over the tables in the join, from left to right */
  pNew = pBuilder->pNew;
  whereLoopInit(pNew);
  for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
    Bitmask mUnusable = 0;
    pNew->iTab = iTab;
    pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
    if( ((pItem->jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){
    if( ((pItem->fg.jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){
      /* This condition is true when pItem is the FROM clause term on the
      ** right-hand-side of a LEFT or CROSS JOIN.  */
      mExtra = mPrior;
    }
    priorJointype = pItem->jointype;
    priorJointype = pItem->fg.jointype;
    if( IsVirtual(pItem->pTab) ){
      struct SrcList_item *p;
      for(p=&pItem[1]; p<pEnd; p++){
        if( mUnusable || (p->jointype & (JT_LEFT|JT_CROSS)) ){
        if( mUnusable || (p->fg.jointype & (JT_LEFT|JT_CROSS)) ){
          mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor);
        }
      }
      rc = whereLoopAddVirtual(pBuilder, mExtra, mUnusable);
    }else{
      rc = whereLoopAddBtree(pBuilder, mExtra);
    }
123900
123901
123902
123903
123904
123905
123906
123907

123908
123909
123910
123911
123912
123913
123914
124299
124300
124301
124302
124303
124304
124305

124306
124307
124308
124309
124310
124311
124312
124313







-
+







  
  pWInfo = pBuilder->pWInfo;
  if( pWInfo->wctrlFlags & WHERE_FORCE_TABLE ) return 0;
  assert( pWInfo->pTabList->nSrc>=1 );
  pItem = pWInfo->pTabList->a;
  pTab = pItem->pTab;
  if( IsVirtual(pTab) ) return 0;
  if( pItem->zIndexedBy ) return 0;
  if( pItem->fg.isIndexedBy ) return 0;
  iCur = pItem->iCursor;
  pWC = &pWInfo->sWC;
  pLoop = pBuilder->pNew;
  pLoop->wsFlags = 0;
  pLoop->nSkip = 0;
  pTerm = sqlite3WhereFindTerm(pWC, iCur, -1, 0, WO_EQ|WO_IS, 0);
  if( pTerm ){
123925
123926
123927
123928
123929
123930
123931
123932

123933
123934
123935
123936
123937
123938
123939
124324
124325
124326
124327
124328
124329
124330

124331
124332
124333
124334
124335
124336
124337
124338







-
+







      assert( pLoop->aLTermSpace==pLoop->aLTerm );
      if( !IsUniqueIndex(pIdx)
       || pIdx->pPartIdxWhere!=0 
       || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace) 
      ) continue;
      opMask = pIdx->uniqNotNull ? (WO_EQ|WO_IS) : WO_EQ;
      for(j=0; j<pIdx->nKeyCol; j++){
        pTerm = sqlite3WhereFindTerm(pWC, iCur, pIdx->aiColumn[j], 0, opMask, pIdx);
        pTerm = sqlite3WhereFindTerm(pWC, iCur, j, 0, opMask, pIdx);
        if( pTerm==0 ) break;
        testcase( pTerm->eOperator & WO_IS );
        pLoop->aLTerm[j] = pTerm;
      }
      if( j!=pIdx->nKeyCol ) continue;
      pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_ONEROW|WHERE_INDEXED;
      if( pIdx->isCovering || (pItem->colUsed & ~columnsInIndex(pIdx))==0 ){
124165
124166
124167
124168
124169
124170
124171
124172
124173
124174




124175
124176
124177
124178
124179


124180
124181
124182
124183
124184
124185
124186
124187

124188
124189

124190
124191
124192
124193
124194



124195
124196
124197
124198
124199
124200
124201
124202
124203
124564
124565
124566
124567
124568
124569
124570



124571
124572
124573
124574





124575
124576
124577
124578
124579
124580
124581
124582
124583
124584
124585
124586

124587





124588
124589
124590


124591
124592
124593
124594
124595
124596
124597







-
-
-
+
+
+
+
-
-
-
-
-
+
+








+

-
+
-
-
-
-
-
+
+
+
-
-







    if( wctrlFlags & WHERE_WANT_DISTINCT ){
      pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
    }
  }

  /* Assign a bit from the bitmask to every term in the FROM clause.
  **
  ** When assigning bitmask values to FROM clause cursors, it must be
  ** the case that if X is the bitmask for the N-th FROM clause term then
  ** the bitmask for all FROM clause terms to the left of the N-th term
  ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
  **
  ** The rule of the previous sentence ensures thta if X is the bitmask for
  ** a table T, then X-1 is the bitmask for all other tables to the left of T.
  ** is (X-1).   An expression from the ON clause of a LEFT JOIN can use
  ** its Expr.iRightJoinTable value to find the bitmask of the right table
  ** of the join.  Subtracting one from the right table bitmask gives a
  ** bitmask for all tables to the left of the join.  Knowing the bitmask
  ** for all tables to the left of a left join is important.  Ticket #3015.
  ** Knowing the bitmask for all tables to the left of a left join is
  ** important.  Ticket #3015.
  **
  ** Note that bitmasks are created for all pTabList->nSrc tables in
  ** pTabList, not just the first nTabList tables.  nTabList is normally
  ** equal to pTabList->nSrc but might be shortened to 1 if the
  ** WHERE_ONETABLE_ONLY flag is set.
  */
  for(ii=0; ii<pTabList->nSrc; ii++){
    createMask(pMaskSet, pTabList->a[ii].iCursor);
    sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC);
  }
#ifndef NDEBUG
#ifdef SQLITE_DEBUG
  {
    Bitmask toTheLeft = 0;
    for(ii=0; ii<pTabList->nSrc; ii++){
      Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
      assert( (m-1)==toTheLeft );
  for(ii=0; ii<pTabList->nSrc; ii++){
    Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
    assert( m==MASKBIT(ii) );
      toTheLeft |= m;
    }
  }
#endif

  /* Analyze all of the subexpressions. */
  sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
  if( db->mallocFailed ) goto whereBeginError;

124287
124288
124289
124290
124291
124292
124293
124294

124295
124296
124297
124298
124299
124300
124301
124681
124682
124683
124684
124685
124686
124687

124688
124689
124690
124691
124692
124693
124694
124695







-
+







    Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
    if( sWLB.pOrderBy ){
      tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
    }
    while( pWInfo->nLevel>=2 ){
      WhereTerm *pTerm, *pEnd;
      pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
      if( (pWInfo->pTabList->a[pLoop->iTab].jointype & JT_LEFT)==0 ) break;
      if( (pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0 ) break;
      if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
       && (pLoop->wsFlags & WHERE_ONEROW)==0
      ){
        break;
      }
      if( (tabUsed & pLoop->maskSelf)!=0 ) break;
      pEnd = sWLB.pWC->a + sWLB.pWC->nTerm;
124525
124526
124527
124528
124529
124530
124531
124532

124533
124534
124535
124536
124537
124538
124539
124919
124920
124921
124922
124923
124924
124925

124926
124927
124928
124929
124930
124931
124932
124933







-
+







        VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
        VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
        sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
      }
    }
    sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
    if( pLevel->addrSkip ){
      sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
      sqlite3VdbeGoto(v, pLevel->addrSkip);
      VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
      sqlite3VdbeJumpHere(v, pLevel->addrSkip);
      sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
    }
    if( pLevel->addrLikeRep ){
      int op;
      if( sqlite3VdbeGetOp(v, pLevel->addrLikeRep-1)->p1 ){
124553
124554
124555
124556
124557
124558
124559
124560

124561
124562
124563
124564
124565
124566
124567
124947
124948
124949
124950
124951
124952
124953

124954
124955
124956
124957
124958
124959
124960
124961







-
+







      }
      if( pLoop->wsFlags & WHERE_INDEXED ){
        sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
      }
      if( pLevel->op==OP_Return ){
        sqlite3VdbeAddOp2(v, OP_Gosub, pLevel->p1, pLevel->addrFirst);
      }else{
        sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
        sqlite3VdbeGoto(v, pLevel->addrFirst);
      }
      sqlite3VdbeJumpHere(v, addr);
    }
    VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
                     pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
  }

124580
124581
124582
124583
124584
124585
124586
124587

124588
124589
124590
124591
124592
124593
124594
124974
124975
124976
124977
124978
124979
124980

124981
124982
124983
124984
124985
124986
124987
124988







-
+







    assert( pTab!=0 );
    pLoop = pLevel->pWLoop;

    /* For a co-routine, change all OP_Column references to the table of
    ** the co-routine into OP_Copy of result contained in a register.
    ** OP_Rowid becomes OP_Null.
    */
    if( pTabItem->viaCoroutine && !db->mallocFailed ){
    if( pTabItem->fg.viaCoroutine && !db->mallocFailed ){
      translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur,
                            pTabItem->regResult);
      continue;
    }

    /* Close all of the cursors that were opened by sqlite3WhereBegin.
    ** Except, do not close cursors that will be reused by the OR optimization
124814
124815
124816
124817
124818
124819
124820























124821
124822
124823
124824
124825
124826
124827
125208
125209
125210
125211
125212
125213
125214
125215
125216
125217
125218
125219
125220
125221
125222
125223
125224
125225
125226
125227
125228
125229
125230
125231
125232
125233
125234
125235
125236
125237
125238
125239
125240
125241
125242
125243
125244







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    ExprSpan *pOperand,    /* The operand */
    Token *pPreOp         /* The operand token for setting the span */
  ){
    pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
    pOut->zStart = pPreOp->z;
    pOut->zEnd = pOperand->zEnd;
  }

  /* Add a single new term to an ExprList that is used to store a
  ** list of identifiers.  Report an error if the ID list contains
  ** a COLLATE clause or an ASC or DESC keyword, except ignore the
  ** error while parsing a legacy schema.
  */
  static ExprList *parserAddExprIdListTerm(
    Parse *pParse,
    ExprList *pPrior,
    Token *pIdToken,
    int hasCollate,
    int sortOrder
  ){
    ExprList *p = sqlite3ExprListAppend(pParse, pPrior, 0);
    if( (hasCollate || sortOrder!=SQLITE_SO_UNDEFINED)
        && pParse->db->init.busy==0
    ){
      sqlite3ErrorMsg(pParse, "syntax error after column name \"%.*s\"",
                         pIdToken->n, pIdToken->z);
    }
    sqlite3ExprListSetName(pParse, p, pIdToken, 1);
    return p;
  }
/* Next is all token values, in a form suitable for use by makeheaders.
** This section will be null unless lemon is run with the -m switch.
*/
/* 
** These constants (all generated automatically by the parser generator)
** specify the various kinds of tokens (terminals) that the parser
** understands. 
124858
124859
124860
124861
124862
124863
124864


124865
124866
124867
124868







124869
124870
124871
124872
124873
124874
124875
125275
125276
125277
125278
125279
125280
125281
125282
125283
125284
125285


125286
125287
125288
125289
125290
125291
125292
125293
125294
125295
125296
125297
125298
125299







+
+


-
-
+
+
+
+
+
+
+







**                       for base tokens is called "yy0".
**    YYSTACKDEPTH       is the maximum depth of the parser's stack.  If
**                       zero the stack is dynamically sized using realloc()
**    sqlite3ParserARG_SDECL     A static variable declaration for the %extra_argument
**    sqlite3ParserARG_PDECL     A parameter declaration for the %extra_argument
**    sqlite3ParserARG_STORE     Code to store %extra_argument into yypParser
**    sqlite3ParserARG_FETCH     Code to extract %extra_argument from yypParser
**    YYERRORSYMBOL      is the code number of the error symbol.  If not
**                       defined, then do no error processing.
**    YYNSTATE           the combined number of states.
**    YYNRULE            the number of rules in the grammar
**    YYERRORSYMBOL      is the code number of the error symbol.  If not
**                       defined, then do no error processing.
**    YY_MAX_SHIFT       Maximum value for shift actions
**    YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
**    YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
**    YY_MIN_REDUCE      Maximum value for reduce actions
**    YY_ERROR_ACTION    The yy_action[] code for syntax error
**    YY_ACCEPT_ACTION   The yy_action[] code for accept
**    YY_NO_ACTION       The yy_action[] code for no-op
*/
#define YYCODETYPE unsigned char
#define YYNOCODE 254
#define YYACTIONTYPE unsigned short int
#define YYWILDCARD 70
#define sqlite3ParserTOKENTYPE Token
typedef union {
124894
124895
124896
124897
124898
124899
124900

124901
124902
124903
124904
124905
124906










124907
124908
124909
124910
124911
124912
124913
125318
125319
125320
125321
125322
125323
125324
125325






125326
125327
125328
125329
125330
125331
125332
125333
125334
125335
125336
125337
125338
125339
125340
125341
125342







+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







#ifndef YYSTACKDEPTH
#define YYSTACKDEPTH 100
#endif
#define sqlite3ParserARG_SDECL Parse *pParse;
#define sqlite3ParserARG_PDECL ,Parse *pParse
#define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
#define sqlite3ParserARG_STORE yypParser->pParse = pParse
#define YYFALLBACK 1
#define YYNSTATE 642
#define YYNRULE 327
#define YYFALLBACK 1
#define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
#define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
#define YY_ERROR_ACTION   (YYNSTATE+YYNRULE)
#define YYNSTATE             436
#define YYNRULE              328
#define YY_MAX_SHIFT         435
#define YY_MIN_SHIFTREDUCE   649
#define YY_MAX_SHIFTREDUCE   976
#define YY_MIN_REDUCE        977
#define YY_MAX_REDUCE        1304
#define YY_ERROR_ACTION      1305
#define YY_ACCEPT_ACTION     1306
#define YY_NO_ACTION         1307

/* The yyzerominor constant is used to initialize instances of
** YYMINORTYPE objects to zero. */
static const YYMINORTYPE yyzerominor = { 0 };

/* Define the yytestcase() macro to be a no-op if is not already defined
** otherwise.
124926
124927
124928
124929
124930
124931
124932
124933

124934
124935

124936

124937



124938

124939
124940

124941
124942

124943
124944
124945
124946
124947
124948
124949
125355
125356
125357
125358
125359
125360
125361

125362
125363
125364
125365

125366
125367
125368
125369
125370

125371
125372

125373
125374

125375
125376
125377
125378
125379
125380
125381
125382







-
+


+
-
+

+
+
+
-
+

-
+

-
+







** current state and lookahead token.  These tables are used to implement
** functions that take a state number and lookahead value and return an
** action integer.  
**
** Suppose the action integer is N.  Then the action is determined as
** follows
**
**   0 <= N < YYNSTATE                  Shift N.  That is, push the lookahead
**   0 <= N <= YY_MAX_SHIFT             Shift N.  That is, push the lookahead
**                                      token onto the stack and goto state N.
**
**   N between YY_MIN_SHIFTREDUCE       Shift to an arbitrary state then
**   YYNSTATE <= N < YYNSTATE+YYNRULE   Reduce by rule N-YYNSTATE.
**     and YY_MAX_SHIFTREDUCE           reduce by rule N-YY_MIN_SHIFTREDUCE.
**
**   N between YY_MIN_REDUCE            Reduce by rule N-YY_MIN_REDUCE
**     and YY_MAX_REDUCE

**   N == YYNSTATE+YYNRULE              A syntax error has occurred.
**   N == YY_ERROR_ACTION               A syntax error has occurred.
**
**   N == YYNSTATE+YYNRULE+1            The parser accepts its input.
**   N == YY_ACCEPT_ACTION              The parser accepts its input.
**
**   N == YYNSTATE+YYNRULE+2            No such action.  Denotes unused
**   N == YY_NO_ACTION                  No such action.  Denotes unused
**                                      slots in the yy_action[] table.
**
** The action table is constructed as a single large table named yy_action[].
** Given state S and lookahead X, the action is computed as
**
**      yy_action[ yy_shift_ofst[S] + X ]
**
124965
124966
124967
124968
124969
124970
124971
124972

124973
124974
124975
124976
124977
124978
124979
124980
124981
124982
124983
124984
124985
124986
124987
124988
124989
124990
124991
124992
124993
124994
124995
124996
124997
124998
124999
125000
125001
125002
125003
125004
125005
125006
125007
125008
125009
125010
125011
125012
125013
125014
125015
125016
125017
125018
125019
125020
125021
125022
125023
125024
125025
125026
125027
125028
125029
125030
125031
125032
125033
125034
125035
125036
125037
125038
125039
125040
125041
125042
125043
125044
125045
125046
125047
125048
125049
125050
125051
125052
125053
125054
125055
125056
125057
125058
125059
125060
125061
125062
125063
125064
125065
125066
125067
125068
125069
125070
125071
125072
125073
125074
125075
125076
125077
125078
125079
125080
125081
125082
125083
125084
125085
125086
125087
125088
125089
125090
125091
125092
125093
125094
125095
125096
125097
125098
125099
125100
125101
125102
125103
125104
125105
125106
125107
125108
125109
125110
125111
125112
125113
125114
125115
125116
125117
125118
125119
125120
125121
125122
125123























































































































































125124
125125
125126

125127
125128
125129
125130
125131
125132
125133
125134
125135
125136
125137
125138











125139
125140
125141
125142
125143
125144
125145
125146
125147








125148
125149
125150
125151
125152
125153
125154
125155
125156
125157
125158
125159
125160












125161
125162
125163
125164
125165
125166
125167
125168
125169
125170
125171
125172
125173
125174













125175
125176
125177
125178
125179
125180
125181
125182
125183








125184
125185
125186
125187
125188
125189
125190






125191
125192
125193
125194
125195
125196
125197
125198
125199
125200
125201
125202
125203
125204
125205



















125206
125207
125208
125209
125210
125211
125212
125213
125214
125215



125216
125217
125218
125219
125220



125221
125222
125223
125224
125225



125226
125227
125228
125229
125230
125231




125232
125233
125234
125235
125236
125237
125238
125239
125240
125241
125242
125243
125244
125245
125246
125247
125248
125249
125250
125251
125252
125253
125254
125255
125256
125257
125258
125259
125260
125261
125262
125263
125264
125265
125266
125267
125268
125269
125270
125271
125272
125273
125274
125275












































125276
125277
125278
125279
125280




125281
125282
125283
125284
125285
125286
125287






125288
125289
125290
125291
125292
125293
125294
125295
125296
125297
125298
125299
125300
125301
125302
125303
125304
125305
125306
125307
125308
125309
125310
125311
125312
125313
125314
125315
125316
125317
125318
125319
125320
125321
125322
125323
125324




































125325
125326
125327
125328
125329




125330
125331
125332
125333
125334
125335
125336
125337
125338
125339
125340
125341
125342
125343
125344
125345
125346
125347
125348
125349
125350
125351
125352
125353
125354
125355
125356
125357
125358
125359
125360
125361
































125362
125363
125364
125365
125366
125367
125368
125369
125370
125371
125372
125373
125374
125375
125376
125377
125378
125379
125380
125381
125382
125383
125384
125385






















125386
125387
125388
125389
125390
125391
125392
125393
125394
125395
125396
125397
125398
125399
125400
125401
125402
125403
125404
125405
125406
125407
125408
125409
125410
125411
125412
125413
125414
125415
125416





















125417
125418
125419
125420
125421
125422
125423
125424
125425
125426
125427
125428

125429
125430
125431
125432
125433
125434
125435
125398
125399
125400
125401
125402
125403
125404

125405
125406






















































































































































125407
125408
125409
125410
125411
125412
125413
125414
125415
125416
125417
125418
125419
125420
125421
125422
125423
125424
125425
125426
125427
125428
125429
125430
125431
125432
125433
125434
125435
125436
125437
125438
125439
125440
125441
125442
125443
125444
125445
125446
125447
125448
125449
125450
125451
125452
125453
125454
125455
125456
125457
125458
125459
125460
125461
125462
125463
125464
125465
125466
125467
125468
125469
125470
125471
125472
125473
125474
125475
125476
125477
125478
125479
125480
125481
125482
125483
125484
125485
125486
125487
125488
125489
125490
125491
125492
125493
125494
125495
125496
125497
125498
125499
125500
125501
125502
125503
125504
125505
125506
125507
125508
125509
125510
125511
125512
125513
125514
125515
125516
125517
125518
125519
125520
125521
125522
125523
125524
125525
125526
125527
125528
125529
125530
125531
125532
125533
125534
125535
125536
125537
125538
125539
125540
125541
125542
125543
125544
125545
125546
125547
125548
125549
125550
125551
125552
125553
125554
125555
125556
125557
125558
125559

125560
125561











125562
125563
125564
125565
125566
125567
125568
125569
125570
125571
125572
125573








125574
125575
125576
125577
125578
125579
125580
125581
125582












125583
125584
125585
125586
125587
125588
125589
125590
125591
125592
125593
125594
125595













125596
125597
125598
125599
125600
125601
125602
125603
125604
125605
125606
125607
125608
125609








125610
125611
125612
125613
125614
125615
125616
125617
125618






125619
125620
125621
125622
125623
125624
125625














125626
125627
125628
125629
125630
125631
125632
125633
125634
125635
125636
125637
125638
125639
125640
125641
125642
125643
125644





125645
125646



125647
125648
125649
125650
125651



125652
125653
125654
125655
125656



125657
125658
125659
125660
125661




125662
125663
125664
125665
125666











































125667
125668
125669
125670
125671
125672
125673
125674
125675
125676
125677
125678
125679
125680
125681
125682
125683
125684
125685
125686
125687
125688
125689
125690
125691
125692
125693
125694
125695
125696
125697
125698
125699
125700
125701
125702
125703
125704
125705
125706
125707
125708
125709
125710
125711




125712
125713
125714
125715
125716






125717
125718
125719
125720
125721
125722
125723
125724



































125725
125726
125727
125728
125729
125730
125731
125732
125733
125734
125735
125736
125737
125738
125739
125740
125741
125742
125743
125744
125745
125746
125747
125748
125749
125750
125751
125752
125753
125754
125755
125756
125757
125758
125759
125760
125761




125762
125763
125764
125765
125766































125767
125768
125769
125770
125771
125772
125773
125774
125775
125776
125777
125778
125779
125780
125781
125782
125783
125784
125785
125786
125787
125788
125789
125790
125791
125792
125793
125794
125795
125796
125797
125798
125799
125800






















125801
125802
125803
125804
125805
125806
125807
125808
125809
125810
125811
125812
125813
125814
125815
125816
125817
125818
125819
125820
125821
125822































125823
125824
125825
125826
125827
125828
125829
125830
125831
125832
125833
125834
125835
125836
125837
125838
125839
125840
125841
125842
125843












125844
125845
125846
125847
125848
125849
125850
125851







-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-


-
-
-
+
+
+


-
-
-
+
+
+


-
-
-
+
+
+


-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+







**                     yy_action.  Used to detect hash collisions.
**  yy_shift_ofst[]    For each state, the offset into yy_action for
**                     shifting terminals.
**  yy_reduce_ofst[]   For each state, the offset into yy_action for
**                     shifting non-terminals after a reduce.
**  yy_default[]       Default action for each state.
*/
#define YY_ACTTAB_COUNT (1497)
#define YY_ACTTAB_COUNT (1501)
static const YYACTIONTYPE yy_action[] = {
 /*     0 */   306,  212,  432,  955,  639,  191,  955,  295,  559,   88,
 /*    10 */    88,   88,   88,   81,   86,   86,   86,   86,   85,   85,
 /*    20 */    84,   84,   84,   83,  330,  185,  184,  183,  635,  635,
 /*    30 */   292,  606,  606,   88,   88,   88,   88,  683,   86,   86,
 /*    40 */    86,   86,   85,   85,   84,   84,   84,   83,  330,   16,
 /*    50 */   436,  597,   89,   90,   80,  600,  599,  601,  601,   87,
 /*    60 */    87,   88,   88,   88,   88,  684,   86,   86,   86,   86,
 /*    70 */    85,   85,   84,   84,   84,   83,  330,  306,  559,   84,
 /*    80 */    84,   84,   83,  330,   65,   86,   86,   86,   86,   85,
 /*    90 */    85,   84,   84,   84,   83,  330,  635,  635,  634,  633,
 /*   100 */   182,  682,  550,  379,  376,  375,   17,  322,  606,  606,
 /*   110 */   371,  198,  479,   91,  374,   82,   79,  165,   85,   85,
 /*   120 */    84,   84,   84,   83,  330,  598,  635,  635,  107,   89,
 /*   130 */    90,   80,  600,  599,  601,  601,   87,   87,   88,   88,
 /*   140 */    88,   88,  186,   86,   86,   86,   86,   85,   85,   84,
 /*   150 */    84,   84,   83,  330,  306,  594,  594,  142,  328,  327,
 /*   160 */   484,  249,  344,  238,  635,  635,  634,  633,  585,  448,
 /*   170 */   526,  525,  229,  388,    1,  394,  450,  584,  449,  635,
 /*   180 */   635,  635,  635,  319,  395,  606,  606,  199,  157,  273,
 /*   190 */   382,  268,  381,  187,  635,  635,  634,  633,  311,  555,
 /*   200 */   266,  593,  593,  266,  347,  588,   89,   90,   80,  600,
 /*   210 */   599,  601,  601,   87,   87,   88,   88,   88,   88,  478,
 /*   220 */    86,   86,   86,   86,   85,   85,   84,   84,   84,   83,
 /*   230 */   330,  306,  272,  536,  634,  633,  146,  610,  197,  310,
 /*   240 */   575,  182,  482,  271,  379,  376,  375,  506,   21,  634,
 /*   250 */   633,  634,  633,  635,  635,  374,  611,  574,  548,  440,
 /*   260 */   111,  563,  606,  606,  634,  633,  324,  479,  608,  608,
 /*   270 */   608,  300,  435,  573,  119,  407,  210,  162,  562,  883,
 /*   280 */   592,  592,  306,   89,   90,   80,  600,  599,  601,  601,
 /*   290 */    87,   87,   88,   88,   88,   88,  506,   86,   86,   86,
 /*   300 */    86,   85,   85,   84,   84,   84,   83,  330,  620,  111,
 /*   310 */   635,  635,  361,  606,  606,  358,  249,  349,  248,  433,
 /*   320 */   243,  479,  586,  634,  633,  195,  611,   93,  119,  221,
 /*   330 */   575,  497,  534,  534,   89,   90,   80,  600,  599,  601,
 /*   340 */   601,   87,   87,   88,   88,   88,   88,  574,   86,   86,
 /*   350 */    86,   86,   85,   85,   84,   84,   84,   83,  330,  306,
 /*   360 */    77,  429,  638,  573,  589,  530,  240,  230,  242,  105,
 /*   370 */   249,  349,  248,  515,  588,  208,  460,  529,  564,  173,
 /*   380 */   634,  633,  970,  144,  430,    2,  424,  228,  380,  557,
 /*   390 */   606,  606,  190,  153,  159,  158,  514,   51,  632,  631,
 /*   400 */   630,   71,  536,  432,  954,  196,  610,  954,  614,   45,
 /*   410 */    18,   89,   90,   80,  600,  599,  601,  601,   87,   87,
 /*   420 */    88,   88,   88,   88,  261,   86,   86,   86,   86,   85,
 /*   430 */    85,   84,   84,   84,   83,  330,  306,  608,  608,  608,
 /*   440 */   542,  424,  402,  385,  241,  506,  451,  320,  211,  543,
 /*   450 */   164,  436,  386,  293,  451,  587,  108,  496,  111,  334,
 /*   460 */   391,  591,  424,  614,   27,  452,  453,  606,  606,   72,
 /*   470 */   257,   70,  259,  452,  339,  342,  564,  582,   68,  415,
 /*   480 */   469,  328,  327,   62,  614,   45,  110,  393,   89,   90,
 /*   490 */    80,  600,  599,  601,  601,   87,   87,   88,   88,   88,
 /*   500 */    88,  152,   86,   86,   86,   86,   85,   85,   84,   84,
 /*   510 */    84,   83,  330,  306,  110,  499,  520,  538,  402,  389,
 /*   520 */   424,  110,  566,  500,  593,  593,  454,   82,   79,  165,
 /*   530 */   424,  591,  384,  564,  340,  615,  188,  162,  424,  350,
 /*   540 */   616,  424,  614,   44,  606,  606,  445,  582,  300,  434,
 /*   550 */   151,   19,  614,    9,  568,  580,  348,  615,  469,  567,
 /*   560 */   614,   26,  616,  614,   45,   89,   90,   80,  600,  599,
 /*   570 */   601,  601,   87,   87,   88,   88,   88,   88,  411,   86,
 /*   580 */    86,   86,   86,   85,   85,   84,   84,   84,   83,  330,
 /*   590 */   306,  579,  110,  578,  521,  282,  433,  398,  400,  255,
 /*   600 */   486,   82,   79,  165,  487,  164,   82,   79,  165,  488,
 /*   610 */   488,  364,  387,  424,  544,  544,  509,  350,  362,  155,
 /*   620 */   191,  606,  606,  559,  642,  640,  333,   82,   79,  165,
 /*   630 */   305,  564,  507,  312,  357,  614,   45,  329,  596,  595,
 /*   640 */   194,  337,   89,   90,   80,  600,  599,  601,  601,   87,
 /*   650 */    87,   88,   88,   88,   88,  424,   86,   86,   86,   86,
 /*   660 */    85,   85,   84,   84,   84,   83,  330,  306,   20,  323,
 /*   670 */   150,  263,  211,  543,  421,  596,  595,  614,   22,  424,
 /*   680 */   193,  424,  284,  424,  391,  424,  509,  424,  577,  424,
 /*   690 */   186,  335,  424,  559,  424,  313,  120,  546,  606,  606,
 /*   700 */    67,  614,   47,  614,   50,  614,   48,  614,  100,  614,
 /*   710 */    99,  614,  101,  576,  614,  102,  614,  109,  326,   89,
 /*   720 */    90,   80,  600,  599,  601,  601,   87,   87,   88,   88,
 /*   730 */    88,   88,  424,   86,   86,   86,   86,   85,   85,   84,
 /*   740 */    84,   84,   83,  330,  306,  424,  311,  424,  585,   54,
 /*   750 */   424,  516,  517,  590,  614,  112,  424,  584,  424,  572,
 /*   760 */   424,  195,  424,  571,  424,   67,  424,  614,   94,  614,
 /*   770 */    98,  424,  614,   97,  264,  606,  606,  195,  614,   46,
 /*   780 */   614,   96,  614,   30,  614,   49,  614,  115,  614,  114,
 /*   790 */   418,  229,  388,  614,  113,  306,   89,   90,   80,  600,
 /*   800 */   599,  601,  601,   87,   87,   88,   88,   88,   88,  424,
 /*   810 */    86,   86,   86,   86,   85,   85,   84,   84,   84,   83,
 /*   820 */   330,  119,  424,  590,  110,  372,  606,  606,  195,   53,
 /*   830 */   250,  614,   29,  195,  472,  438,  729,  190,  302,  498,
 /*   840 */    14,  523,  641,    2,  614,   43,  306,   89,   90,   80,
 /*   850 */   600,  599,  601,  601,   87,   87,   88,   88,   88,   88,
 /*   860 */   424,   86,   86,   86,   86,   85,   85,   84,   84,   84,
 /*   870 */    83,  330,  424,  613,  964,  964,  354,  606,  606,  420,
 /*   880 */   312,   64,  614,   42,  391,  355,  283,  437,  301,  255,
 /*   890 */   414,  410,  495,  492,  614,   28,  471,  306,   89,   90,
 /*   900 */    80,  600,  599,  601,  601,   87,   87,   88,   88,   88,
 /*   910 */    88,  424,   86,   86,   86,   86,   85,   85,   84,   84,
 /*   920 */    84,   83,  330,  424,  110,  110,  110,  110,  606,  606,
 /*   930 */   110,  254,   13,  614,   41,  532,  531,  283,  481,  531,
 /*   940 */   457,  284,  119,  561,  356,  614,   40,  284,  306,   89,
 /*   950 */    78,   80,  600,  599,  601,  601,   87,   87,   88,   88,
 /*   960 */    88,   88,  424,   86,   86,   86,   86,   85,   85,   84,
 /*   970 */    84,   84,   83,  330,  110,  424,  341,  220,  555,  606,
 /*   980 */   606,  351,  555,  318,  614,   95,  413,  255,   83,  330,
 /*   990 */   284,  284,  255,  640,  333,  356,  255,  614,   39,  306,
 /*  1000 */   356,   90,   80,  600,  599,  601,  601,   87,   87,   88,
 /*  1010 */    88,   88,   88,  424,   86,   86,   86,   86,   85,   85,
 /*  1020 */    84,   84,   84,   83,  330,  424,  317,  316,  141,  465,
 /*  1030 */   606,  606,  219,  619,  463,  614,   10,  417,  462,  255,
 /*  1040 */   189,  510,  553,  351,  207,  363,  161,  614,   38,  315,
 /*  1050 */   218,  255,  255,   80,  600,  599,  601,  601,   87,   87,
 /*  1060 */    88,   88,   88,   88,  424,   86,   86,   86,   86,   85,
 /*  1070 */    85,   84,   84,   84,   83,  330,   76,  419,  255,    3,
 /*  1080 */   878,  461,  424,  247,  331,  331,  614,   37,  217,   76,
 /*  1090 */   419,  390,    3,  216,  215,  422,    4,  331,  331,  424,
 /*  1100 */   547,   12,  424,  545,  614,   36,  424,  541,  422,  424,
 /*  1110 */   540,  424,  214,  424,  408,  424,  539,  403,  605,  605,
 /*  1120 */   237,  614,   25,  119,  614,   24,  588,  408,  614,   45,
 /*  1130 */   118,  614,   35,  614,   34,  614,   33,  614,   23,  588,
 /*  1140 */    60,  223,  603,  602,  513,  378,   73,   74,  140,  139,
 /*  1150 */   424,  110,  265,   75,  426,  425,   59,  424,  610,   73,
 /*  1160 */    74,  549,  402,  404,  424,  373,   75,  426,  425,  604,
 /*  1170 */   138,  610,  614,   11,  392,   76,  419,  181,    3,  614,
 /*  1180 */    32,  271,  369,  331,  331,  493,  614,   31,  149,  608,
 /*  1190 */   608,  608,  607,   15,  422,  365,  614,    8,  137,  489,
 /*  1200 */   136,  190,  608,  608,  608,  607,   15,  485,  176,  135,
 /*  1210 */     7,  252,  477,  408,  174,  133,  175,  474,   57,   56,
 /*  1220 */   132,  130,  119,   76,  419,  588,    3,  468,  245,  464,
 /*  1230 */   171,  331,  331,  125,  123,  456,  447,  122,  446,  104,
 /*  1240 */   336,  231,  422,  166,  154,   73,   74,  332,  116,  431,
 /*  1250 */   121,  309,   75,  426,  425,  222,  106,  610,  308,  637,
 /*  1260 */   204,  408,  629,  627,  628,    6,  200,  428,  427,  290,
 /*  1270 */   203,  622,  201,  588,   62,   63,  289,   66,  419,  399,
 /*  1280 */     3,  401,  288,   92,  143,  331,  331,  287,  608,  608,
 /*  1290 */   608,  607,   15,   73,   74,  227,  422,  325,   69,  416,
 /*  1300 */    75,  426,  425,  612,  412,  610,  192,   61,  569,  209,
 /*  1310 */   396,  226,  278,  225,  383,  408,  527,  558,  276,  533,
 /*  1320 */   552,  528,  321,  523,  370,  508,  180,  588,  494,  179,
 /*  1330 */   366,  117,  253,  269,  522,  503,  608,  608,  608,  607,
 /*  1340 */    15,  551,  502,   58,  274,  524,  178,   73,   74,  304,
 /*  1350 */   501,  368,  303,  206,   75,  426,  425,  491,  360,  610,
 /*  1360 */   213,  177,  483,  131,  345,  298,  297,  296,  202,  294,
 /*  1370 */   480,  490,  466,  134,  172,  129,  444,  346,  470,  128,
 /*  1380 */   314,  459,  103,  127,  126,  148,  124,  167,  443,  235,
 /*  1390 */   608,  608,  608,  607,   15,  442,  439,  623,  234,  299,
 /*  1400 */   145,  583,  291,  377,  581,  160,  119,  156,  270,  636,
 /*  1410 */   971,  169,  279,  626,  520,  625,  473,  624,  170,  621,
 /*  1420 */   618,  119,  168,   55,  409,  423,  537,  609,  286,  285,
 /*  1430 */   405,  570,  560,  556,    5,   52,  458,  554,  147,  267,
 /*  1440 */   519,  504,  518,  406,  262,  239,  260,  512,  343,  511,
 /*  1450 */   258,  353,  565,  256,  224,  251,  359,  277,  275,  476,
 /*  1460 */   475,  246,  352,  244,  467,  455,  236,  233,  232,  307,
 /*  1470 */   441,  281,  205,  163,  397,  280,  535,  505,  330,  617,
 /*  1480 */   971,  971,  971,  971,  367,  971,  971,  971,  971,  971,
 /*  1490 */   971,  971,  971,  971,  971,  971,  338,
 /*     0 */   311, 1306,  145,  651,    2,  192,  652,  338,  780,   92,
 /*    10 */    92,   92,   92,   85,   90,   90,   90,   90,   89,   89,
 /*    20 */    88,   88,   88,   87,  335,   88,   88,   88,   87,  335,
 /*    30 */   327,  856,  856,   92,   92,   92,   92,  776,   90,   90,
 /*    40 */    90,   90,   89,   89,   88,   88,   88,   87,  335,   86,
 /*    50 */    83,  166,   93,   94,   84,  868,  871,  860,  860,   91,
 /*    60 */    91,   92,   92,   92,   92,  335,   90,   90,   90,   90,
 /*    70 */    89,   89,   88,   88,   88,   87,  335,  311,  780,   90,
 /*    80 */    90,   90,   90,   89,   89,   88,   88,   88,   87,  335,
 /*    90 */   123,  808,  689,  689,  689,  689,  112,  230,  430,  257,
 /*   100 */   809,  698,  430,   86,   83,  166,  324,   55,  856,  856,
 /*   110 */   201,  158,  276,  387,  271,  386,  188,  689,  689,  828,
 /*   120 */   833,   49,  944,  269,  833,   49,  123,   87,  335,   93,
 /*   130 */    94,   84,  868,  871,  860,  860,   91,   91,   92,   92,
 /*   140 */    92,   92,  342,   90,   90,   90,   90,   89,   89,   88,
 /*   150 */    88,   88,   87,  335,  311,  328,  333,  332,  701,  408,
 /*   160 */   394,   69,  690,  691,  690,  691,  715,  910,  251,  354,
 /*   170 */   250,  698,  704,  430,  908,  430,  909,   89,   89,   88,
 /*   180 */    88,   88,   87,  335,  391,  856,  856,  690,  691,  183,
 /*   190 */    95,  340,  384,  381,  380,  833,   31,  833,   49,  912,
 /*   200 */   912,  333,  332,  379,  123,  311,   93,   94,   84,  868,
 /*   210 */   871,  860,  860,   91,   91,   92,   92,   92,   92,  114,
 /*   220 */    90,   90,   90,   90,   89,   89,   88,   88,   88,   87,
 /*   230 */   335,  430,  408,  399,  435,  657,  856,  856,  346,   57,
 /*   240 */   232,  828,  109,   20,  912,  912,  231,  393,  937,  760,
 /*   250 */    97,  751,  752,  833,   49,  708,  708,   93,   94,   84,
 /*   260 */   868,  871,  860,  860,   91,   91,   92,   92,   92,   92,
 /*   270 */   707,   90,   90,   90,   90,   89,   89,   88,   88,   88,
 /*   280 */    87,  335,  311,  114,   22,  706,  688,   58,  408,  390,
 /*   290 */   251,  349,  240,  749,  752,  689,  689,  847,  685,  115,
 /*   300 */    21,  231,  393,  689,  689,  697,  183,  355,  430,  384,
 /*   310 */   381,  380,  192,  856,  856,  780,  123,  160,  159,  223,
 /*   320 */   379,  738,   25,  315,  362,  841,  143,  689,  689,  835,
 /*   330 */   833,   48,  339,  937,   93,   94,   84,  868,  871,  860,
 /*   340 */   860,   91,   91,   92,   92,   92,   92,  914,   90,   90,
 /*   350 */    90,   90,   89,   89,   88,   88,   88,   87,  335,  311,
 /*   360 */   840,  840,  840,  266,  430,  690,  691,  778,  114, 1300,
 /*   370 */  1300,  430,    1,  690,  691,  697,  688,  689,  689,  689,
 /*   380 */   689,  689,  689,  287,  298,  780,  833,   10,  686,  115,
 /*   390 */   856,  856,  355,  833,   10,  828,  366,  690,  691,  363,
 /*   400 */   321,   76,  123,   74,   23,  737,  807,  323,  356,  353,
 /*   410 */   847,   93,   94,   84,  868,  871,  860,  860,   91,   91,
 /*   420 */    92,   92,   92,   92,  940,   90,   90,   90,   90,   89,
 /*   430 */    89,   88,   88,   88,   87,  335,  311,  806,  841,  429,
 /*   440 */   713,  941,  835,  430,  251,  354,  250,  690,  691,  690,
 /*   450 */   691,  690,  691,   86,   83,  166,   24,  942,  151,  753,
 /*   460 */   285,  907,  403,  907,  164,  833,   10,  856,  856,  965,
 /*   470 */   306,  754,  679,  840,  840,  840,  795,  216,  794,  222,
 /*   480 */   906,  344,  906,  904,   86,   83,  166,  286,   93,   94,
 /*   490 */    84,  868,  871,  860,  860,   91,   91,   92,   92,   92,
 /*   500 */    92,  430,   90,   90,   90,   90,   89,   89,   88,   88,
 /*   510 */    88,   87,  335,  311,  430,  724,  352,  705,  427,  699,
 /*   520 */   700,  376,  210,  833,   49,  793,  397,  857,  857,  940,
 /*   530 */   213,  762,  727,  334,  699,  700,  833,   10,   86,   83,
 /*   540 */   166,  345,  396,  902,  856,  856,  941,  385,  833,    9,
 /*   550 */   406,  869,  872,  187,  890,  728,  347,  398,  404,  977,
 /*   560 */   652,  338,  942,  954,  413,   93,   94,   84,  868,  871,
 /*   570 */   860,  860,   91,   91,   92,   92,   92,   92,  861,   90,
 /*   580 */    90,   90,   90,   89,   89,   88,   88,   88,   87,  335,
 /*   590 */   311, 1219,  114,  430,  834,  430,    5,  165,  192,  688,
 /*   600 */   832,  780,  430,  723,  430,  234,  325,  189,  163,  316,
 /*   610 */   356,  955,  115,  235,  269,  833,   35,  833,   36,  747,
 /*   620 */   720,  856,  856,  793,  833,   12,  833,   27,  745,  174,
 /*   630 */   968, 1290,  968, 1291, 1290,  310, 1291,  693,  317,  245,
 /*   640 */   264,  311,   93,   94,   84,  868,  871,  860,  860,   91,
 /*   650 */    91,   92,   92,   92,   92,  832,   90,   90,   90,   90,
 /*   660 */    89,   89,   88,   88,   88,   87,  335,  430,  320,  213,
 /*   670 */   762,  780,  856,  856,  920,  920,  369,  257,  966,  220,
 /*   680 */   966,  396,  663,  664,  665,  242,  259,  244,  262,  833,
 /*   690 */    37,  650,    2,   93,   94,   84,  868,  871,  860,  860,
 /*   700 */    91,   91,   92,   92,   92,   92,  430,   90,   90,   90,
 /*   710 */    90,   89,   89,   88,   88,   88,   87,  335,  311,  430,
 /*   720 */   239,  430,  917,  368,  430,  238,  916,  793,  833,   38,
 /*   730 */   430,  825,  430,   66,  430,  392,  430,  766,  766,  430,
 /*   740 */   367,  833,   39,  833,   28,  430,  833,   29,   68,  856,
 /*   750 */   856,  900,  833,   40,  833,   41,  833,   42,  833,   11,
 /*   760 */    72,  833,   43,  243,  305,  970,  114,  833,   99,  961,
 /*   770 */    93,   94,   84,  868,  871,  860,  860,   91,   91,   92,
 /*   780 */    92,   92,   92,  430,   90,   90,   90,   90,   89,   89,
 /*   790 */    88,   88,   88,   87,  335,  311,  430,  361,  430,  165,
 /*   800 */   147,  430,  186,  185,  184,  833,   44,  430,  289,  430,
 /*   810 */   246,  430,  971,  430,  212,  163,  430,  357,  833,   45,
 /*   820 */   833,   32,  932,  833,   46,  793,  856,  856,  718,  833,
 /*   830 */    47,  833,   33,  833,  117,  833,  118,   75,  833,  119,
 /*   840 */   288,  305,  967,  214,  935,  322,  311,   93,   94,   84,
 /*   850 */   868,  871,  860,  860,   91,   91,   92,   92,   92,   92,
 /*   860 */   430,   90,   90,   90,   90,   89,   89,   88,   88,   88,
 /*   870 */    87,  335,  430,  832,  426,  317,  288,  856,  856,  114,
 /*   880 */   763,  257,  833,   53,  930,  219,  364,  257,  257,  971,
 /*   890 */   361,  396,  257,  257,  833,   34,  257,  311,   93,   94,
 /*   900 */    84,  868,  871,  860,  860,   91,   91,   92,   92,   92,
 /*   910 */    92,  430,   90,   90,   90,   90,   89,   89,   88,   88,
 /*   920 */    88,   87,  335,  430,  217,  318,  124,  253,  856,  856,
 /*   930 */   218,  943,  257,  833,  100,  898,  759,  774,  361,  755,
 /*   940 */   423,  329,  758, 1017,  289,  833,   50,  682,  311,   93,
 /*   950 */    82,   84,  868,  871,  860,  860,   91,   91,   92,   92,
 /*   960 */    92,   92,  430,   90,   90,   90,   90,   89,   89,   88,
 /*   970 */    88,   88,   87,  335,  430,  256,  419,  114,  249,  856,
 /*   980 */   856,  331,  114,  400,  833,  101,  359,  187, 1064,  726,
 /*   990 */   725,  739,  401,  416,  420,  360,  833,  102,  424,  311,
 /*  1000 */   258,   94,   84,  868,  871,  860,  860,   91,   91,   92,
 /*  1010 */    92,   92,   92,  430,   90,   90,   90,   90,   89,   89,
 /*  1020 */    88,   88,   88,   87,  335,  430,  221,  261,  114,  114,
 /*  1030 */   856,  856,  808,  114,  156,  833,   98,  772,  733,  734,
 /*  1040 */   275,  809,  771,  316,  263,  265,  960,  833,  116,  307,
 /*  1050 */   741,  274,  722,   84,  868,  871,  860,  860,   91,   91,
 /*  1060 */    92,   92,   92,   92,  430,   90,   90,   90,   90,   89,
 /*  1070 */    89,   88,   88,   88,   87,  335,   80,  425,  830,    3,
 /*  1080 */  1214,  191,  430,  721,  336,  336,  833,  113,  252,   80,
 /*  1090 */   425,   68,    3,  913,  913,  428,  270,  336,  336,  430,
 /*  1100 */   377,  784,  430,  197,  833,  106,  430,  716,  428,  430,
 /*  1110 */   267,  430,  897,   68,  414,  430,  769,  409,  430,   71,
 /*  1120 */   430,  833,  105,  123,  833,  103,  847,  414,  833,   49,
 /*  1130 */   843,  833,  104,  833,   52,  800,  123,  833,   54,  847,
 /*  1140 */   833,   51,  833,   26,  831,  802,   77,   78,  191,  389,
 /*  1150 */   430,  372,  114,   79,  432,  431,  911,  911,  835,   77,
 /*  1160 */    78,  779,  893,  408,  410,  197,   79,  432,  431,  791,
 /*  1170 */   226,  835,  833,   30,  772,   80,  425,  716,    3,  771,
 /*  1180 */   411,  412,  897,  336,  336,  290,  291,  839,  703,  840,
 /*  1190 */   840,  840,  842,   19,  428,  695,  684,  672,  111,  671,
 /*  1200 */   843,  673,  840,  840,  840,  842,   19,  207,  661,  278,
 /*  1210 */   148,  304,  280,  414,  282,    6,  822,  348,  248,  241,
 /*  1220 */   358,  934,  720,   80,  425,  847,    3,  161,  382,  273,
 /*  1230 */   284,  336,  336,  415,  296,  958,  895,  894,  157,  674,
 /*  1240 */   107,  194,  428,  948,  135,   77,   78,  777,  953,  951,
 /*  1250 */    56,  319,   79,  432,  431,  121,   66,  835,   59,  128,
 /*  1260 */   146,  414,  350,  130,  351,  819,  131,  132,  133,  375,
 /*  1270 */   173,  149,  138,  847,  936,  365,  178,   70,  425,  827,
 /*  1280 */     3,  889,   62,  371,  915,  336,  336,  792,  840,  840,
 /*  1290 */   840,  842,   19,   77,   78,  208,  428,  144,  179,  373,
 /*  1300 */    79,  432,  431,  255,  180,  835,  260,  675,  181,  308,
 /*  1310 */   388,  744,  326,  743,  742,  414,  731,  718,  712,  402,
 /*  1320 */   309,  711,  788,   65,  277,  272,  789,  847,  730,  710,
 /*  1330 */   709,  279,  193,  787,  281,  876,  840,  840,  840,  842,
 /*  1340 */    19,  786,  283,   73,  418,  330,  422,   77,   78,  227,
 /*  1350 */    96,  407,   67,  405,   79,  432,  431,  292,  228,  835,
 /*  1360 */   215,  202,  229,  293,  767,  303,  302,  301,  204,  299,
 /*  1370 */   294,  295,  676,    7,  681,  433,  669,  206,  110,  224,
 /*  1380 */   203,  205,  434,  667,  666,  658,  120,  168,  656,  237,
 /*  1390 */   840,  840,  840,  842,   19,  337,  155,  233,  236,  341,
 /*  1400 */   167,  905,  108,  313,  903,  826,  314,  125,  126,  127,
 /*  1410 */   129,  170,  247,  756,  172,  928,  134,  136,  171,   60,
 /*  1420 */    61,  123,  169,  137,  175,  933,  176,  927,    8,   13,
 /*  1430 */   177,  254,  191,  918,  139,  370,  924,  140,  678,  150,
 /*  1440 */   374,  274,  182,  378,  141,  122,   63,   14,  383,  729,
 /*  1450 */   268,   15,   64,  225,  846,  845,  874,   16,  765,  770,
 /*  1460 */     4,  162,  209,  395,  211,  142,  878,  796,  801,  312,
 /*  1470 */   190,   71,   68,  875,  873,  939,  199,  938,   17,  195,
 /*  1480 */    18,  196,  417,  975,  152,  653,  976,  198,  153,  421,
 /*  1490 */   877,  154,  200,  844,  696,   81,  343,  297, 1019, 1018,
 /*  1500 */   300,
};
static const YYCODETYPE yy_lookahead[] = {
 /*     0 */    19,   22,   22,   23,    1,   24,   26,   15,   27,   80,
 /*     0 */    19,  144,  145,  146,  147,   24,    1,    2,   27,   80,
 /*    10 */    81,   82,   83,   84,   85,   86,   87,   88,   89,   90,
 /*    20 */    91,   92,   93,   94,   95,  108,  109,  110,   27,   28,
 /*    30 */    23,   50,   51,   80,   81,   82,   83,  122,   85,   86,
 /*    40 */    87,   88,   89,   90,   91,   92,   93,   94,   95,   22,
 /*    50 */    70,   23,   71,   72,   73,   74,   75,   76,   77,   78,
 /*    60 */    79,   80,   81,   82,   83,  122,   85,   86,   87,   88,
 /*    70 */    89,   90,   91,   92,   93,   94,   95,   19,   97,   91,
 /*    80 */    92,   93,   94,   95,   26,   85,   86,   87,   88,   89,
 /*    90 */    90,   91,   92,   93,   94,   95,   27,   28,   97,   98,
 /*   100 */    99,  122,  211,  102,  103,  104,   79,   19,   50,   51,
 /*   110 */    19,  122,   59,   55,  113,  224,  225,  226,   89,   90,
 /*   120 */    91,   92,   93,   94,   95,   23,   27,   28,   26,   71,
 /*    20 */    91,   92,   93,   94,   95,   91,   92,   93,   94,   95,
 /*    30 */    19,   50,   51,   80,   81,   82,   83,  212,   85,   86,
 /*    40 */    87,   88,   89,   90,   91,   92,   93,   94,   95,  224,
 /*    50 */   225,  226,   71,   72,   73,   74,   75,   76,   77,   78,
 /*    60 */    79,   80,   81,   82,   83,   95,   85,   86,   87,   88,
 /*    70 */    89,   90,   91,   92,   93,   94,   95,   19,   97,   85,
 /*    80 */    86,   87,   88,   89,   90,   91,   92,   93,   94,   95,
 /*    90 */    66,   33,   27,   28,   27,   28,   22,  201,  152,  152,
 /*   100 */    42,   27,  152,  224,  225,  226,   95,  211,   50,   51,
 /*   110 */    99,  100,  101,  102,  103,  104,  105,   27,   28,   59,
 /*   120 */   174,  175,  243,  112,  174,  175,   66,   94,   95,   71,
 /*   130 */    72,   73,   74,   75,   76,   77,   78,   79,   80,   81,
 /*   140 */    82,   83,   51,   85,   86,   87,   88,   89,   90,   91,
 /*   150 */    92,   93,   94,   95,   19,  132,  133,   58,   89,   90,
 /*   160 */    21,  108,  109,  110,   27,   28,   97,   98,   33,  100,
 /*   170 */     7,    8,  119,  120,   22,   19,  107,   42,  109,   27,
 /*   180 */    28,   27,   28,   95,   28,   50,   51,   99,  100,  101,
 /*   190 */   102,  103,  104,  105,   27,   28,   97,   98,  107,  152,
 /*   200 */   112,  132,  133,  112,   65,   69,   71,   72,   73,   74,
 /*   210 */    75,   76,   77,   78,   79,   80,   81,   82,   83,   11,
 /*   140 */    82,   83,  195,   85,   86,   87,   88,   89,   90,   91,
 /*   150 */    92,   93,   94,   95,   19,  209,   89,   90,  173,  209,
 /*   160 */   210,   26,   97,   98,   97,   98,  181,  100,  108,  109,
 /*   170 */   110,   97,  174,  152,  107,  152,  109,   89,   90,   91,
 /*   180 */    92,   93,   94,   95,  163,   50,   51,   97,   98,   99,
 /*   190 */    55,  244,  102,  103,  104,  174,  175,  174,  175,  132,
 /*   200 */   133,   89,   90,  113,   66,   19,   71,   72,   73,   74,
 /*   210 */    75,   76,   77,   78,   79,   80,   81,   82,   83,  198,
 /*   220 */    85,   86,   87,   88,   89,   90,   91,   92,   93,   94,
 /*   230 */    95,   19,  101,   97,   97,   98,   24,  101,  122,  157,
 /*   240 */    12,   99,  103,  112,  102,  103,  104,  152,   22,   97,
 /*   250 */    98,   97,   98,   27,   28,  113,   27,   29,   91,  164,
 /*   260 */   165,  124,   50,   51,   97,   98,  219,   59,  132,  133,
 /*   270 */   134,   22,   23,   45,   66,   47,  212,  213,  124,  140,
 /*   280 */   132,  133,   19,   71,   72,   73,   74,   75,   76,   77,
 /*   290 */    78,   79,   80,   81,   82,   83,  152,   85,   86,   87,
 /*   300 */    88,   89,   90,   91,   92,   93,   94,   95,  164,  165,
 /*   310 */    27,   28,  230,   50,   51,  233,  108,  109,  110,   70,
 /*   320 */    16,   59,   23,   97,   98,   26,   97,   22,   66,  185,
 /*   330 */    12,  187,   27,   28,   71,   72,   73,   74,   75,   76,
 /*   340 */    77,   78,   79,   80,   81,   82,   83,   29,   85,   86,
 /*   230 */    95,  152,  209,  210,  148,  149,   50,   51,  100,   53,
 /*   240 */   154,   59,  156,   22,  132,  133,  119,  120,  163,  163,
 /*   250 */    22,  192,  193,  174,  175,   27,   28,   71,   72,   73,
 /*   260 */    74,   75,   76,   77,   78,   79,   80,   81,   82,   83,
 /*   270 */   174,   85,   86,   87,   88,   89,   90,   91,   92,   93,
 /*   280 */    94,   95,   19,  198,  198,  174,  152,   24,  209,  210,
 /*   290 */   108,  109,  110,  192,  193,   27,   28,   69,  164,  165,
 /*   300 */    79,  119,  120,   27,   28,   27,   99,  222,  152,  102,
 /*   310 */   103,  104,   24,   50,   51,   27,   66,   89,   90,  185,
 /*   320 */   113,  187,   22,  157,  239,   97,   58,   27,   28,  101,
 /*   330 */   174,  175,  246,  163,   71,   72,   73,   74,   75,   76,
 /*   340 */    77,   78,   79,   80,   81,   82,   83,   11,   85,   86,
 /*   350 */    87,   88,   89,   90,   91,   92,   93,   94,   95,   19,
 /*   360 */    22,  148,  149,   45,   23,   47,   62,  154,   64,  156,
 /*   370 */   108,  109,  110,   37,   69,   23,  163,   59,   26,   26,
 /*   380 */    97,   98,  144,  145,  146,  147,  152,  200,   52,   23,
 /*   390 */    50,   51,   26,   22,   89,   90,   60,  210,    7,    8,
 /*   400 */     9,  138,   97,   22,   23,   26,  101,   26,  174,  175,
 /*   410 */   197,   71,   72,   73,   74,   75,   76,   77,   78,   79,
 /*   420 */    80,   81,   82,   83,   16,   85,   86,   87,   88,   89,
 /*   430 */    90,   91,   92,   93,   94,   95,   19,  132,  133,  134,
 /*   440 */    23,  152,  208,  209,  140,  152,  152,  111,  195,  196,
 /*   450 */    98,   70,  163,  160,  152,   23,   22,  164,  165,  246,
 /*   460 */   207,   27,  152,  174,  175,  171,  172,   50,   51,  137,
 /*   470 */    62,  139,   64,  171,  172,  222,  124,   27,  138,   24,
 /*   480 */   163,   89,   90,  130,  174,  175,  197,  163,   71,   72,
 /*   360 */   132,  133,  134,   23,  152,   97,   98,   91,  198,  119,
 /*   370 */   120,  152,   22,   97,   98,   97,  152,   27,   28,   27,
 /*   380 */    28,   27,   28,  227,  160,   97,  174,  175,  164,  165,
 /*   390 */    50,   51,  222,  174,  175,   59,  230,   97,   98,  233,
 /*   400 */   188,  137,   66,  139,  234,  187,  177,  188,  152,  239,
 /*   410 */    69,   71,   72,   73,   74,   75,   76,   77,   78,   79,
 /*   420 */    80,   81,   82,   83,   12,   85,   86,   87,   88,   89,
 /*   430 */    90,   91,   92,   93,   94,   95,   19,  177,   97,  152,
 /*   440 */    23,   29,  101,  152,  108,  109,  110,   97,   98,   97,
 /*   450 */    98,   97,   98,  224,  225,  226,   22,   45,   24,   47,
 /*   460 */   152,  152,  152,  152,  152,  174,  175,   50,   51,  249,
 /*   470 */   250,   59,   21,  132,  133,  134,  124,  221,  124,  188,
 /*   480 */   171,  172,  171,  172,  224,  225,  226,  152,   71,   72,
 /*   490 */    73,   74,   75,   76,   77,   78,   79,   80,   81,   82,
 /*   500 */    83,   22,   85,   86,   87,   88,   89,   90,   91,   92,
 /*   510 */    93,   94,   95,   19,  197,  181,  182,   23,  208,  209,
 /*   520 */   152,  197,   26,  189,  132,  133,  232,  224,  225,  226,
 /*   530 */   152,   97,   91,   26,  232,  116,  212,  213,  152,  222,
 /*   540 */   121,  152,  174,  175,   50,   51,  243,   97,   22,   23,
 /*   550 */    22,  234,  174,  175,  177,   23,  239,  116,  163,  177,
 /*   560 */   174,  175,  121,  174,  175,   71,   72,   73,   74,   75,
 /*   570 */    76,   77,   78,   79,   80,   81,   82,   83,   24,   85,
 /*   500 */    83,  152,   85,   86,   87,   88,   89,   90,   91,   92,
 /*   510 */    93,   94,   95,   19,  152,  183,   65,   23,  170,  171,
 /*   520 */   172,   19,   23,  174,  175,   26,  152,   50,   51,   12,
 /*   530 */   196,  197,   37,  170,  171,  172,  174,  175,  224,  225,
 /*   540 */   226,  232,  208,  232,   50,   51,   29,   52,  174,  175,
 /*   550 */   188,   74,   75,   51,  103,   60,  222,  163,  209,    0,
 /*   560 */     1,    2,   45,  152,   47,   71,   72,   73,   74,   75,
 /*   570 */    76,   77,   78,   79,   80,   81,   82,   83,  101,   85,
 /*   580 */    86,   87,   88,   89,   90,   91,   92,   93,   94,   95,
 /*   590 */    19,   23,  197,   11,   23,  227,   70,  208,  220,  152,
 /*   600 */    31,  224,  225,  226,   35,   98,  224,  225,  226,  108,
 /*   610 */   109,  110,  115,  152,  117,  118,   27,  222,   49,  123,
 /*   620 */    24,   50,   51,   27,    0,    1,    2,  224,  225,  226,
 /*   630 */   166,  124,  168,  169,  239,  174,  175,  170,  171,  172,
 /*   640 */    22,  194,   71,   72,   73,   74,   75,   76,   77,   78,
 /*   590 */    19,  140,  198,  152,   23,  152,   22,   98,   24,  152,
 /*   600 */   152,   27,  152,  183,  152,  152,  111,  213,  214,  107,
 /*   610 */   152,  164,  165,  152,  112,  174,  175,  174,  175,  181,
 /*   620 */   182,   50,   51,  124,  174,  175,  174,  175,  190,   26,
 /*   630 */    22,   23,   22,   23,   26,  166,   26,  168,  169,   16,
 /*   640 */    16,   19,   71,   72,   73,   74,   75,   76,   77,   78,
 /*   650 */    79,   80,   81,   82,   83,  152,   85,   86,   87,   88,
 /*   660 */    89,   90,   91,   92,   93,   94,   95,   19,   22,  208,
 /*   670 */    24,   23,  195,  196,  170,  171,  172,  174,  175,  152,
 /*   680 */    26,  152,  152,  152,  207,  152,   97,  152,   23,  152,
 /*   690 */    51,  244,  152,   97,  152,  247,  248,   23,   50,   51,
 /*   700 */    26,  174,  175,  174,  175,  174,  175,  174,  175,  174,
 /*   710 */   175,  174,  175,   23,  174,  175,  174,  175,  188,   71,
 /*   720 */    72,   73,   74,   75,   76,   77,   78,   79,   80,   81,
 /*   730 */    82,   83,  152,   85,   86,   87,   88,   89,   90,   91,
 /*   740 */    92,   93,   94,   95,   19,  152,  107,  152,   33,   24,
 /*   750 */   152,  100,  101,   27,  174,  175,  152,   42,  152,   23,
 /*   760 */   152,   26,  152,   23,  152,   26,  152,  174,  175,  174,
 /*   770 */   175,  152,  174,  175,   23,   50,   51,   26,  174,  175,
 /*   780 */   174,  175,  174,  175,  174,  175,  174,  175,  174,  175,
 /*   790 */   163,  119,  120,  174,  175,   19,   71,   72,   73,   74,
 /*   660 */    89,   90,   91,   92,   93,   94,   95,  152,  220,  196,
 /*   670 */   197,   97,   50,   51,  108,  109,  110,  152,   70,  221,
 /*   680 */    70,  208,    7,    8,    9,   62,   62,   64,   64,  174,
 /*   690 */   175,  146,  147,   71,   72,   73,   74,   75,   76,   77,
 /*   700 */    78,   79,   80,   81,   82,   83,  152,   85,   86,   87,
 /*   710 */    88,   89,   90,   91,   92,   93,   94,   95,   19,  152,
 /*   720 */   195,  152,   31,  220,  152,  152,   35,   26,  174,  175,
 /*   730 */   152,  163,  152,  130,  152,  115,  152,  117,  118,  152,
 /*   740 */    49,  174,  175,  174,  175,  152,  174,  175,   26,   50,
 /*   750 */    51,  152,  174,  175,  174,  175,  174,  175,  174,  175,
 /*   760 */   138,  174,  175,  140,   22,   23,  198,  174,  175,  152,
 /*   770 */    71,   72,   73,   74,   75,   76,   77,   78,   79,   80,
 /*   780 */    81,   82,   83,  152,   85,   86,   87,   88,   89,   90,
 /*   790 */    91,   92,   93,   94,   95,   19,  152,  152,  152,   98,
 /*   800 */    24,  152,  108,  109,  110,  174,  175,  152,  152,  152,
 /*   810 */   152,  152,   70,  152,  213,  214,  152,  152,  174,  175,
 /*   820 */   174,  175,  152,  174,  175,  124,   50,   51,  106,  174,
 /*   830 */   175,  174,  175,  174,  175,  174,  175,  138,  174,  175,
 /*   840 */   152,   22,   23,   22,  163,  189,   19,   71,   72,   73,
 /*   800 */    75,   76,   77,   78,   79,   80,   81,   82,   83,  152,
 /*   810 */    85,   86,   87,   88,   89,   90,   91,   92,   93,   94,
 /*   820 */    95,   66,  152,   97,  197,   23,   50,   51,   26,   53,
 /*   830 */    23,  174,  175,   26,   23,   23,   23,   26,   26,   26,
 /*   840 */    36,  106,  146,  147,  174,  175,   19,   71,   72,   73,
 /*   850 */    74,   75,   76,   77,   78,   79,   80,   81,   82,   83,
 /*   860 */   152,   85,   86,   87,   88,   89,   90,   91,   92,   93,
 /*   870 */    94,   95,  152,  196,  119,  120,   19,   50,   51,  168,
 /*   880 */   169,   26,  174,  175,  207,   28,  152,  249,  250,  152,
 /*   890 */   163,  163,  163,  163,  174,  175,  163,   19,   71,   72,
 /*   870 */    94,   95,  152,  152,  168,  169,  152,   50,   51,  198,
 /*   880 */   197,  152,  174,  175,  152,  240,  152,  152,  152,   70,
 /*   890 */   152,  208,  152,  152,  174,  175,  152,   19,   71,   72,
 /*   900 */    73,   74,   75,   76,   77,   78,   79,   80,   81,   82,
 /*   910 */    83,  152,   85,   86,   87,   88,   89,   90,   91,   92,
 /*   920 */    93,   94,   95,  152,  197,  197,  197,  197,   50,   51,
 /*   930 */   197,  194,   36,  174,  175,  191,  192,  152,  191,  192,
 /*   940 */   163,  152,   66,  124,  152,  174,  175,  152,   19,   71,
 /*   920 */    93,   94,   95,  152,  195,  247,  248,  152,   50,   51,
 /*   930 */   195,  195,  152,  174,  175,  195,  195,   26,  152,  195,
 /*   940 */   252,  220,  163,  122,  152,  174,  175,  163,   19,   71,
 /*   950 */    72,   73,   74,   75,   76,   77,   78,   79,   80,   81,
 /*   960 */    82,   83,  152,   85,   86,   87,   88,   89,   90,   91,
 /*   970 */    92,   93,   94,   95,  197,  152,  100,  188,  152,   50,
 /*   980 */    51,  152,  152,  188,  174,  175,  252,  152,   94,   95,
 /*   990 */   152,  152,  152,    1,    2,  152,  152,  174,  175,   19,
 /*   970 */    92,   93,   94,   95,  152,  195,  252,  198,  240,   50,
 /*   980 */    51,  189,  198,   19,  174,  175,   19,   51,   23,  100,
 /*   990 */   101,   26,   28,  163,  163,   28,  174,  175,  163,   19,
 /*  1000 */   152,   72,   73,   74,   75,   76,   77,   78,   79,   80,
 /*  1010 */    81,   82,   83,  152,   85,   86,   87,   88,   89,   90,
 /*  1020 */    91,   92,   93,   94,   95,  152,  188,  188,   22,  194,
 /*  1030 */    50,   51,  240,  173,  194,  174,  175,  252,  194,  152,
 /*  1040 */    36,  181,   28,  152,   23,  219,  122,  174,  175,  219,
 /*  1050 */   221,  152,  152,   73,   74,   75,   76,   77,   78,   79,
 /*  1020 */    91,   92,   93,   94,   95,  152,  240,  152,  198,  198,
 /*  1030 */    50,   51,   33,  198,  123,  174,  175,  116,    7,    8,
 /*  1040 */   101,   42,  121,  107,  152,  152,   23,  174,  175,   26,
 /*  1050 */   152,  112,  183,   73,   74,   75,   76,   77,   78,   79,
 /*  1060 */    80,   81,   82,   83,  152,   85,   86,   87,   88,   89,
 /*  1070 */    90,   91,   92,   93,   94,   95,   19,   20,  152,   22,
 /*  1080 */    23,  194,  152,  240,   27,   28,  174,  175,  240,   19,
 /*  1090 */    20,   26,   22,  194,  194,   38,   22,   27,   28,  152,
 /*  1100 */    23,   22,  152,  116,  174,  175,  152,   23,   38,  152,
 /*  1110 */    23,  152,  221,  152,   57,  152,   23,  163,   50,   51,
 /*  1120 */   194,  174,  175,   66,  174,  175,   69,   57,  174,  175,
 /*  1130 */    40,  174,  175,  174,  175,  174,  175,  174,  175,   69,
 /*  1140 */    22,   53,   74,   75,   30,   53,   89,   90,   22,   22,
 /*  1150 */   152,  197,   23,   96,   97,   98,   22,  152,  101,   89,
 /*  1160 */    90,   91,  208,  209,  152,   53,   96,   97,   98,  101,
 /*  1170 */    22,  101,  174,  175,  152,   19,   20,  105,   22,  174,
 /*  1180 */   175,  112,   19,   27,   28,   20,  174,  175,   24,  132,
 /*  1190 */   133,  134,  135,  136,   38,   44,  174,  175,  107,   61,
 /*  1200 */    54,   26,  132,  133,  134,  135,  136,   54,  107,   22,
 /*  1210 */     5,  140,    1,   57,   36,  111,  122,   28,   79,   79,
 /*  1220 */   131,  123,   66,   19,   20,   69,   22,    1,   16,   20,
 /*  1230 */   125,   27,   28,  123,  111,  120,   23,  131,   23,   16,
 /*  1240 */    68,  142,   38,   15,   22,   89,   90,    3,  167,    4,
 /*  1250 */   248,  251,   96,   97,   98,  180,  180,  101,  251,  151,
 /*  1260 */     6,   57,  151,   13,  151,   26,   25,  151,  161,  202,
 /*  1270 */   153,  162,  153,   69,  130,  128,  203,   19,   20,  127,
 /*  1280 */    22,  126,  204,  129,   22,   27,   28,  205,  132,  133,
 /*  1290 */   134,  135,  136,   89,   90,  231,   38,   95,  137,  179,
 /*  1300 */    96,   97,   98,  206,  179,  101,  122,  107,  159,  159,
 /*  1310 */   125,  231,  216,  228,  107,   57,  184,  217,  216,  176,
 /*  1320 */   217,  176,   48,  106,   18,  184,  158,   69,  159,  158,
 /*  1330 */    46,   71,  237,  176,  176,  176,  132,  133,  134,  135,
 /*  1340 */   136,  217,  176,  137,  216,  178,  158,   89,   90,  179,
 /*  1350 */   176,  159,  179,  159,   96,   97,   98,  159,  159,  101,
 /*  1360 */     5,  158,  202,   22,   18,   10,   11,   12,   13,   14,
 /*  1370 */   190,  238,   17,  190,  158,  193,   41,  159,  202,  193,
 /*  1380 */   159,  202,  245,  193,  193,  223,  190,   32,  159,   34,
 /*  1390 */   132,  133,  134,  135,  136,  159,   39,  155,   43,  150,
 /*  1400 */   223,  177,  201,  178,  177,  186,   66,  199,  177,  152,
 /*  1410 */   253,   56,  215,  152,  182,  152,  202,  152,   63,  152,
 /*  1420 */   152,   66,   67,  242,  229,  152,  174,  152,  152,  152,
 /*  1430 */   152,  152,  152,  152,  199,  242,  202,  152,  198,  152,
 /*  1440 */   152,  152,  183,  192,  152,  215,  152,  183,  215,  183,
 /*  1450 */   152,  241,  214,  152,  211,  152,  152,  211,  211,  152,
 /*  1460 */   152,  241,  152,  152,  152,  152,  152,  152,  152,  114,
 /*  1470 */   152,  152,  235,  152,  152,  152,  174,  187,   95,  174,
 /*  1480 */   253,  253,  253,  253,  236,  253,  253,  253,  253,  253,
 /*  1490 */   253,  253,  253,  253,  253,  253,  141,
 /*  1070 */    90,   91,   92,   93,   94,   95,   19,   20,   23,   22,
 /*  1080 */    23,   26,  152,  152,   27,   28,  174,  175,   23,   19,
 /*  1090 */    20,   26,   22,  132,  133,   38,  152,   27,   28,  152,
 /*  1100 */    23,  215,  152,   26,  174,  175,  152,   27,   38,  152,
 /*  1110 */    23,  152,   27,   26,   57,  152,   23,  163,  152,   26,
 /*  1120 */   152,  174,  175,   66,  174,  175,   69,   57,  174,  175,
 /*  1130 */    27,  174,  175,  174,  175,  152,   66,  174,  175,   69,
 /*  1140 */   174,  175,  174,  175,  152,   23,   89,   90,   26,   91,
 /*  1150 */   152,  236,  198,   96,   97,   98,  132,  133,  101,   89,
 /*  1160 */    90,  152,   23,  209,  210,   26,   96,   97,   98,  152,
 /*  1170 */   212,  101,  174,  175,  116,   19,   20,   97,   22,  121,
 /*  1180 */   152,  193,   97,   27,   28,  152,  152,  152,  152,  132,
 /*  1190 */   133,  134,  135,  136,   38,   23,  152,  152,   26,  152,
 /*  1200 */    97,  152,  132,  133,  134,  135,  136,  235,  152,  212,
 /*  1210 */   199,  150,  212,   57,  212,  200,  203,  216,  241,  216,
 /*  1220 */   241,  203,  182,   19,   20,   69,   22,  186,  178,  177,
 /*  1230 */   216,   27,   28,  229,  202,   39,  177,  177,  200,  155,
 /*  1240 */   245,  122,   38,   41,   22,   89,   90,   91,  159,  159,
 /*  1250 */   242,  159,   96,   97,   98,   71,  130,  101,  242,  191,
 /*  1260 */   223,   57,   18,  194,  159,  203,  194,  194,  194,   18,
 /*  1270 */   158,  223,  191,   69,  203,  159,  158,   19,   20,  191,
 /*  1280 */    22,  203,  137,   46,  238,   27,   28,  159,  132,  133,
 /*  1290 */   134,  135,  136,   89,   90,  159,   38,   22,  158,  179,
 /*  1300 */    96,   97,   98,  237,  158,  101,  159,  159,  158,  179,
 /*  1310 */   107,  176,   48,  176,  176,   57,  184,  106,  176,  125,
 /*  1320 */   179,  178,  218,  107,  217,  176,  218,   69,  184,  176,
 /*  1330 */   176,  217,  159,  218,  217,  159,  132,  133,  134,  135,
 /*  1340 */   136,  218,  217,  137,  179,   95,  179,   89,   90,  228,
 /*  1350 */   129,  126,  128,  127,   96,   97,   98,  206,  231,  101,
 /*  1360 */     5,   25,  231,  205,  207,   10,   11,   12,   13,   14,
 /*  1370 */   204,  203,   17,   26,  162,  161,   13,    6,  180,  180,
 /*  1380 */   153,  153,  151,  151,  151,  151,  167,   32,    4,   34,
 /*  1390 */   132,  133,  134,  135,  136,    3,   22,  142,   43,   68,
 /*  1400 */    15,   23,   16,  251,   23,  120,  251,  248,  131,  111,
 /*  1410 */   123,   56,   16,   20,  125,    1,  123,  131,   63,   79,
 /*  1420 */    79,   66,   67,  111,   36,   28,  122,    1,    5,   22,
 /*  1430 */   107,  140,   26,   54,   54,   44,   61,  107,   20,   24,
 /*  1440 */    19,  112,  105,   53,   22,   40,   22,   22,   53,   30,
 /*  1450 */    23,   22,   22,   53,   23,   23,   23,   22,  116,   23,
 /*  1460 */    22,  122,   23,   26,   23,   22,   11,  124,   28,  114,
 /*  1470 */    36,   26,   26,   23,   23,   23,  122,   23,   36,   26,
 /*  1480 */    36,   22,   24,   23,   22,    1,   23,   26,   22,   24,
 /*  1490 */    23,   22,  122,   23,   23,   22,  141,   23,  122,  122,
 /*  1500 */    15,
};
#define YY_SHIFT_USE_DFLT (-86)
#define YY_SHIFT_COUNT (429)
#define YY_SHIFT_MIN   (-85)
#define YY_SHIFT_MAX   (1383)
#define YY_SHIFT_USE_DFLT (-72)
#define YY_SHIFT_COUNT (435)
#define YY_SHIFT_MIN   (-71)
#define YY_SHIFT_MAX   (1485)
static const short yy_shift_ofst[] = {
 /*     0 */   992, 1057, 1355, 1156, 1204, 1204,    1,  262,  -19,  135,
 /*    10 */   135,  776, 1204, 1204, 1204, 1204,   69,   69,   53,  208,
 /*    20 */   283,  755,   58,  725,  648,  571,  494,  417,  340,  263,
 /*    30 */   212,  827,  827,  827,  827,  827,  827,  827,  827,  827,
 /*    40 */   827,  827,  827,  827,  827,  827,  878,  827,  929,  980,
 /*    50 */   980, 1070, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
 /*     0 */     5, 1057, 1355, 1070, 1204, 1204, 1204,   90,   60,  -19,
 /*    10 */    58,   58,  186, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
 /*    20 */    67,   67,  182,  336,   65,  250,  135,  263,  340,  417,
 /*    30 */   494,  571,  622,  699,  776,  827,  827,  827,  827,  827,
 /*    40 */   827,  827,  827,  827,  827,  827,  827,  827,  827,  827,
 /*    50 */   878,  827,  929,  980,  980, 1156, 1204, 1204, 1204, 1204,
 /*    60 */  1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
 /*    70 */  1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
 /*    80 */  1258, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
 /*    90 */  1204, 1204, 1204, 1204,  -71,  -47,  -47,  -47,  -47,  -47,
 /*   100 */     0,   29,  -12,  283,  283,  139,   91,  392,  392,  894,
 /*   110 */   672,  726, 1383,  -86,  -86,  -86,   88,  318,  318,   99,
 /*   120 */   381,  -20,  283,  283,  283,  283,  283,  283,  283,  283,
 /*   130 */   283,  283,  283,  283,  283,  283,  283,  283,  283,  283,
 /*   140 */   283,  283,  283,  283,  624,  876,  726,  672, 1340, 1340,
 /*   150 */  1340, 1340, 1340, 1340,  -86,  -86,  -86,  305,  136,  136,
 /*   160 */   142,  167,  226,  154,  137,  152,  283,  283,  283,  283,
 /*   170 */   283,  283,  283,  283,  283,  283,  283,  283,  283,  283,
 /*   180 */   283,  283,  283,  336,  336,  336,  283,  283,  352,  283,
 /*   190 */   283,  283,  283,  283,  228,  283,  283,  283,  283,  283,
 /*   200 */   283,  283,  283,  283,  283,  501,  569,  596,  596,  596,
 /*   210 */   507,  497,  441,  391,  353,  156,  156,  857,  353,  857,
 /*   220 */   735,  813,  639,  715,  156,  332,  715,  715,  496,  419,
 /*   230 */   646, 1357, 1184, 1184, 1335, 1335, 1184, 1341, 1260, 1144,
 /*   240 */  1346, 1346, 1346, 1346, 1184, 1306, 1144, 1341, 1260, 1260,
 /*   250 */  1144, 1184, 1306, 1206, 1284, 1184, 1184, 1306, 1184, 1306,
 /*   260 */  1184, 1306, 1262, 1207, 1207, 1207, 1274, 1262, 1207, 1217,
 /*   270 */  1207, 1274, 1207, 1207, 1185, 1200, 1185, 1200, 1185, 1200,
 /*   280 */  1184, 1184, 1161, 1262, 1202, 1202, 1262, 1154, 1155, 1147,
 /*   290 */  1152, 1144, 1241, 1239, 1250, 1250, 1254, 1254, 1254, 1254,
 /*   300 */   -86,  -86,  -86,  -86,  -86,  -86, 1068,  304,  526,  249,
 /*   310 */   408,  -83,  434,  812,   27,  811,  807,  802,  751,  589,
 /*   320 */   651,  163,  131,  674,  366,  450,  299,  148,   23,  102,
 /*   330 */   229,  -21, 1245, 1244, 1222, 1099, 1228, 1172, 1223, 1215,
 /*   340 */  1213, 1115, 1106, 1123, 1110, 1209, 1105, 1212, 1226, 1098,
 /*   350 */  1089, 1140, 1139, 1104, 1189, 1178, 1094, 1211, 1205, 1187,
 /*   360 */  1101, 1071, 1153, 1175, 1146, 1138, 1151, 1091, 1164, 1165,
 /*   370 */  1163, 1069, 1072, 1148, 1112, 1134, 1127, 1129, 1126, 1092,
 /*   380 */  1114, 1118, 1088, 1090, 1093, 1087, 1084,  987, 1079, 1077,
 /*   390 */  1074, 1065,  924, 1021, 1014, 1004, 1006,  819,  739,  896,
 /*   400 */   855,  804,  739,  740,  736,  690,  654,  665,  618,  582,
 /*   410 */   568,  528,  554,  379,  532,  479,  455,  379,  432,  371,
 /*   420 */   341,   28,  338,  116,  -11,  -57,  -85,    7,   -8,    3,
 /*    80 */  1204, 1204, 1204, 1204, 1258, 1204, 1204, 1204, 1204, 1204,
 /*    90 */  1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,  -71,  -47,
 /*   100 */   -47,  -47,  -47,  -47,   -6,   88,  -66,   65,   65,  451,
 /*   110 */   502,  112,  112,   33,  127,  278,  -30,  -72,  -72,  -72,
 /*   120 */    11,  412,  412,  268,  608,  610,   65,   65,   65,   65,
 /*   130 */    65,   65,   65,   65,   65,   65,   65,   65,   65,   65,
 /*   140 */    65,   65,   65,   65,   65,  559,  138,  278,  127,   24,
 /*   150 */    24,   24,   24,   24,   24,  -72,  -72,  -72,  228,  341,
 /*   160 */   341,  207,  276,  300,  352,  354,  350,   65,   65,   65,
 /*   170 */    65,   65,   65,   65,   65,   65,   65,   65,   65,   65,
 /*   180 */    65,   65,   65,   65,  495,  495,  495,   65,   65,  499,
 /*   190 */    65,   65,   65,  574,   65,   65,  517,   65,   65,   65,
 /*   200 */    65,   65,   65,   65,   65,   65,   65,  566,  691,  288,
 /*   210 */   288,  288,  701,  620, 1058,  675,  603,  964,  964,  967,
 /*   220 */   603,  967,  722,  965,  936,  999,  964,  264,  999,  999,
 /*   230 */   911,  921,  434, 1196, 1119, 1119, 1202, 1202, 1119, 1222,
 /*   240 */  1184, 1126, 1244, 1244, 1244, 1244, 1119, 1251, 1126, 1222,
 /*   250 */  1184, 1184, 1126, 1119, 1251, 1145, 1237, 1119, 1119, 1251,
 /*   260 */  1275, 1119, 1251, 1119, 1251, 1275, 1203, 1203, 1203, 1264,
 /*   270 */  1275, 1203, 1211, 1203, 1264, 1203, 1203, 1194, 1216, 1194,
 /*   280 */  1216, 1194, 1216, 1194, 1216, 1119, 1119, 1206, 1275, 1250,
 /*   290 */  1250, 1275, 1221, 1225, 1224, 1226, 1126, 1336, 1347, 1363,
 /*   300 */  1363, 1371, 1371, 1371, 1371,  -72,  -72,  -72,  -72,  -72,
 /*   310 */   -72,  477,  623,  742,  819,  624,  694,   74, 1023,  221,
 /*   320 */  1055, 1065, 1077, 1087, 1080,  889, 1031,  939, 1093, 1122,
 /*   330 */  1085, 1139,  961, 1024, 1172, 1103,  821, 1384, 1392, 1374,
 /*   340 */  1255, 1385, 1331, 1386, 1378, 1381, 1285, 1277, 1298, 1287,
 /*   350 */  1393, 1289, 1396, 1414, 1293, 1286, 1340, 1341, 1312, 1397,
 /*   360 */  1388, 1304, 1426, 1423, 1407, 1323, 1291, 1379, 1406, 1380,
 /*   370 */  1375, 1391, 1330, 1415, 1418, 1421, 1329, 1337, 1422, 1390,
 /*   380 */  1424, 1425, 1427, 1429, 1395, 1419, 1430, 1400, 1405, 1431,
 /*   390 */  1432, 1433, 1342, 1435, 1436, 1438, 1437, 1339, 1439, 1441,
 /*   400 */  1440, 1434, 1443, 1343, 1445, 1442, 1446, 1444, 1445, 1450,
 /*   410 */  1451, 1452, 1453, 1454, 1459, 1455, 1460, 1462, 1458, 1461,
 /*   420 */  1463, 1466, 1465, 1461, 1467, 1469, 1470, 1471, 1473, 1354,
 /*   430 */  1370, 1376, 1377, 1474, 1485, 1484,
};
#define YY_REDUCE_USE_DFLT (-110)
#define YY_REDUCE_COUNT (305)
#define YY_REDUCE_MIN   (-109)
#define YY_REDUCE_MAX   (1323)
#define YY_REDUCE_USE_DFLT (-176)
#define YY_REDUCE_COUNT (310)
#define YY_REDUCE_MIN   (-175)
#define YY_REDUCE_MAX   (1234)
static const short yy_reduce_ofst[] = {
 /*     0 */   238,  954,  213,  289,  310,  234,  144,  317, -109,  382,
 /*    10 */   377,  303,  461,  389,  378,  368,  302,  294,  253,  395,
 /*    20 */   293,  324,  403,  403,  403,  403,  403,  403,  403,  403,
 /*    30 */   403,  403,  403,  403,  403,  403,  403,  403,  403,  403,
 /*    40 */   403,  403,  403,  403,  403,  403,  403,  403,  403,  403,
 /*    50 */   403, 1022, 1012, 1005,  998,  963,  961,  959,  957,  950,
 /*    60 */   947,  930,  912,  873,  861,  823,  810,  771,  759,  720,
 /*    70 */   708,  670,  657,  619,  614,  612,  610,  608,  606,  604,
 /*    80 */   598,  595,  593,  580,  542,  540,  537,  535,  533,  531,
 /*    90 */   529,  527,  503,  386,  403,  403,  403,  403,  403,  403,
 /*   100 */   403,  403,  403,   95,  447,   82,  334,  504,  467,  403,
 /*   110 */   477,  464,  403,  403,  403,  403,  860,  747,  744,  785,
 /*   120 */   638,  638,  926,  891,  900,  899,  887,  844,  840,  835,
 /*   130 */   848,  830,  843,  829,  792,  839,  826,  737,  838,  795,
 /*   140 */   789,   47,  734,  530,  696,  777,  711,  677,  733,  730,
 /*   150 */   729,  728,  727,  627,  448,   64,  187, 1305, 1302, 1252,
 /*   160 */  1290, 1273, 1323, 1322, 1321, 1319, 1318, 1316, 1315, 1314,
 /*   170 */  1313, 1312, 1311, 1310, 1308, 1307, 1304, 1303, 1301, 1298,
 /*   180 */  1294, 1292, 1289, 1266, 1264, 1259, 1288, 1287, 1238, 1285,
 /*   190 */  1281, 1280, 1279, 1278, 1251, 1277, 1276, 1275, 1273, 1268,
 /*   200 */  1267, 1265, 1263, 1261, 1257, 1248, 1237, 1247, 1246, 1243,
 /*   210 */  1238, 1240, 1235, 1249, 1234, 1233, 1230, 1220, 1214, 1210,
 /*   220 */  1225, 1219, 1232, 1231, 1197, 1195, 1227, 1224, 1201, 1208,
 /*   230 */  1242, 1137, 1236, 1229, 1193, 1181, 1221, 1177, 1196, 1179,
 /*   240 */  1191, 1190, 1186, 1182, 1218, 1216, 1176, 1162, 1183, 1180,
 /*   250 */  1160, 1199, 1203, 1133, 1095, 1198, 1194, 1188, 1192, 1171,
 /*   260 */  1169, 1168, 1173, 1174, 1166, 1159, 1141, 1170, 1158, 1167,
 /*   270 */  1157, 1132, 1145, 1143, 1124, 1128, 1103, 1102, 1100, 1096,
 /*   280 */  1150, 1149, 1085, 1125, 1080, 1064, 1120, 1097, 1082, 1078,
 /*   290 */  1073, 1067, 1109, 1107, 1119, 1117, 1116, 1113, 1111, 1108,
 /*   300 */  1007, 1000, 1002, 1076, 1075, 1081,
 /*     0 */  -143,  954,   86,   21,  -50,   23,   79,  134,  170, -175,
 /*    10 */   229,  260, -121,  212,  219,  291,  -54,  349,  362,  156,
 /*    20 */   309,  311,  334,   85,  224,  394,  314,  314,  314,  314,
 /*    30 */   314,  314,  314,  314,  314,  314,  314,  314,  314,  314,
 /*    40 */   314,  314,  314,  314,  314,  314,  314,  314,  314,  314,
 /*    50 */   314,  314,  314,  314,  314,  374,  441,  443,  450,  452,
 /*    60 */   515,  554,  567,  569,  572,  578,  580,  582,  584,  587,
 /*    70 */   593,  631,  644,  646,  649,  655,  657,  659,  661,  664,
 /*    80 */   708,  720,  759,  771,  810,  822,  861,  873,  912,  930,
 /*    90 */   947,  950,  957,  959,  963,  966,  968,  998,  314,  314,
 /*   100 */   314,  314,  314,  314,  314,  314,  314,  447,  -53,  166,
 /*   110 */   438,  348,  363,  314,  473,  469,  314,  314,  314,  314,
 /*   120 */   -15,   59,  101,  688,  220,  220,  525,  256,  729,  735,
 /*   130 */   736,  740,  741,  744,  645,  448,  738,  458,  786,  503,
 /*   140 */   780,  656,  721,  724,  792,  545,  568,  706,  683,  681,
 /*   150 */   779,  784,  830,  831,  835,  678,  601, -104,   -2,   96,
 /*   160 */   111,  218,  287,  308,  310,  312,  335,  411,  453,  461,
 /*   170 */   573,  599,  617,  658,  665,  670,  732,  734,  775,  848,
 /*   180 */   875,  892,  893,  898,  332,  420,  869,  931,  944,  886,
 /*   190 */   983,  992, 1009,  958, 1017, 1028,  988, 1033, 1034, 1035,
 /*   200 */   287, 1036, 1044, 1045, 1047, 1049, 1056,  915,  972,  997,
 /*   210 */  1000, 1002,  886, 1011, 1015, 1061, 1013, 1001, 1003,  977,
 /*   220 */  1018,  979, 1050, 1041, 1040, 1052, 1014, 1004, 1059, 1060,
 /*   230 */  1032, 1038, 1084,  995, 1089, 1090, 1008, 1016, 1092, 1037,
 /*   240 */  1068, 1062, 1069, 1072, 1073, 1074, 1105, 1112, 1071, 1048,
 /*   250 */  1081, 1088, 1078, 1116, 1118, 1046, 1066, 1128, 1136, 1140,
 /*   260 */  1120, 1147, 1146, 1148, 1150, 1130, 1135, 1137, 1138, 1132,
 /*   270 */  1141, 1142, 1143, 1149, 1144, 1153, 1154, 1104, 1107, 1108,
 /*   280 */  1114, 1115, 1117, 1123, 1125, 1173, 1176, 1121, 1165, 1127,
 /*   290 */  1131, 1167, 1157, 1151, 1158, 1166, 1168, 1212, 1214, 1227,
 /*   300 */  1228, 1231, 1232, 1233, 1234, 1152, 1155, 1159, 1198, 1199,
 /*   310 */  1219,
};
static const YYACTIONTYPE yy_default[] = {
 /*     0 */   647,  964,  964,  964,  878,  878,  969,  964,  774,  802,
 /*    10 */   802,  938,  969,  969,  969,  876,  969,  969,  969,  964,
 /*    20 */   969,  778,  808,  969,  969,  969,  969,  969,  969,  969,
 /*    30 */   969,  937,  939,  816,  815,  918,  789,  813,  806,  810,
 /*    40 */   879,  872,  873,  871,  875,  880,  969,  809,  841,  856,
 /*    50 */   840,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*    60 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*    70 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*    80 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*    90 */   969,  969,  969,  969,  850,  855,  862,  854,  851,  843,
 /*   100 */   842,  844,  845,  969,  969,  673,  739,  969,  969,  846,
 /*   110 */   969,  685,  847,  859,  858,  857,  680,  969,  969,  969,
 /*   120 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*   130 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*   140 */   969,  969,  969,  969,  647,  964,  969,  969,  964,  964,
 /*   150 */   964,  964,  964,  964,  956,  778,  768,  969,  969,  969,
 /*   160 */   969,  969,  969,  969,  969,  969,  969,  944,  942,  969,
 /*   170 */   891,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*   180 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*   190 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*   200 */   969,  969,  969,  969,  653,  969,  911,  774,  774,  774,
 /*   210 */   776,  754,  766,  655,  812,  791,  791,  923,  812,  923,
 /*     0 */   982, 1300, 1300, 1300, 1214, 1214, 1214, 1305, 1300, 1109,
 /*    10 */  1138, 1138, 1274, 1305, 1305, 1305, 1305, 1305, 1305, 1212,
 /*    20 */  1305, 1305, 1305, 1300, 1305, 1113, 1144, 1305, 1305, 1305,
 /*    30 */  1305, 1305, 1305, 1305, 1305, 1273, 1275, 1152, 1151, 1254,
 /*    40 */  1125, 1149, 1142, 1146, 1215, 1208, 1209, 1207, 1211, 1216,
 /*    50 */  1305, 1145, 1177, 1192, 1176, 1305, 1305, 1305, 1305, 1305,
 /*    60 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*    70 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*    80 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*    90 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1186, 1191,
 /*   100 */  1198, 1190, 1187, 1179, 1178, 1180, 1181, 1305, 1305, 1008,
 /*   110 */  1074, 1305, 1305, 1182, 1305, 1020, 1183, 1195, 1194, 1193,
 /*   120 */  1015, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*   130 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*   140 */  1305, 1305, 1305, 1305, 1305,  982, 1300, 1305, 1305, 1300,
 /*   150 */  1300, 1300, 1300, 1300, 1300, 1292, 1113, 1103, 1305, 1305,
 /*   160 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1280, 1278,
 /*   170 */  1305, 1227, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*   180 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*   190 */  1305, 1305, 1305, 1109, 1305, 1305, 1305, 1305, 1305, 1305,
 /*   200 */  1305, 1305, 1305, 1305, 1305, 1305,  988, 1305, 1247, 1109,
 /*   210 */  1109, 1109, 1111, 1089, 1101,  990, 1148, 1127, 1127, 1259,
 /*   220 */   710,  733,  707,  802,  791,  874,  802,  802,  775,  766,
 /*   230 */   969,  949,  782,  782,  941,  941,  782,  821,  743,  812,
 /*   240 */   750,  750,  750,  750,  782,  670,  812,  821,  743,  743,
 /*   250 */   812,  782,  670,  917,  915,  782,  782,  670,  782,  670,
 /*   260 */   782,  670,  884,  741,  741,  741,  725,  884,  741,  710,
 /*   270 */   741,  725,  741,  741,  795,  790,  795,  790,  795,  790,
 /*   280 */   782,  782,  969,  884,  888,  888,  884,  807,  796,  805,
 /*   290 */   803,  812,  676,  728,  663,  663,  652,  652,  652,  652,
 /*   300 */   961,  961,  956,  712,  712,  695,  969,  969,  969,  969,
 /*   310 */   969,  969,  687,  969,  893,  969,  969,  969,  969,  969,
 /*   320 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*   330 */   969,  828,  969,  648,  951,  969,  969,  948,  969,  969,
 /*   340 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*   350 */   969,  969,  969,  969,  969,  969,  921,  969,  969,  969,
 /*   360 */   969,  969,  969,  914,  913,  969,  969,  969,  969,  969,
 /*   370 */   969,  969,  969,  969,  969,  969,  969,  969,  969,  969,
 /*   380 */   969,  969,  969,  969,  969,  969,  969,  757,  969,  969,
 /*   390 */   969,  761,  969,  969,  969,  969,  969,  969,  804,  969,
 /*   400 */   797,  969,  877,  969,  969,  969,  969,  969,  969,  969,
 /*   410 */   969,  969,  969,  966,  969,  969,  969,  965,  969,  969,
 /*   420 */   969,  969,  969,  830,  969,  829,  833,  969,  661,  969,
 /*   430 */   644,  649,  960,  963,  962,  959,  958,  957,  952,  950,
 /*   440 */   947,  946,  945,  943,  940,  936,  897,  895,  902,  901,
 /*   450 */   900,  899,  898,  896,  894,  892,  818,  817,  814,  811,
 /*   460 */   753,  935,  890,  752,  749,  748,  669,  953,  920,  929,
 /*   470 */   928,  927,  822,  926,  925,  924,  922,  919,  906,  820,
 /*   480 */   819,  744,  882,  881,  672,  910,  909,  908,  912,  916,
 /*   490 */   907,  784,  751,  671,  668,  675,  679,  731,  732,  740,
 /*   500 */   738,  737,  736,  735,  734,  730,  681,  686,  724,  709,
 /*   510 */   708,  717,  716,  722,  721,  720,  719,  718,  715,  714,
 /*   520 */   713,  706,  705,  711,  704,  727,  726,  723,  703,  747,
 /*   220 */  1148, 1259, 1045, 1068, 1042, 1138, 1127, 1210, 1138, 1138,
 /*   230 */  1110, 1101, 1305, 1285, 1118, 1118, 1277, 1277, 1118, 1157,
 /*   240 */  1078, 1148, 1085, 1085, 1085, 1085, 1118, 1005, 1148, 1157,
 /*   250 */  1078, 1078, 1148, 1118, 1005, 1253, 1251, 1118, 1118, 1005,
 /*   260 */  1220, 1118, 1005, 1118, 1005, 1220, 1076, 1076, 1076, 1060,
 /*   270 */  1220, 1076, 1045, 1076, 1060, 1076, 1076, 1131, 1126, 1131,
 /*   280 */  1126, 1131, 1126, 1131, 1126, 1118, 1118, 1305, 1220, 1224,
 /*   290 */  1224, 1220, 1143, 1132, 1141, 1139, 1148, 1011, 1063,  998,
 /*   300 */   998,  987,  987,  987,  987, 1297, 1297, 1292, 1047, 1047,
 /*   310 */  1030, 1305, 1305, 1305, 1305, 1305, 1305, 1022, 1305, 1229,
 /*   320 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*   330 */  1305, 1305, 1305, 1305, 1305, 1305, 1164, 1305,  983, 1287,
 /*   340 */  1305, 1305, 1284, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*   350 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*   360 */  1305, 1257, 1305, 1305, 1305, 1305, 1305, 1305, 1250, 1249,
 /*   370 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*   380 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
 /*   390 */  1305, 1305, 1092, 1305, 1305, 1305, 1096, 1305, 1305, 1305,
 /*   400 */  1305, 1305, 1305, 1305, 1140, 1305, 1133, 1305, 1213, 1305,
 /*   410 */  1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1302,
 /*   420 */  1305, 1305, 1305, 1301, 1305, 1305, 1305, 1305, 1305, 1166,
 /*   530 */   746,  745,  742,  702,  701,  700,  833,  699,  698,  838,
 /*   540 */   837,  866,  826,  755,  759,  758,  762,  763,  771,  770,
 /*   550 */   769,  780,  781,  793,  792,  824,  823,  794,  779,  773,
 /*   560 */   772,  788,  787,  786,  785,  777,  767,  799,  798,  868,
 /*   570 */   783,  867,  865,  934,  933,  932,  931,  930,  870,  967,
 /*   580 */   968,  887,  889,  886,  801,  800,  885,  869,  839,  836,
 /*   590 */   690,  691,  905,  904,  903,  693,  692,  689,  688,  863,
 /*   600 */   860,  852,  864,  861,  853,  849,  848,  834,  832,  831,
 /*   610 */   827,  835,  760,  756,  825,  765,  764,  697,  696,  694,
 /*   620 */   678,  677,  674,  667,  665,  664,  666,  662,  660,  659,
 /*   630 */   658,  657,  656,  684,  683,  682,  654,  651,  650,  646,
 /*   640 */   645,  643,
 /*   430 */  1305, 1165, 1169, 1305,  996, 1305,
};

/* The next table maps tokens into fallback tokens.  If a construct
** like the following:
** 
**      %fallback ID X Y Z.
**
125520
125521
125522
125523
125524
125525
125526




125527
125528
125529

125530
125531
125532
125533
125534
125535
125536
125936
125937
125938
125939
125940
125941
125942
125943
125944
125945
125946
125947
125948

125949
125950
125951
125952
125953
125954
125955
125956







+
+
+
+


-
+







**
**   +  The value of the token stored at this level of the stack.
**      (In other words, the "major" token.)
**
**   +  The semantic value stored at this level of the stack.  This is
**      the information used by the action routines in the grammar.
**      It is sometimes called the "minor" token.
**
** After the "shift" half of a SHIFTREDUCE action, the stateno field
** actually contains the reduce action for the second half of the
** SHIFTREDUCE.
*/
struct yyStackEntry {
  YYACTIONTYPE stateno;  /* The state-number */
  YYACTIONTYPE stateno;  /* The state-number, or reduce action in SHIFTREDUCE */
  YYCODETYPE major;      /* The major token value.  This is the code
                         ** number for the token at this stack level */
  YYMINORTYPE minor;     /* The user-supplied minor token value.  This
                         ** is the value of the token  */
};
typedef struct yyStackEntry yyStackEntry;

125628
125629
125630
125631
125632
125633
125634
125635

125636
125637
125638
125639
125640
125641
125642
125643
125644
125645
125646









125647
125648
125649
125650
125651
125652
125653
126048
126049
126050
126051
126052
126053
126054

126055
126056
126057









126058
126059
126060
126061
126062
126063
126064
126065
126066
126067
126068
126069
126070
126071
126072
126073







-
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+







  "cmdx",          "cmd",           "transtype",     "trans_opt",   
  "nm",            "savepoint_opt",  "create_table",  "create_table_args",
  "createkw",      "temp",          "ifnotexists",   "dbnm",        
  "columnlist",    "conslist_opt",  "table_options",  "select",      
  "column",        "columnid",      "type",          "carglist",    
  "typetoken",     "typename",      "signed",        "plus_num",    
  "minus_num",     "ccons",         "term",          "expr",        
  "onconf",        "sortorder",     "autoinc",       "idxlist_opt", 
  "onconf",        "sortorder",     "autoinc",       "eidlist_opt", 
  "refargs",       "defer_subclause",  "refarg",        "refact",      
  "init_deferred_pred_opt",  "conslist",      "tconscomma",    "tcons",       
  "idxlist",       "defer_subclause_opt",  "orconf",        "resolvetype", 
  "raisetype",     "ifexists",      "fullname",      "selectnowith",
  "oneselect",     "with",          "multiselect_op",  "distinct",    
  "selcollist",    "from",          "where_opt",     "groupby_opt", 
  "having_opt",    "orderby_opt",   "limit_opt",     "values",      
  "nexprlist",     "exprlist",      "sclp",          "as",          
  "seltablist",    "stl_prefix",    "joinop",        "indexed_opt", 
  "on_opt",        "using_opt",     "joinop2",       "idlist",      
  "sortlist",      "setlist",       "insert_cmd",    "inscollist_opt",
  "sortlist",      "eidlist",       "defer_subclause_opt",  "orconf",      
  "resolvetype",   "raisetype",     "ifexists",      "fullname",    
  "selectnowith",  "oneselect",     "with",          "multiselect_op",
  "distinct",      "selcollist",    "from",          "where_opt",   
  "groupby_opt",   "having_opt",    "orderby_opt",   "limit_opt",   
  "values",        "nexprlist",     "exprlist",      "sclp",        
  "as",            "seltablist",    "stl_prefix",    "joinop",      
  "indexed_opt",   "on_opt",        "using_opt",     "joinop2",     
  "idlist",        "setlist",       "insert_cmd",    "idlist_opt",  
  "likeop",        "between_op",    "in_op",         "case_operand",
  "case_exprlist",  "case_else",     "uniqueflag",    "collate",     
  "nmnum",         "trigger_decl",  "trigger_cmd_list",  "trigger_time",
  "trigger_event",  "foreach_clause",  "when_clause",   "trigger_cmd", 
  "trnm",          "tridxby",       "database_kw_opt",  "key_opt",     
  "add_column_fullname",  "kwcolumn_opt",  "create_vtab",   "vtabarglist", 
  "vtabarg",       "vtabargtoken",  "lp",            "anylist",     
125720
125721
125722
125723
125724
125725
125726
125727

125728
125729
125730
125731
125732
125733
125734
126140
126141
126142
126143
126144
126145
126146

126147
126148
126149
126150
126151
126152
126153
126154







-
+







 /*  58 */ "ccons ::= DEFAULT MINUS term",
 /*  59 */ "ccons ::= DEFAULT ID|INDEXED",
 /*  60 */ "ccons ::= NULL onconf",
 /*  61 */ "ccons ::= NOT NULL onconf",
 /*  62 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
 /*  63 */ "ccons ::= UNIQUE onconf",
 /*  64 */ "ccons ::= CHECK LP expr RP",
 /*  65 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
 /*  65 */ "ccons ::= REFERENCES nm eidlist_opt refargs",
 /*  66 */ "ccons ::= defer_subclause",
 /*  67 */ "ccons ::= COLLATE ID|STRING",
 /*  68 */ "autoinc ::=",
 /*  69 */ "autoinc ::= AUTOINCR",
 /*  70 */ "refargs ::=",
 /*  71 */ "refargs ::= refargs refarg",
 /*  72 */ "refarg ::= MATCH nm",
125748
125749
125750
125751
125752
125753
125754
125755
125756


125757
125758

125759
125760
125761
125762
125763
125764
125765
125766
125767
125768
125769
125770
125771

125772
125773
125774
125775
125776
125777
125778
126168
126169
126170
126171
126172
126173
126174


126175
126176
126177

126178
126179
126180
126181
126182
126183
126184
126185
126186
126187
126188
126189
126190

126191
126192
126193
126194
126195
126196
126197
126198







-
-
+
+

-
+












-
+







 /*  86 */ "conslist_opt ::=",
 /*  87 */ "conslist_opt ::= COMMA conslist",
 /*  88 */ "conslist ::= conslist tconscomma tcons",
 /*  89 */ "conslist ::= tcons",
 /*  90 */ "tconscomma ::= COMMA",
 /*  91 */ "tconscomma ::=",
 /*  92 */ "tcons ::= CONSTRAINT nm",
 /*  93 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
 /*  94 */ "tcons ::= UNIQUE LP idxlist RP onconf",
 /*  93 */ "tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf",
 /*  94 */ "tcons ::= UNIQUE LP sortlist RP onconf",
 /*  95 */ "tcons ::= CHECK LP expr RP onconf",
 /*  96 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
 /*  96 */ "tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt",
 /*  97 */ "defer_subclause_opt ::=",
 /*  98 */ "defer_subclause_opt ::= defer_subclause",
 /*  99 */ "onconf ::=",
 /* 100 */ "onconf ::= ON CONFLICT resolvetype",
 /* 101 */ "orconf ::=",
 /* 102 */ "orconf ::= OR resolvetype",
 /* 103 */ "resolvetype ::= raisetype",
 /* 104 */ "resolvetype ::= IGNORE",
 /* 105 */ "resolvetype ::= REPLACE",
 /* 106 */ "cmd ::= DROP TABLE ifexists fullname",
 /* 107 */ "ifexists ::= IF EXISTS",
 /* 108 */ "ifexists ::=",
 /* 109 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select",
 /* 109 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select",
 /* 110 */ "cmd ::= DROP VIEW ifexists fullname",
 /* 111 */ "cmd ::= select",
 /* 112 */ "select ::= with selectnowith",
 /* 113 */ "selectnowith ::= oneselect",
 /* 114 */ "selectnowith ::= selectnowith multiselect_op oneselect",
 /* 115 */ "multiselect_op ::= UNION",
 /* 116 */ "multiselect_op ::= UNION ALL",
125793
125794
125795
125796
125797
125798
125799

125800
125801
125802
125803
125804





125805
125806
125807
125808
125809
125810
125811
125812
125813
125814
125815
125816
125817
125818
125819
125820
125821
125822
125823
125824
125825
125826
125827
125828
125829
125830
125831
125832
125833
125834
125835
125836
125837
125838
125839
125840
125841
125842
125843
125844
125845
125846
125847











































125848
125849
125850
125851
125852
125853
125854
125855
125856
125857
125858
125859












125860
125861
125862
125863
125864
125865
125866
125867
125868
125869










125870
125871
125872
125873
125874
125875
125876
125877
125878
125879
125880
125881
125882
125883
125884
125885
125886
125887
125888
125889
125890
125891
125892























125893
125894
125895
125896
125897
125898
125899
125900
125901
125902
125903
125904
125905
125906
125907
125908
125909
125910


















125911
125912
125913
125914
125915
125916
125917







125918
125919
125920
125921
125922
125923
125924
125925
125926
125927










125928
125929
125930
125931
125932
125933
125934
125935
125936
125937
125938
125939
125940













125941
125942
125943
125944
125945
125946
125947
125948
125949
125950
125951
125952
125953
125954
125955
125956
125957
125958
125959
125960
125961
125962
125963
125964
125965
125966
125967
125968
125969
125970
125971
125972
125973

































125974
125975
125976
125977
125978
125979
125980
125981
125982
125983
125984
125985
125986
125987
125988















125989
125990
125991
125992
125993
125994
125995
126213
126214
126215
126216
126217
126218
126219
126220





126221
126222
126223
126224
126225











































126226
126227
126228
126229
126230
126231
126232
126233
126234
126235
126236
126237
126238
126239
126240
126241
126242
126243
126244
126245
126246
126247
126248
126249
126250
126251
126252
126253
126254
126255
126256
126257
126258
126259
126260
126261
126262
126263
126264
126265
126266
126267
126268












126269
126270
126271
126272
126273
126274
126275
126276
126277
126278
126279
126280










126281
126282
126283
126284
126285
126286
126287
126288
126289
126290























126291
126292
126293
126294
126295
126296
126297
126298
126299
126300
126301
126302
126303
126304
126305
126306
126307
126308
126309
126310
126311
126312
126313


















126314
126315
126316
126317
126318
126319
126320
126321
126322
126323
126324
126325
126326
126327
126328
126329
126330
126331







126332
126333
126334
126335
126336
126337
126338










126339
126340
126341
126342
126343
126344
126345
126346
126347
126348













126349
126350
126351
126352
126353
126354
126355
126356
126357
126358
126359
126360
126361

































126362
126363
126364
126365
126366
126367
126368
126369
126370
126371
126372
126373
126374
126375
126376
126377
126378
126379
126380
126381
126382
126383
126384
126385
126386
126387
126388
126389
126390
126391
126392
126393
126394















126395
126396
126397
126398
126399
126400
126401
126402
126403
126404
126405
126406
126407
126408
126409
126410
126411
126412
126413
126414
126415
126416







+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 /* 131 */ "as ::= ID|STRING",
 /* 132 */ "as ::=",
 /* 133 */ "from ::=",
 /* 134 */ "from ::= FROM seltablist",
 /* 135 */ "stl_prefix ::= seltablist joinop",
 /* 136 */ "stl_prefix ::=",
 /* 137 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
 /* 138 */ "seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt",
 /* 138 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
 /* 139 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
 /* 140 */ "dbnm ::=",
 /* 141 */ "dbnm ::= DOT nm",
 /* 142 */ "fullname ::= nm dbnm",
 /* 139 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
 /* 140 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
 /* 141 */ "dbnm ::=",
 /* 142 */ "dbnm ::= DOT nm",
 /* 143 */ "fullname ::= nm dbnm",
 /* 143 */ "joinop ::= COMMA|JOIN",
 /* 144 */ "joinop ::= JOIN_KW JOIN",
 /* 145 */ "joinop ::= JOIN_KW nm JOIN",
 /* 146 */ "joinop ::= JOIN_KW nm nm JOIN",
 /* 147 */ "on_opt ::= ON expr",
 /* 148 */ "on_opt ::=",
 /* 149 */ "indexed_opt ::=",
 /* 150 */ "indexed_opt ::= INDEXED BY nm",
 /* 151 */ "indexed_opt ::= NOT INDEXED",
 /* 152 */ "using_opt ::= USING LP idlist RP",
 /* 153 */ "using_opt ::=",
 /* 154 */ "orderby_opt ::=",
 /* 155 */ "orderby_opt ::= ORDER BY sortlist",
 /* 156 */ "sortlist ::= sortlist COMMA expr sortorder",
 /* 157 */ "sortlist ::= expr sortorder",
 /* 158 */ "sortorder ::= ASC",
 /* 159 */ "sortorder ::= DESC",
 /* 160 */ "sortorder ::=",
 /* 161 */ "groupby_opt ::=",
 /* 162 */ "groupby_opt ::= GROUP BY nexprlist",
 /* 163 */ "having_opt ::=",
 /* 164 */ "having_opt ::= HAVING expr",
 /* 165 */ "limit_opt ::=",
 /* 166 */ "limit_opt ::= LIMIT expr",
 /* 167 */ "limit_opt ::= LIMIT expr OFFSET expr",
 /* 168 */ "limit_opt ::= LIMIT expr COMMA expr",
 /* 169 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt",
 /* 170 */ "where_opt ::=",
 /* 171 */ "where_opt ::= WHERE expr",
 /* 172 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt",
 /* 173 */ "setlist ::= setlist COMMA nm EQ expr",
 /* 174 */ "setlist ::= nm EQ expr",
 /* 175 */ "cmd ::= with insert_cmd INTO fullname inscollist_opt select",
 /* 176 */ "cmd ::= with insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
 /* 177 */ "insert_cmd ::= INSERT orconf",
 /* 178 */ "insert_cmd ::= REPLACE",
 /* 179 */ "inscollist_opt ::=",
 /* 180 */ "inscollist_opt ::= LP idlist RP",
 /* 181 */ "idlist ::= idlist COMMA nm",
 /* 182 */ "idlist ::= nm",
 /* 183 */ "expr ::= term",
 /* 184 */ "expr ::= LP expr RP",
 /* 185 */ "term ::= NULL",
 /* 144 */ "joinop ::= COMMA|JOIN",
 /* 145 */ "joinop ::= JOIN_KW JOIN",
 /* 146 */ "joinop ::= JOIN_KW nm JOIN",
 /* 147 */ "joinop ::= JOIN_KW nm nm JOIN",
 /* 148 */ "on_opt ::= ON expr",
 /* 149 */ "on_opt ::=",
 /* 150 */ "indexed_opt ::=",
 /* 151 */ "indexed_opt ::= INDEXED BY nm",
 /* 152 */ "indexed_opt ::= NOT INDEXED",
 /* 153 */ "using_opt ::= USING LP idlist RP",
 /* 154 */ "using_opt ::=",
 /* 155 */ "orderby_opt ::=",
 /* 156 */ "orderby_opt ::= ORDER BY sortlist",
 /* 157 */ "sortlist ::= sortlist COMMA expr sortorder",
 /* 158 */ "sortlist ::= expr sortorder",
 /* 159 */ "sortorder ::= ASC",
 /* 160 */ "sortorder ::= DESC",
 /* 161 */ "sortorder ::=",
 /* 162 */ "groupby_opt ::=",
 /* 163 */ "groupby_opt ::= GROUP BY nexprlist",
 /* 164 */ "having_opt ::=",
 /* 165 */ "having_opt ::= HAVING expr",
 /* 166 */ "limit_opt ::=",
 /* 167 */ "limit_opt ::= LIMIT expr",
 /* 168 */ "limit_opt ::= LIMIT expr OFFSET expr",
 /* 169 */ "limit_opt ::= LIMIT expr COMMA expr",
 /* 170 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt",
 /* 171 */ "where_opt ::=",
 /* 172 */ "where_opt ::= WHERE expr",
 /* 173 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt",
 /* 174 */ "setlist ::= setlist COMMA nm EQ expr",
 /* 175 */ "setlist ::= nm EQ expr",
 /* 176 */ "cmd ::= with insert_cmd INTO fullname idlist_opt select",
 /* 177 */ "cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES",
 /* 178 */ "insert_cmd ::= INSERT orconf",
 /* 179 */ "insert_cmd ::= REPLACE",
 /* 180 */ "idlist_opt ::=",
 /* 181 */ "idlist_opt ::= LP idlist RP",
 /* 182 */ "idlist ::= idlist COMMA nm",
 /* 183 */ "idlist ::= nm",
 /* 184 */ "expr ::= term",
 /* 185 */ "expr ::= LP expr RP",
 /* 186 */ "term ::= NULL",
 /* 186 */ "expr ::= ID|INDEXED",
 /* 187 */ "expr ::= JOIN_KW",
 /* 188 */ "expr ::= nm DOT nm",
 /* 189 */ "expr ::= nm DOT nm DOT nm",
 /* 190 */ "term ::= INTEGER|FLOAT|BLOB",
 /* 191 */ "term ::= STRING",
 /* 192 */ "expr ::= VARIABLE",
 /* 193 */ "expr ::= expr COLLATE ID|STRING",
 /* 194 */ "expr ::= CAST LP expr AS typetoken RP",
 /* 195 */ "expr ::= ID|INDEXED LP distinct exprlist RP",
 /* 196 */ "expr ::= ID|INDEXED LP STAR RP",
 /* 197 */ "term ::= CTIME_KW",
 /* 187 */ "expr ::= ID|INDEXED",
 /* 188 */ "expr ::= JOIN_KW",
 /* 189 */ "expr ::= nm DOT nm",
 /* 190 */ "expr ::= nm DOT nm DOT nm",
 /* 191 */ "term ::= INTEGER|FLOAT|BLOB",
 /* 192 */ "term ::= STRING",
 /* 193 */ "expr ::= VARIABLE",
 /* 194 */ "expr ::= expr COLLATE ID|STRING",
 /* 195 */ "expr ::= CAST LP expr AS typetoken RP",
 /* 196 */ "expr ::= ID|INDEXED LP distinct exprlist RP",
 /* 197 */ "expr ::= ID|INDEXED LP STAR RP",
 /* 198 */ "term ::= CTIME_KW",
 /* 198 */ "expr ::= expr AND expr",
 /* 199 */ "expr ::= expr OR expr",
 /* 200 */ "expr ::= expr LT|GT|GE|LE expr",
 /* 201 */ "expr ::= expr EQ|NE expr",
 /* 202 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
 /* 203 */ "expr ::= expr PLUS|MINUS expr",
 /* 204 */ "expr ::= expr STAR|SLASH|REM expr",
 /* 205 */ "expr ::= expr CONCAT expr",
 /* 206 */ "likeop ::= LIKE_KW|MATCH",
 /* 207 */ "likeop ::= NOT LIKE_KW|MATCH",
 /* 199 */ "expr ::= expr AND expr",
 /* 200 */ "expr ::= expr OR expr",
 /* 201 */ "expr ::= expr LT|GT|GE|LE expr",
 /* 202 */ "expr ::= expr EQ|NE expr",
 /* 203 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
 /* 204 */ "expr ::= expr PLUS|MINUS expr",
 /* 205 */ "expr ::= expr STAR|SLASH|REM expr",
 /* 206 */ "expr ::= expr CONCAT expr",
 /* 207 */ "likeop ::= LIKE_KW|MATCH",
 /* 208 */ "likeop ::= NOT LIKE_KW|MATCH",
 /* 208 */ "expr ::= expr likeop expr",
 /* 209 */ "expr ::= expr likeop expr ESCAPE expr",
 /* 210 */ "expr ::= expr ISNULL|NOTNULL",
 /* 211 */ "expr ::= expr NOT NULL",
 /* 212 */ "expr ::= expr IS expr",
 /* 213 */ "expr ::= expr IS NOT expr",
 /* 214 */ "expr ::= NOT expr",
 /* 215 */ "expr ::= BITNOT expr",
 /* 216 */ "expr ::= MINUS expr",
 /* 217 */ "expr ::= PLUS expr",
 /* 218 */ "between_op ::= BETWEEN",
 /* 219 */ "between_op ::= NOT BETWEEN",
 /* 220 */ "expr ::= expr between_op expr AND expr",
 /* 221 */ "in_op ::= IN",
 /* 222 */ "in_op ::= NOT IN",
 /* 223 */ "expr ::= expr in_op LP exprlist RP",
 /* 224 */ "expr ::= LP select RP",
 /* 225 */ "expr ::= expr in_op LP select RP",
 /* 226 */ "expr ::= expr in_op nm dbnm",
 /* 227 */ "expr ::= EXISTS LP select RP",
 /* 228 */ "expr ::= CASE case_operand case_exprlist case_else END",
 /* 229 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
 /* 230 */ "case_exprlist ::= WHEN expr THEN expr",
 /* 209 */ "expr ::= expr likeop expr",
 /* 210 */ "expr ::= expr likeop expr ESCAPE expr",
 /* 211 */ "expr ::= expr ISNULL|NOTNULL",
 /* 212 */ "expr ::= expr NOT NULL",
 /* 213 */ "expr ::= expr IS expr",
 /* 214 */ "expr ::= expr IS NOT expr",
 /* 215 */ "expr ::= NOT expr",
 /* 216 */ "expr ::= BITNOT expr",
 /* 217 */ "expr ::= MINUS expr",
 /* 218 */ "expr ::= PLUS expr",
 /* 219 */ "between_op ::= BETWEEN",
 /* 220 */ "between_op ::= NOT BETWEEN",
 /* 221 */ "expr ::= expr between_op expr AND expr",
 /* 222 */ "in_op ::= IN",
 /* 223 */ "in_op ::= NOT IN",
 /* 224 */ "expr ::= expr in_op LP exprlist RP",
 /* 225 */ "expr ::= LP select RP",
 /* 226 */ "expr ::= expr in_op LP select RP",
 /* 227 */ "expr ::= expr in_op nm dbnm",
 /* 228 */ "expr ::= EXISTS LP select RP",
 /* 229 */ "expr ::= CASE case_operand case_exprlist case_else END",
 /* 230 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
 /* 231 */ "case_exprlist ::= WHEN expr THEN expr",
 /* 231 */ "case_else ::= ELSE expr",
 /* 232 */ "case_else ::=",
 /* 233 */ "case_operand ::= expr",
 /* 234 */ "case_operand ::=",
 /* 235 */ "exprlist ::= nexprlist",
 /* 236 */ "exprlist ::=",
 /* 237 */ "nexprlist ::= nexprlist COMMA expr",
 /* 238 */ "nexprlist ::= expr",
 /* 239 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt",
 /* 240 */ "uniqueflag ::= UNIQUE",
 /* 241 */ "uniqueflag ::=",
 /* 242 */ "idxlist_opt ::=",
 /* 243 */ "idxlist_opt ::= LP idxlist RP",
 /* 244 */ "idxlist ::= idxlist COMMA nm collate sortorder",
 /* 245 */ "idxlist ::= nm collate sortorder",
 /* 246 */ "collate ::=",
 /* 247 */ "collate ::= COLLATE ID|STRING",
 /* 248 */ "cmd ::= DROP INDEX ifexists fullname",
 /* 232 */ "case_else ::= ELSE expr",
 /* 233 */ "case_else ::=",
 /* 234 */ "case_operand ::= expr",
 /* 235 */ "case_operand ::=",
 /* 236 */ "exprlist ::= nexprlist",
 /* 237 */ "exprlist ::=",
 /* 238 */ "nexprlist ::= nexprlist COMMA expr",
 /* 239 */ "nexprlist ::= expr",
 /* 240 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
 /* 241 */ "uniqueflag ::= UNIQUE",
 /* 242 */ "uniqueflag ::=",
 /* 243 */ "eidlist_opt ::=",
 /* 244 */ "eidlist_opt ::= LP eidlist RP",
 /* 245 */ "eidlist ::= eidlist COMMA nm collate sortorder",
 /* 246 */ "eidlist ::= nm collate sortorder",
 /* 247 */ "collate ::=",
 /* 248 */ "collate ::= COLLATE ID|STRING",
 /* 249 */ "cmd ::= DROP INDEX ifexists fullname",
 /* 249 */ "cmd ::= VACUUM",
 /* 250 */ "cmd ::= VACUUM nm",
 /* 251 */ "cmd ::= PRAGMA nm dbnm",
 /* 252 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
 /* 253 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
 /* 254 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
 /* 255 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
 /* 250 */ "cmd ::= VACUUM",
 /* 251 */ "cmd ::= VACUUM nm",
 /* 252 */ "cmd ::= PRAGMA nm dbnm",
 /* 253 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
 /* 254 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
 /* 255 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
 /* 256 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
 /* 256 */ "nmnum ::= plus_num",
 /* 257 */ "nmnum ::= nm",
 /* 258 */ "nmnum ::= ON",
 /* 259 */ "nmnum ::= DELETE",
 /* 260 */ "nmnum ::= DEFAULT",
 /* 261 */ "plus_num ::= PLUS INTEGER|FLOAT",
 /* 262 */ "plus_num ::= INTEGER|FLOAT",
 /* 263 */ "minus_num ::= MINUS INTEGER|FLOAT",
 /* 264 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
 /* 265 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
 /* 257 */ "nmnum ::= plus_num",
 /* 258 */ "nmnum ::= nm",
 /* 259 */ "nmnum ::= ON",
 /* 260 */ "nmnum ::= DELETE",
 /* 261 */ "nmnum ::= DEFAULT",
 /* 262 */ "plus_num ::= PLUS INTEGER|FLOAT",
 /* 263 */ "plus_num ::= INTEGER|FLOAT",
 /* 264 */ "minus_num ::= MINUS INTEGER|FLOAT",
 /* 265 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
 /* 266 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
 /* 266 */ "trigger_time ::= BEFORE",
 /* 267 */ "trigger_time ::= AFTER",
 /* 268 */ "trigger_time ::= INSTEAD OF",
 /* 269 */ "trigger_time ::=",
 /* 270 */ "trigger_event ::= DELETE|INSERT",
 /* 271 */ "trigger_event ::= UPDATE",
 /* 272 */ "trigger_event ::= UPDATE OF idlist",
 /* 273 */ "foreach_clause ::=",
 /* 274 */ "foreach_clause ::= FOR EACH ROW",
 /* 275 */ "when_clause ::=",
 /* 276 */ "when_clause ::= WHEN expr",
 /* 277 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
 /* 278 */ "trigger_cmd_list ::= trigger_cmd SEMI",
 /* 267 */ "trigger_time ::= BEFORE",
 /* 268 */ "trigger_time ::= AFTER",
 /* 269 */ "trigger_time ::= INSTEAD OF",
 /* 270 */ "trigger_time ::=",
 /* 271 */ "trigger_event ::= DELETE|INSERT",
 /* 272 */ "trigger_event ::= UPDATE",
 /* 273 */ "trigger_event ::= UPDATE OF idlist",
 /* 274 */ "foreach_clause ::=",
 /* 275 */ "foreach_clause ::= FOR EACH ROW",
 /* 276 */ "when_clause ::=",
 /* 277 */ "when_clause ::= WHEN expr",
 /* 278 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
 /* 279 */ "trigger_cmd_list ::= trigger_cmd SEMI",
 /* 279 */ "trnm ::= nm",
 /* 280 */ "trnm ::= nm DOT nm",
 /* 281 */ "tridxby ::=",
 /* 282 */ "tridxby ::= INDEXED BY nm",
 /* 283 */ "tridxby ::= NOT INDEXED",
 /* 284 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
 /* 285 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select",
 /* 286 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
 /* 287 */ "trigger_cmd ::= select",
 /* 288 */ "expr ::= RAISE LP IGNORE RP",
 /* 289 */ "expr ::= RAISE LP raisetype COMMA nm RP",
 /* 290 */ "raisetype ::= ROLLBACK",
 /* 291 */ "raisetype ::= ABORT",
 /* 292 */ "raisetype ::= FAIL",
 /* 293 */ "cmd ::= DROP TRIGGER ifexists fullname",
 /* 294 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
 /* 295 */ "cmd ::= DETACH database_kw_opt expr",
 /* 296 */ "key_opt ::=",
 /* 297 */ "key_opt ::= KEY expr",
 /* 298 */ "database_kw_opt ::= DATABASE",
 /* 299 */ "database_kw_opt ::=",
 /* 300 */ "cmd ::= REINDEX",
 /* 301 */ "cmd ::= REINDEX nm dbnm",
 /* 302 */ "cmd ::= ANALYZE",
 /* 303 */ "cmd ::= ANALYZE nm dbnm",
 /* 304 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
 /* 305 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
 /* 306 */ "add_column_fullname ::= fullname",
 /* 307 */ "kwcolumn_opt ::=",
 /* 308 */ "kwcolumn_opt ::= COLUMNKW",
 /* 309 */ "cmd ::= create_vtab",
 /* 310 */ "cmd ::= create_vtab LP vtabarglist RP",
 /* 311 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
 /* 280 */ "trnm ::= nm",
 /* 281 */ "trnm ::= nm DOT nm",
 /* 282 */ "tridxby ::=",
 /* 283 */ "tridxby ::= INDEXED BY nm",
 /* 284 */ "tridxby ::= NOT INDEXED",
 /* 285 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
 /* 286 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select",
 /* 287 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
 /* 288 */ "trigger_cmd ::= select",
 /* 289 */ "expr ::= RAISE LP IGNORE RP",
 /* 290 */ "expr ::= RAISE LP raisetype COMMA nm RP",
 /* 291 */ "raisetype ::= ROLLBACK",
 /* 292 */ "raisetype ::= ABORT",
 /* 293 */ "raisetype ::= FAIL",
 /* 294 */ "cmd ::= DROP TRIGGER ifexists fullname",
 /* 295 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
 /* 296 */ "cmd ::= DETACH database_kw_opt expr",
 /* 297 */ "key_opt ::=",
 /* 298 */ "key_opt ::= KEY expr",
 /* 299 */ "database_kw_opt ::= DATABASE",
 /* 300 */ "database_kw_opt ::=",
 /* 301 */ "cmd ::= REINDEX",
 /* 302 */ "cmd ::= REINDEX nm dbnm",
 /* 303 */ "cmd ::= ANALYZE",
 /* 304 */ "cmd ::= ANALYZE nm dbnm",
 /* 305 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
 /* 306 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
 /* 307 */ "add_column_fullname ::= fullname",
 /* 308 */ "kwcolumn_opt ::=",
 /* 309 */ "kwcolumn_opt ::= COLUMNKW",
 /* 310 */ "cmd ::= create_vtab",
 /* 311 */ "cmd ::= create_vtab LP vtabarglist RP",
 /* 312 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
 /* 312 */ "vtabarglist ::= vtabarg",
 /* 313 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
 /* 314 */ "vtabarg ::=",
 /* 315 */ "vtabarg ::= vtabarg vtabargtoken",
 /* 316 */ "vtabargtoken ::= ANY",
 /* 317 */ "vtabargtoken ::= lp anylist RP",
 /* 318 */ "lp ::= LP",
 /* 319 */ "anylist ::=",
 /* 320 */ "anylist ::= anylist LP anylist RP",
 /* 321 */ "anylist ::= anylist ANY",
 /* 322 */ "with ::=",
 /* 323 */ "with ::= WITH wqlist",
 /* 324 */ "with ::= WITH RECURSIVE wqlist",
 /* 325 */ "wqlist ::= nm idxlist_opt AS LP select RP",
 /* 326 */ "wqlist ::= wqlist COMMA nm idxlist_opt AS LP select RP",
 /* 313 */ "vtabarglist ::= vtabarg",
 /* 314 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
 /* 315 */ "vtabarg ::=",
 /* 316 */ "vtabarg ::= vtabarg vtabargtoken",
 /* 317 */ "vtabargtoken ::= ANY",
 /* 318 */ "vtabargtoken ::= lp anylist RP",
 /* 319 */ "lp ::= LP",
 /* 320 */ "anylist ::=",
 /* 321 */ "anylist ::= anylist LP anylist RP",
 /* 322 */ "anylist ::= anylist ANY",
 /* 323 */ "with ::=",
 /* 324 */ "with ::= WITH wqlist",
 /* 325 */ "with ::= WITH RECURSIVE wqlist",
 /* 326 */ "wqlist ::= nm eidlist_opt AS LP select RP",
 /* 327 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
};
#endif /* NDEBUG */


#if YYSTACKDEPTH<=0
/*
** Try to increase the size of the parser stack.
126061
126062
126063
126064
126065
126066
126067
126068
126069
126070



126071
126072
126073
126074
126075
126076
126077
126078
126079
126080
126081
126082
126083
126084
126085
126086
126087
126088









126089
126090
126091
126092
126093
126094
126095
126096
126097
126098
126099




126100
126101
126102
126103
126104

126105
126106
126107
126108
126109
126110
126111
126112



126113
126114
126115
126116
126117
126118
126119
126120
126121
126122
126123



126124
126125
126126
126127
126128
126129
126130
126482
126483
126484
126485
126486
126487
126488



126489
126490
126491
126492
126493
126494
126495
126496
126497
126498
126499
126500
126501








126502
126503
126504
126505
126506
126507
126508
126509
126510

126511
126512
126513
126514
126515
126516




126517
126518
126519
126520
126521
126522
126523
126524

126525
126526
126527
126528
126529
126530



126531
126532
126533
126534
126535
126536
126537
126538
126539
126540
126541



126542
126543
126544
126545
126546
126547
126548
126549
126550
126551







-
-
-
+
+
+










-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-






-
-
-
-
+
+
+
+




-
+





-
-
-
+
+
+








-
-
-
+
+
+







    ** being destroyed before it is finished parsing.
    **
    ** Note: during a reduce, the only symbols destroyed are those
    ** which appear on the RHS of the rule, but which are not used
    ** inside the C code.
    */
    case 163: /* select */
    case 195: /* selectnowith */
    case 196: /* oneselect */
    case 207: /* values */
    case 196: /* selectnowith */
    case 197: /* oneselect */
    case 208: /* values */
{
sqlite3SelectDelete(pParse->db, (yypminor->yy3));
}
      break;
    case 174: /* term */
    case 175: /* expr */
{
sqlite3ExprDelete(pParse->db, (yypminor->yy346).pExpr);
}
      break;
    case 179: /* idxlist_opt */
    case 188: /* idxlist */
    case 200: /* selcollist */
    case 203: /* groupby_opt */
    case 205: /* orderby_opt */
    case 208: /* nexprlist */
    case 209: /* exprlist */
    case 210: /* sclp */
    case 179: /* eidlist_opt */
    case 188: /* sortlist */
    case 189: /* eidlist */
    case 201: /* selcollist */
    case 204: /* groupby_opt */
    case 206: /* orderby_opt */
    case 209: /* nexprlist */
    case 210: /* exprlist */
    case 211: /* sclp */
    case 220: /* sortlist */
    case 221: /* setlist */
    case 228: /* case_exprlist */
{
sqlite3ExprListDelete(pParse->db, (yypminor->yy14));
}
      break;
    case 194: /* fullname */
    case 201: /* from */
    case 212: /* seltablist */
    case 213: /* stl_prefix */
    case 195: /* fullname */
    case 202: /* from */
    case 213: /* seltablist */
    case 214: /* stl_prefix */
{
sqlite3SrcListDelete(pParse->db, (yypminor->yy65));
}
      break;
    case 197: /* with */
    case 198: /* with */
    case 252: /* wqlist */
{
sqlite3WithDelete(pParse->db, (yypminor->yy59));
}
      break;
    case 202: /* where_opt */
    case 204: /* having_opt */
    case 216: /* on_opt */
    case 203: /* where_opt */
    case 205: /* having_opt */
    case 217: /* on_opt */
    case 227: /* case_operand */
    case 229: /* case_else */
    case 238: /* when_clause */
    case 243: /* key_opt */
{
sqlite3ExprDelete(pParse->db, (yypminor->yy132));
}
      break;
    case 217: /* using_opt */
    case 219: /* idlist */
    case 223: /* inscollist_opt */
    case 218: /* using_opt */
    case 220: /* idlist */
    case 223: /* idlist_opt */
{
sqlite3IdListDelete(pParse->db, (yypminor->yy408));
}
      break;
    case 234: /* trigger_cmd_list */
    case 239: /* trigger_cmd */
{
126216
126217
126218
126219
126220
126221
126222

126223
126224
126225



126226
126227
126228
126229
126230
126231
126232
126233
126637
126638
126639
126640
126641
126642
126643
126644



126645
126646
126647

126648
126649
126650
126651
126652
126653
126654







+
-
-
-
+
+
+
-







static int yy_find_shift_action(
  yyParser *pParser,        /* The parser */
  YYCODETYPE iLookAhead     /* The look-ahead token */
){
  int i;
  int stateno = pParser->yystack[pParser->yyidx].stateno;
 
  if( stateno>=YY_MIN_REDUCE ) return stateno;
  if( stateno>YY_SHIFT_COUNT
   || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){
    return yy_default[stateno];
  assert( stateno <= YY_SHIFT_COUNT );
  i = yy_shift_ofst[stateno];
  if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno];
  }
  assert( iLookAhead!=YYNOCODE );
  i += iLookAhead;
  if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
    if( iLookAhead>0 ){
#ifdef YYFALLBACK
      YYCODETYPE iFallback;            /* Fallback token */
      if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
126322
126323
126324
126325
126326
126327
126328






















126329

126330
126331
126332
126333
126334
126335
126336
126743
126744
126745
126746
126747
126748
126749
126750
126751
126752
126753
126754
126755
126756
126757
126758
126759
126760
126761
126762
126763
126764
126765
126766
126767
126768
126769
126770
126771

126772
126773
126774
126775
126776
126777
126778
126779







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+








  UNUSED_PARAMETER(yypMinor); /* Silence some compiler warnings */
  sqlite3ErrorMsg(pParse, "parser stack overflow");
   sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument var */
}

/*
** Print tracing information for a SHIFT action
*/
#ifndef NDEBUG
static void yyTraceShift(yyParser *yypParser, int yyNewState){
  if( yyTraceFILE ){
    int i;
    if( yyNewState<YYNSTATE ){
      fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
      fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
      for(i=1; i<=yypParser->yyidx; i++)
        fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
      fprintf(yyTraceFILE,"\n");
    }else{
      fprintf(yyTraceFILE,"%sShift *\n",yyTracePrompt);
    }
  }
}
#else
# define yyTraceShift(X,Y)
#endif

/*
** Perform a shift action.
** Perform a shift action.  Return the number of errors.
*/
static void yy_shift(
  yyParser *yypParser,          /* The parser to be shifted */
  int yyNewState,               /* The new state to shift in */
  int yyMajor,                  /* The major token to shift in */
  YYMINORTYPE *yypMinor         /* Pointer to the minor token to shift in */
){
126355
126356
126357
126358
126359
126360
126361
126362
126363
126364
126365
126366
126367
126368
126369

126370
126371
126372
126373
126374
126375
126376
126377
126378
126798
126799
126800
126801
126802
126803
126804








126805


126806
126807
126808
126809
126810
126811
126812







-
-
-
-
-
-
-
-
+
-
-







    }
  }
#endif
  yytos = &yypParser->yystack[yypParser->yyidx];
  yytos->stateno = (YYACTIONTYPE)yyNewState;
  yytos->major = (YYCODETYPE)yyMajor;
  yytos->minor = *yypMinor;
#ifndef NDEBUG
  if( yyTraceFILE && yypParser->yyidx>0 ){
    int i;
    fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
    fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
    for(i=1; i<=yypParser->yyidx; i++)
      fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
    fprintf(yyTraceFILE,"\n");
  yyTraceShift(yypParser, yyNewState);
  }
#endif
}

/* The following table contains information about every rule that
** is used during the reduce.
*/
static const struct {
  YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
126471
126472
126473
126474
126475
126476
126477
126478
126479


126480
126481
126482
126483
126484
126485
126486





126487
126488
126489
126490



126491
126492
126493
126494
126495
126496
126497
126498
126499
126500
126501
126502
126503
126504
126505
126506
126507
126508
126509
126510
126511
126512
126513
126514
126515
126516
126517
126518
126519
126520




























126521
126522
126523
126524
126525
126526
126527
126528
126529
126530
126531
126532
126533
126534
126535
126536
126537
126538
















126539
126540
126541
126542
126543
126544
126545
126546
126547
126548
126549








126550
126551
126552


126553
126554
126555
126556
126557
126558
126559
126560
126561
126562
126563


126564
126565
126566
126567
126568
126569
126570
126905
126906
126907
126908
126909
126910
126911


126912
126913
126914
126915





126916
126917
126918
126919
126920
126921



126922
126923
126924
126925
126926
126927



























126928
126929
126930
126931
126932
126933
126934
126935
126936
126937
126938
126939
126940
126941
126942
126943
126944
126945
126946
126947
126948
126949
126950
126951
126952
126953
126954
126955
126956
126957
















126958
126959
126960
126961
126962
126963
126964
126965
126966
126967
126968
126969
126970
126971
126972
126973
126974
126975
126976








126977
126978
126979
126980
126981
126982
126983
126984
126985


126986
126987
126988
126989
126990
126991
126992
126993
126994
126995
126996


126997
126998
126999
127000
127001
127002
127003
127004
127005







-
-
+
+


-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
+
+









-
-
+
+







  { 186, 1 },
  { 186, 0 },
  { 187, 2 },
  { 187, 7 },
  { 187, 5 },
  { 187, 5 },
  { 187, 10 },
  { 189, 0 },
  { 189, 1 },
  { 190, 0 },
  { 190, 1 },
  { 176, 0 },
  { 176, 3 },
  { 190, 0 },
  { 190, 2 },
  { 191, 1 },
  { 191, 1 },
  { 191, 1 },
  { 191, 0 },
  { 191, 2 },
  { 192, 1 },
  { 192, 1 },
  { 192, 1 },
  { 149, 4 },
  { 193, 2 },
  { 193, 0 },
  { 149, 8 },
  { 194, 2 },
  { 194, 0 },
  { 149, 9 },
  { 149, 4 },
  { 149, 1 },
  { 163, 2 },
  { 195, 1 },
  { 195, 3 },
  { 198, 1 },
  { 198, 2 },
  { 198, 1 },
  { 196, 9 },
  { 196, 1 },
  { 207, 4 },
  { 207, 5 },
  { 199, 1 },
  { 199, 1 },
  { 199, 0 },
  { 210, 2 },
  { 210, 0 },
  { 200, 3 },
  { 200, 2 },
  { 200, 4 },
  { 211, 2 },
  { 211, 1 },
  { 211, 0 },
  { 201, 0 },
  { 201, 2 },
  { 213, 2 },
  { 213, 0 },
  { 212, 7 },
  { 212, 7 },
  { 212, 7 },
  { 196, 1 },
  { 196, 3 },
  { 199, 1 },
  { 199, 2 },
  { 199, 1 },
  { 197, 9 },
  { 197, 1 },
  { 208, 4 },
  { 208, 5 },
  { 200, 1 },
  { 200, 1 },
  { 200, 0 },
  { 211, 2 },
  { 211, 0 },
  { 201, 3 },
  { 201, 2 },
  { 201, 4 },
  { 212, 2 },
  { 212, 1 },
  { 212, 0 },
  { 202, 0 },
  { 202, 2 },
  { 214, 2 },
  { 214, 0 },
  { 213, 7 },
  { 213, 9 },
  { 213, 7 },
  { 213, 7 },
  { 159, 0 },
  { 159, 2 },
  { 194, 2 },
  { 214, 1 },
  { 214, 2 },
  { 214, 3 },
  { 214, 4 },
  { 216, 2 },
  { 216, 0 },
  { 215, 0 },
  { 215, 3 },
  { 215, 2 },
  { 217, 4 },
  { 217, 0 },
  { 205, 0 },
  { 205, 3 },
  { 220, 4 },
  { 220, 2 },
  { 195, 2 },
  { 215, 1 },
  { 215, 2 },
  { 215, 3 },
  { 215, 4 },
  { 217, 2 },
  { 217, 0 },
  { 216, 0 },
  { 216, 3 },
  { 216, 2 },
  { 218, 4 },
  { 218, 0 },
  { 206, 0 },
  { 206, 3 },
  { 188, 4 },
  { 188, 2 },
  { 177, 1 },
  { 177, 1 },
  { 177, 0 },
  { 203, 0 },
  { 203, 3 },
  { 204, 0 },
  { 204, 2 },
  { 206, 0 },
  { 206, 2 },
  { 206, 4 },
  { 206, 4 },
  { 204, 0 },
  { 204, 3 },
  { 205, 0 },
  { 205, 2 },
  { 207, 0 },
  { 207, 2 },
  { 207, 4 },
  { 207, 4 },
  { 149, 6 },
  { 202, 0 },
  { 202, 2 },
  { 203, 0 },
  { 203, 2 },
  { 149, 8 },
  { 221, 5 },
  { 221, 3 },
  { 149, 6 },
  { 149, 7 },
  { 222, 2 },
  { 222, 1 },
  { 223, 0 },
  { 223, 3 },
  { 219, 3 },
  { 219, 1 },
  { 220, 3 },
  { 220, 1 },
  { 175, 1 },
  { 175, 3 },
  { 174, 1 },
  { 175, 1 },
  { 175, 1 },
  { 175, 3 },
  { 175, 5 },
126609
126610
126611
126612
126613
126614
126615
126616
126617
126618
126619




126620
126621
126622
126623
126624
126625
126626


126627
126628
126629
126630
126631
126632
126633
127044
127045
127046
127047
127048
127049
127050




127051
127052
127053
127054
127055
127056
127057
127058
127059


127060
127061
127062
127063
127064
127065
127066
127067
127068







-
-
-
-
+
+
+
+





-
-
+
+







  { 175, 5 },
  { 228, 5 },
  { 228, 4 },
  { 229, 2 },
  { 229, 0 },
  { 227, 1 },
  { 227, 0 },
  { 209, 1 },
  { 209, 0 },
  { 208, 3 },
  { 208, 1 },
  { 210, 1 },
  { 210, 0 },
  { 209, 3 },
  { 209, 1 },
  { 149, 12 },
  { 230, 1 },
  { 230, 0 },
  { 179, 0 },
  { 179, 3 },
  { 188, 5 },
  { 188, 3 },
  { 189, 5 },
  { 189, 3 },
  { 231, 0 },
  { 231, 2 },
  { 149, 4 },
  { 149, 1 },
  { 149, 2 },
  { 149, 3 },
  { 149, 5 },
126664
126665
126666
126667
126668
126669
126670
126671
126672
126673



126674
126675
126676
126677
126678
126679
126680
127099
127100
127101
127102
127103
127104
127105



127106
127107
127108
127109
127110
127111
127112
127113
127114
127115







-
-
-
+
+
+







  { 241, 2 },
  { 239, 7 },
  { 239, 5 },
  { 239, 5 },
  { 239, 1 },
  { 175, 4 },
  { 175, 6 },
  { 192, 1 },
  { 192, 1 },
  { 192, 1 },
  { 193, 1 },
  { 193, 1 },
  { 193, 1 },
  { 149, 4 },
  { 149, 6 },
  { 149, 3 },
  { 243, 0 },
  { 243, 2 },
  { 242, 1 },
  { 242, 0 },
126696
126697
126698
126699
126700
126701
126702
126703
126704
126705



126706
126707
126708
126709
126710
126711
126712
127131
127132
127133
127134
127135
127136
127137



127138
127139
127140
127141
127142
127143
127144
127145
127146
127147







-
-
-
+
+
+







  { 248, 2 },
  { 249, 1 },
  { 249, 3 },
  { 250, 1 },
  { 251, 0 },
  { 251, 4 },
  { 251, 2 },
  { 197, 0 },
  { 197, 2 },
  { 197, 3 },
  { 198, 0 },
  { 198, 2 },
  { 198, 3 },
  { 252, 6 },
  { 252, 8 },
};

static void yy_accept(yyParser*);  /* Forward Declaration */

/*
126723
126724
126725
126726
126727
126728
126729

126730
126731


126732
126733
126734
126735
126736
126737
126738
127158
127159
127160
127161
127162
127163
127164
127165


127166
127167
127168
127169
127170
127171
127172
127173
127174







+
-
-
+
+







  yyStackEntry *yymsp;            /* The top of the parser's stack */
  int yysize;                     /* Amount to pop the stack */
  sqlite3ParserARG_FETCH;
  yymsp = &yypParser->yystack[yypParser->yyidx];
#ifndef NDEBUG
  if( yyTraceFILE && yyruleno>=0 
        && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
    yysize = yyRuleInfo[yyruleno].nrhs;
    fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
      yyRuleName[yyruleno]);
    fprintf(yyTraceFILE, "%sReduce [%s] -> state %d.\n", yyTracePrompt,
      yyRuleName[yyruleno], yymsp[-yysize].stateno);
  }
#endif /* NDEBUG */

  /* Silence complaints from purify about yygotominor being uninitialized
  ** in some cases when it is copied into the stack after the following
  ** switch.  yygotominor is uninitialized when a rule reduces that does
  ** not set the value of its left-hand side nonterminal.  Leaving the
126821
126822
126823
126824
126825
126826
126827
126828
126829



126830
126831
126832
126833
126834
126835
126836
126837
126838



126839
126840
126841
126842
126843
126844
126845
127257
127258
127259
127260
127261
127262
127263


127264
127265
127266
127267
127268
127269
127270
127271
127272
127273


127274
127275
127276
127277
127278
127279
127280
127281
127282
127283







-
-
+
+
+







-
-
+
+
+







      case 31: /* temp ::= */ yytestcase(yyruleno==31);
      case 68: /* autoinc ::= */ yytestcase(yyruleno==68);
      case 81: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==81);
      case 83: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==83);
      case 85: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==85);
      case 97: /* defer_subclause_opt ::= */ yytestcase(yyruleno==97);
      case 108: /* ifexists ::= */ yytestcase(yyruleno==108);
      case 218: /* between_op ::= BETWEEN */ yytestcase(yyruleno==218);
      case 221: /* in_op ::= IN */ yytestcase(yyruleno==221);
      case 219: /* between_op ::= BETWEEN */ yytestcase(yyruleno==219);
      case 222: /* in_op ::= IN */ yytestcase(yyruleno==222);
      case 247: /* collate ::= */ yytestcase(yyruleno==247);
{yygotominor.yy328 = 0;}
        break;
      case 29: /* ifnotexists ::= IF NOT EXISTS */
      case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30);
      case 69: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==69);
      case 84: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==84);
      case 107: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==107);
      case 219: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==219);
      case 222: /* in_op ::= NOT IN */ yytestcase(yyruleno==222);
      case 220: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==220);
      case 223: /* in_op ::= NOT IN */ yytestcase(yyruleno==223);
      case 248: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==248);
{yygotominor.yy328 = 1;}
        break;
      case 32: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
{
  sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy186,0);
}
        break;
126878
126879
126880
126881
126882
126883
126884
126885
126886


126887
126888
126889
126890
126891
126892
126893
126894
126895
126896









126897
126898
126899
126900
126901
126902
126903
127316
127317
127318
127319
127320
127321
127322


127323
127324










127325
127326
127327
127328
127329
127330
127331
127332
127333
127334
127335
127336
127337
127338
127339
127340







-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+







      case 40: /* nm ::= ID|INDEXED */
      case 41: /* nm ::= STRING */ yytestcase(yyruleno==41);
      case 42: /* nm ::= JOIN_KW */ yytestcase(yyruleno==42);
      case 45: /* typetoken ::= typename */ yytestcase(yyruleno==45);
      case 48: /* typename ::= ID|STRING */ yytestcase(yyruleno==48);
      case 130: /* as ::= AS nm */ yytestcase(yyruleno==130);
      case 131: /* as ::= ID|STRING */ yytestcase(yyruleno==131);
      case 141: /* dbnm ::= DOT nm */ yytestcase(yyruleno==141);
      case 150: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==150);
      case 142: /* dbnm ::= DOT nm */ yytestcase(yyruleno==142);
      case 151: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==151);
      case 247: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==247);
      case 256: /* nmnum ::= plus_num */ yytestcase(yyruleno==256);
      case 257: /* nmnum ::= nm */ yytestcase(yyruleno==257);
      case 258: /* nmnum ::= ON */ yytestcase(yyruleno==258);
      case 259: /* nmnum ::= DELETE */ yytestcase(yyruleno==259);
      case 260: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==260);
      case 261: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==261);
      case 262: /* plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==262);
      case 263: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==263);
      case 279: /* trnm ::= nm */ yytestcase(yyruleno==279);
      case 257: /* nmnum ::= plus_num */ yytestcase(yyruleno==257);
      case 258: /* nmnum ::= nm */ yytestcase(yyruleno==258);
      case 259: /* nmnum ::= ON */ yytestcase(yyruleno==259);
      case 260: /* nmnum ::= DELETE */ yytestcase(yyruleno==260);
      case 261: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==261);
      case 262: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==262);
      case 263: /* plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==263);
      case 264: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==264);
      case 280: /* trnm ::= nm */ yytestcase(yyruleno==280);
{yygotominor.yy0 = yymsp[0].minor.yy0;}
        break;
      case 44: /* type ::= typetoken */
{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
        break;
      case 46: /* typetoken ::= typename LP signed RP */
{
126949
126950
126951
126952
126953
126954
126955
126956

126957
126958
126959
126960
126961
126962
126963
127386
127387
127388
127389
127390
127391
127392

127393
127394
127395
127396
127397
127398
127399
127400







-
+







        break;
      case 63: /* ccons ::= UNIQUE onconf */
{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy328,0,0,0,0);}
        break;
      case 64: /* ccons ::= CHECK LP expr RP */
{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy346.pExpr);}
        break;
      case 65: /* ccons ::= REFERENCES nm idxlist_opt refargs */
      case 65: /* ccons ::= REFERENCES nm eidlist_opt refargs */
{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy14,yymsp[0].minor.yy328);}
        break;
      case 66: /* ccons ::= defer_subclause */
{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy328);}
        break;
      case 67: /* ccons ::= COLLATE ID|STRING */
{sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
127004
127005
127006
127007
127008
127009
127010
127011

127012
127013
127014

127015
127016
127017
127018
127019
127020

127021
127022
127023
127024
127025
127026
127027
127441
127442
127443
127444
127445
127446
127447

127448
127449
127450

127451
127452
127453
127454
127455
127456

127457
127458
127459
127460
127461
127462
127463
127464







-
+


-
+





-
+







        break;
      case 87: /* conslist_opt ::= COMMA conslist */
{yygotominor.yy0 = yymsp[-1].minor.yy0;}
        break;
      case 90: /* tconscomma ::= COMMA */
{pParse->constraintName.n = 0;}
        break;
      case 93: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
      case 93: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy14,yymsp[0].minor.yy328,yymsp[-2].minor.yy328,0);}
        break;
      case 94: /* tcons ::= UNIQUE LP idxlist RP onconf */
      case 94: /* tcons ::= UNIQUE LP sortlist RP onconf */
{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy14,yymsp[0].minor.yy328,0,0,0,0);}
        break;
      case 95: /* tcons ::= CHECK LP expr RP onconf */
{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy346.pExpr);}
        break;
      case 96: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
      case 96: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
{
    sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy14, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy14, yymsp[-1].minor.yy328);
    sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy328);
}
        break;
      case 99: /* onconf ::= */
{yygotominor.yy328 = OE_Default;}
127039
127040
127041
127042
127043
127044
127045
127046

127047
127048

127049
127050
127051
127052
127053
127054
127055
127476
127477
127478
127479
127480
127481
127482

127483
127484

127485
127486
127487
127488
127489
127490
127491
127492







-
+

-
+







{yygotominor.yy328 = OE_Replace;}
        break;
      case 106: /* cmd ::= DROP TABLE ifexists fullname */
{
  sqlite3DropTable(pParse, yymsp[0].minor.yy65, 0, yymsp[-1].minor.yy328);
}
        break;
      case 109: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */
      case 109: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
{
  sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy3, yymsp[-6].minor.yy328, yymsp[-4].minor.yy328);
  sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy14, yymsp[0].minor.yy3, yymsp[-7].minor.yy328, yymsp[-5].minor.yy328);
}
        break;
      case 110: /* cmd ::= DROP VIEW ifexists fullname */
{
  sqlite3DropTable(pParse, yymsp[0].minor.yy65, 1, yymsp[-1].minor.yy328);
}
        break;
127158
127159
127160
127161
127162
127163
127164
127165

127166
127167
127168
127169
127170
127171
127172




127173
127174
127175
127176
127177
127178
127179
127595
127596
127597
127598
127599
127600
127601

127602
127603
127604
127605




127606
127607
127608
127609
127610
127611
127612
127613
127614
127615
127616







-
+



-
-
-
-
+
+
+
+







      case 123: /* distinct ::= ALL */
{yygotominor.yy381 = SF_All;}
        break;
      case 124: /* distinct ::= */
{yygotominor.yy381 = 0;}
        break;
      case 125: /* sclp ::= selcollist COMMA */
      case 243: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==243);
      case 244: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==244);
{yygotominor.yy14 = yymsp[-1].minor.yy14;}
        break;
      case 126: /* sclp ::= */
      case 154: /* orderby_opt ::= */ yytestcase(yyruleno==154);
      case 161: /* groupby_opt ::= */ yytestcase(yyruleno==161);
      case 236: /* exprlist ::= */ yytestcase(yyruleno==236);
      case 242: /* idxlist_opt ::= */ yytestcase(yyruleno==242);
      case 155: /* orderby_opt ::= */ yytestcase(yyruleno==155);
      case 162: /* groupby_opt ::= */ yytestcase(yyruleno==162);
      case 237: /* exprlist ::= */ yytestcase(yyruleno==237);
      case 243: /* eidlist_opt ::= */ yytestcase(yyruleno==243);
{yygotominor.yy14 = 0;}
        break;
      case 127: /* selcollist ::= sclp expr as */
{
   yygotominor.yy14 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy14, yymsp[-1].minor.yy346.pExpr);
   if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[0].minor.yy0, 1);
   sqlite3ExprListSetSpan(pParse,yygotominor.yy14,&yymsp[-1].minor.yy346);
127204
127205
127206
127207
127208
127209
127210
127211

127212
127213
127214
127215
127216
127217
127218
127219
127220
127221
127222






127223

127224
127225
127226
127227
127228

127229
127230
127231
127232
127233
127234
127235
127641
127642
127643
127644
127645
127646
127647

127648
127649
127650
127651
127652
127653
127654
127655
127656
127657
127658
127659
127660
127661
127662
127663
127664
127665

127666
127667
127668
127669
127670

127671
127672
127673
127674
127675
127676
127677
127678







-
+











+
+
+
+
+
+
-
+




-
+







  yygotominor.yy65 = yymsp[0].minor.yy65;
  sqlite3SrcListShiftJoinType(yygotominor.yy65);
}
        break;
      case 135: /* stl_prefix ::= seltablist joinop */
{
   yygotominor.yy65 = yymsp[-1].minor.yy65;
   if( ALWAYS(yygotominor.yy65 && yygotominor.yy65->nSrc>0) ) yygotominor.yy65->a[yygotominor.yy65->nSrc-1].jointype = (u8)yymsp[0].minor.yy328;
   if( ALWAYS(yygotominor.yy65 && yygotominor.yy65->nSrc>0) ) yygotominor.yy65->a[yygotominor.yy65->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy328;
}
        break;
      case 136: /* stl_prefix ::= */
{yygotominor.yy65 = 0;}
        break;
      case 137: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
{
  yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
  sqlite3SrcListIndexedBy(pParse, yygotominor.yy65, &yymsp[-2].minor.yy0);
}
        break;
      case 138: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
{
  yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy65,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
  sqlite3SrcListFuncArgs(pParse, yygotominor.yy65, yymsp[-4].minor.yy14);
}
        break;
      case 138: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
      case 139: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
{
    yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy3,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
  }
        break;
      case 139: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
      case 140: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
{
    if( yymsp[-6].minor.yy65==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy132==0 && yymsp[0].minor.yy408==0 ){
      yygotominor.yy65 = yymsp[-4].minor.yy65;
    }else if( yymsp[-4].minor.yy65->nSrc==1 ){
      yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
      if( yygotominor.yy65 ){
        struct SrcList_item *pNew = &yygotominor.yy65->a[yygotominor.yy65->nSrc-1];
127245
127246
127247
127248
127249
127250
127251
127252
127253


127254
127255
127256

127257
127258
127259

127260
127261
127262

127263
127264
127265

127266
127267
127268

127269
127270
127271
127272
127273
127274
127275





127276
127277
127278
127279
127280
127281
127282





127283
127284
127285

127286
127287
127288
127289


127290
127291
127292
127293


127294
127295
127296
127297
127298



127299
127300
127301

127302
127303
127304

127305
127306
127307

127308
127309
127310

127311
127312
127313
127314
127315





127316
127317
127318


127319
127320

127321
127322
127323

127324
127325
127326

127327
127328
127329

127330
127331
127332

127333
127334
127335
127336
127337
127338
127339

127340
127341
127342
127343
127344
127345
127346
127347

127348
127349
127350
127351
127352
127353

127354
127355
127356
127357
127358
127359

127360
127361
127362
127363
127364
127365

127366
127367
127368
127369
127370
127371

127372
127373
127374

127375
127376
127377

127378
127379
127380

127381
127382
127383

127384
127385
127386

127387
127388
127389
127390
127391



127392
127393
127394
127395


127396
127397
127398

127399
127400
127401
127402
127403
127404
127405
127406

127407
127408
127409
127410
127411
127412
127413
127414
127415
127416

127417
127418
127419
127420
127421
127422
127423
127424
127425
127426
127427
127428
127429
127430
127431
127432
127433
127434
127435
127436

127437
127438
127439
127440
127441
127442
127443

127444
127445
127446
127447
127448
127449

127450
127451
127452
127453
127454
127455
127456
127457
127458
127459
127460
127461

127462
127463
127464
127465
127466
127467

127468
127469
127470
127471
127472
127473
127474
127475
127476
127477
127478
127479
127480








127481
127482
127483

127484
127485
127486

127487
127488
127489

127490
127491
127492
127493
127494
127495
127496
127497
127498
127499
127500
127501

127502
127503
127504
127505
127506
127507
127508
127509
127510
127511
127512
127513
127514

127515
127516
127517

127518
127519
127520

127521
127522
127523
127524
127525
127526

127527
127528
127529
127530
127531
127532
127533


127534
127535
127536

127537
127538
127539

127540
127541
127542

127543
127544
127545
127546
127547
127548
127549
127550
127551
127552
127553
127554
127555
127556
127557

127558
127559
127560
127561
127562
127563
127564
127688
127689
127690
127691
127692
127693
127694


127695
127696
127697
127698

127699
127700
127701

127702
127703
127704

127705
127706
127707

127708
127709
127710

127711
127712
127713





127714
127715
127716
127717
127718
127719
127720





127721
127722
127723
127724
127725
127726
127727

127728
127729
127730


127731
127732
127733
127734


127735
127736
127737
127738



127739
127740
127741
127742
127743

127744
127745
127746

127747
127748
127749

127750
127751
127752

127753
127754
127755



127756
127757
127758
127759
127760
127761


127762
127763
127764

127765
127766
127767

127768
127769
127770

127771
127772
127773

127774
127775
127776

127777
127778
127779
127780
127781
127782
127783

127784
127785
127786
127787
127788
127789
127790
127791

127792
127793
127794
127795
127796
127797

127798
127799
127800
127801
127802
127803

127804
127805
127806
127807
127808
127809

127810
127811
127812
127813
127814
127815

127816
127817
127818

127819
127820
127821

127822
127823
127824

127825
127826
127827

127828
127829
127830

127831
127832
127833



127834
127835
127836
127837
127838


127839
127840
127841
127842

127843
127844
127845
127846
127847
127848
127849
127850

127851
127852
127853
127854
127855
127856
127857
127858
127859
127860

127861
127862
127863
127864
127865
127866
127867
127868
127869
127870
127871
127872
127873
127874
127875
127876
127877
127878
127879
127880

127881
127882
127883
127884
127885
127886
127887

127888
127889
127890
127891
127892
127893

127894
127895
127896
127897
127898
127899
127900
127901
127902
127903
127904
127905

127906
127907
127908
127909
127910
127911

127912
127913
127914
127915
127916
127917








127918
127919
127920
127921
127922
127923
127924
127925
127926
127927

127928
127929
127930

127931
127932
127933

127934
127935
127936
127937
127938
127939
127940
127941
127942
127943
127944
127945

127946
127947
127948
127949
127950
127951
127952
127953
127954
127955
127956
127957
127958

127959
127960
127961

127962
127963
127964

127965
127966
127967
127968
127969
127970

127971
127972
127973
127974
127975
127976


127977
127978
127979
127980

127981
127982
127983

127984
127985
127986

127987
127988
127989
127990
127991
127992
127993
127994
127995
127996
127997
127998
127999
128000
128001

128002
128003
128004
128005
128006
128007
128008
128009







-
-
+
+


-
+


-
+


-
+


-
+


-
+


-
-
-
-
-
+
+
+
+
+


-
-
-
-
-
+
+
+
+
+


-
+


-
-
+
+


-
-
+
+


-
-
-
+
+
+


-
+


-
+


-
+


-
+


-
-
-
+
+
+
+
+

-
-
+
+

-
+


-
+


-
+


-
+


-
+






-
+







-
+





-
+





-
+





-
+





-
+


-
+


-
+


-
+


-
+


-
+


-
-
-
+
+
+


-
-
+
+


-
+







-
+









-
+



















-
+






-
+





-
+











-
+





-
+





-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+


-
+


-
+


-
+











-
+












-
+


-
+


-
+





-
+





-
-
+
+


-
+


-
+


-
+














-
+







      Select *pSubquery;
      sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy65);
      pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy65,0,0,0,0,SF_NestedFrom,0,0);
      yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
    }
  }
        break;
      case 140: /* dbnm ::= */
      case 149: /* indexed_opt ::= */ yytestcase(yyruleno==149);
      case 141: /* dbnm ::= */
      case 150: /* indexed_opt ::= */ yytestcase(yyruleno==150);
{yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
        break;
      case 142: /* fullname ::= nm dbnm */
      case 143: /* fullname ::= nm dbnm */
{yygotominor.yy65 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
        break;
      case 143: /* joinop ::= COMMA|JOIN */
      case 144: /* joinop ::= COMMA|JOIN */
{ yygotominor.yy328 = JT_INNER; }
        break;
      case 144: /* joinop ::= JOIN_KW JOIN */
      case 145: /* joinop ::= JOIN_KW JOIN */
{ yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
        break;
      case 145: /* joinop ::= JOIN_KW nm JOIN */
      case 146: /* joinop ::= JOIN_KW nm JOIN */
{ yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
        break;
      case 146: /* joinop ::= JOIN_KW nm nm JOIN */
      case 147: /* joinop ::= JOIN_KW nm nm JOIN */
{ yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
        break;
      case 147: /* on_opt ::= ON expr */
      case 164: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==164);
      case 171: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==171);
      case 231: /* case_else ::= ELSE expr */ yytestcase(yyruleno==231);
      case 233: /* case_operand ::= expr */ yytestcase(yyruleno==233);
      case 148: /* on_opt ::= ON expr */
      case 165: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==165);
      case 172: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==172);
      case 232: /* case_else ::= ELSE expr */ yytestcase(yyruleno==232);
      case 234: /* case_operand ::= expr */ yytestcase(yyruleno==234);
{yygotominor.yy132 = yymsp[0].minor.yy346.pExpr;}
        break;
      case 148: /* on_opt ::= */
      case 163: /* having_opt ::= */ yytestcase(yyruleno==163);
      case 170: /* where_opt ::= */ yytestcase(yyruleno==170);
      case 232: /* case_else ::= */ yytestcase(yyruleno==232);
      case 234: /* case_operand ::= */ yytestcase(yyruleno==234);
      case 149: /* on_opt ::= */
      case 164: /* having_opt ::= */ yytestcase(yyruleno==164);
      case 171: /* where_opt ::= */ yytestcase(yyruleno==171);
      case 233: /* case_else ::= */ yytestcase(yyruleno==233);
      case 235: /* case_operand ::= */ yytestcase(yyruleno==235);
{yygotominor.yy132 = 0;}
        break;
      case 151: /* indexed_opt ::= NOT INDEXED */
      case 152: /* indexed_opt ::= NOT INDEXED */
{yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
        break;
      case 152: /* using_opt ::= USING LP idlist RP */
      case 180: /* inscollist_opt ::= LP idlist RP */ yytestcase(yyruleno==180);
      case 153: /* using_opt ::= USING LP idlist RP */
      case 181: /* idlist_opt ::= LP idlist RP */ yytestcase(yyruleno==181);
{yygotominor.yy408 = yymsp[-1].minor.yy408;}
        break;
      case 153: /* using_opt ::= */
      case 179: /* inscollist_opt ::= */ yytestcase(yyruleno==179);
      case 154: /* using_opt ::= */
      case 180: /* idlist_opt ::= */ yytestcase(yyruleno==180);
{yygotominor.yy408 = 0;}
        break;
      case 155: /* orderby_opt ::= ORDER BY sortlist */
      case 162: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==162);
      case 235: /* exprlist ::= nexprlist */ yytestcase(yyruleno==235);
      case 156: /* orderby_opt ::= ORDER BY sortlist */
      case 163: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==163);
      case 236: /* exprlist ::= nexprlist */ yytestcase(yyruleno==236);
{yygotominor.yy14 = yymsp[0].minor.yy14;}
        break;
      case 156: /* sortlist ::= sortlist COMMA expr sortorder */
      case 157: /* sortlist ::= sortlist COMMA expr sortorder */
{
  yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy14,yymsp[-1].minor.yy346.pExpr);
  if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
  sqlite3ExprListSetSortOrder(yygotominor.yy14,yymsp[0].minor.yy328);
}
        break;
      case 157: /* sortlist ::= expr sortorder */
      case 158: /* sortlist ::= expr sortorder */
{
  yygotominor.yy14 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy346.pExpr);
  if( yygotominor.yy14 && ALWAYS(yygotominor.yy14->a) ) yygotominor.yy14->a[0].sortOrder = (u8)yymsp[0].minor.yy328;
  sqlite3ExprListSetSortOrder(yygotominor.yy14,yymsp[0].minor.yy328);
}
        break;
      case 158: /* sortorder ::= ASC */
      case 160: /* sortorder ::= */ yytestcase(yyruleno==160);
{yygotominor.yy328 = SQLITE_SO_ASC;}
      case 159: /* sortorder ::= ASC */
{yygotominor.yy328 = SQLITE_SO_ASC;}
        break;
      case 160: /* sortorder ::= DESC */
{yygotominor.yy328 = SQLITE_SO_DESC;}
        break;
      case 159: /* sortorder ::= DESC */
{yygotominor.yy328 = SQLITE_SO_DESC;}
      case 161: /* sortorder ::= */
{yygotominor.yy328 = SQLITE_SO_UNDEFINED;}
        break;
      case 165: /* limit_opt ::= */
      case 166: /* limit_opt ::= */
{yygotominor.yy476.pLimit = 0; yygotominor.yy476.pOffset = 0;}
        break;
      case 166: /* limit_opt ::= LIMIT expr */
      case 167: /* limit_opt ::= LIMIT expr */
{yygotominor.yy476.pLimit = yymsp[0].minor.yy346.pExpr; yygotominor.yy476.pOffset = 0;}
        break;
      case 167: /* limit_opt ::= LIMIT expr OFFSET expr */
      case 168: /* limit_opt ::= LIMIT expr OFFSET expr */
{yygotominor.yy476.pLimit = yymsp[-2].minor.yy346.pExpr; yygotominor.yy476.pOffset = yymsp[0].minor.yy346.pExpr;}
        break;
      case 168: /* limit_opt ::= LIMIT expr COMMA expr */
      case 169: /* limit_opt ::= LIMIT expr COMMA expr */
{yygotominor.yy476.pOffset = yymsp[-2].minor.yy346.pExpr; yygotominor.yy476.pLimit = yymsp[0].minor.yy346.pExpr;}
        break;
      case 169: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
      case 170: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
{
  sqlite3WithPush(pParse, yymsp[-5].minor.yy59, 1);
  sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy65, &yymsp[-1].minor.yy0);
  sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy65,yymsp[0].minor.yy132);
}
        break;
      case 172: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
      case 173: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
{
  sqlite3WithPush(pParse, yymsp[-7].minor.yy59, 1);
  sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy65, &yymsp[-3].minor.yy0);
  sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy14,"set list"); 
  sqlite3Update(pParse,yymsp[-4].minor.yy65,yymsp[-1].minor.yy14,yymsp[0].minor.yy132,yymsp[-5].minor.yy186);
}
        break;
      case 173: /* setlist ::= setlist COMMA nm EQ expr */
      case 174: /* setlist ::= setlist COMMA nm EQ expr */
{
  yygotominor.yy14 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy14, yymsp[0].minor.yy346.pExpr);
  sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
}
        break;
      case 174: /* setlist ::= nm EQ expr */
      case 175: /* setlist ::= nm EQ expr */
{
  yygotominor.yy14 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy346.pExpr);
  sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
}
        break;
      case 175: /* cmd ::= with insert_cmd INTO fullname inscollist_opt select */
      case 176: /* cmd ::= with insert_cmd INTO fullname idlist_opt select */
{
  sqlite3WithPush(pParse, yymsp[-5].minor.yy59, 1);
  sqlite3Insert(pParse, yymsp[-2].minor.yy65, yymsp[0].minor.yy3, yymsp[-1].minor.yy408, yymsp[-4].minor.yy186);
}
        break;
      case 176: /* cmd ::= with insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
      case 177: /* cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */
{
  sqlite3WithPush(pParse, yymsp[-6].minor.yy59, 1);
  sqlite3Insert(pParse, yymsp[-3].minor.yy65, 0, yymsp[-2].minor.yy408, yymsp[-5].minor.yy186);
}
        break;
      case 177: /* insert_cmd ::= INSERT orconf */
      case 178: /* insert_cmd ::= INSERT orconf */
{yygotominor.yy186 = yymsp[0].minor.yy186;}
        break;
      case 178: /* insert_cmd ::= REPLACE */
      case 179: /* insert_cmd ::= REPLACE */
{yygotominor.yy186 = OE_Replace;}
        break;
      case 181: /* idlist ::= idlist COMMA nm */
      case 182: /* idlist ::= idlist COMMA nm */
{yygotominor.yy408 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy408,&yymsp[0].minor.yy0);}
        break;
      case 182: /* idlist ::= nm */
      case 183: /* idlist ::= nm */
{yygotominor.yy408 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
        break;
      case 183: /* expr ::= term */
      case 184: /* expr ::= term */
{yygotominor.yy346 = yymsp[0].minor.yy346;}
        break;
      case 184: /* expr ::= LP expr RP */
      case 185: /* expr ::= LP expr RP */
{yygotominor.yy346.pExpr = yymsp[-1].minor.yy346.pExpr; spanSet(&yygotominor.yy346,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
        break;
      case 185: /* term ::= NULL */
      case 190: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==190);
      case 191: /* term ::= STRING */ yytestcase(yyruleno==191);
      case 186: /* term ::= NULL */
      case 191: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==191);
      case 192: /* term ::= STRING */ yytestcase(yyruleno==192);
{spanExpr(&yygotominor.yy346, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
        break;
      case 186: /* expr ::= ID|INDEXED */
      case 187: /* expr ::= JOIN_KW */ yytestcase(yyruleno==187);
      case 187: /* expr ::= ID|INDEXED */
      case 188: /* expr ::= JOIN_KW */ yytestcase(yyruleno==188);
{spanExpr(&yygotominor.yy346, pParse, TK_ID, &yymsp[0].minor.yy0);}
        break;
      case 188: /* expr ::= nm DOT nm */
      case 189: /* expr ::= nm DOT nm */
{
  Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
  Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
  yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
  spanSet(&yygotominor.yy346,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
}
        break;
      case 189: /* expr ::= nm DOT nm DOT nm */
      case 190: /* expr ::= nm DOT nm DOT nm */
{
  Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
  Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
  Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
  Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
  yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
  spanSet(&yygotominor.yy346,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
}
        break;
      case 192: /* expr ::= VARIABLE */
      case 193: /* expr ::= VARIABLE */
{
  if( yymsp[0].minor.yy0.n>=2 && yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1]) ){
    /* When doing a nested parse, one can include terms in an expression
    ** that look like this:   #1 #2 ...  These terms refer to registers
    ** in the virtual machine.  #N is the N-th register. */
    if( pParse->nested==0 ){
      sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &yymsp[0].minor.yy0);
      yygotominor.yy346.pExpr = 0;
    }else{
      yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &yymsp[0].minor.yy0);
      if( yygotominor.yy346.pExpr ) sqlite3GetInt32(&yymsp[0].minor.yy0.z[1], &yygotominor.yy346.pExpr->iTable);
    }
  }else{
    spanExpr(&yygotominor.yy346, pParse, TK_VARIABLE, &yymsp[0].minor.yy0);
    sqlite3ExprAssignVarNumber(pParse, yygotominor.yy346.pExpr);
  }
  spanSet(&yygotominor.yy346, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
}
        break;
      case 193: /* expr ::= expr COLLATE ID|STRING */
      case 194: /* expr ::= expr COLLATE ID|STRING */
{
  yygotominor.yy346.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy346.pExpr, &yymsp[0].minor.yy0, 1);
  yygotominor.yy346.zStart = yymsp[-2].minor.yy346.zStart;
  yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
}
        break;
      case 194: /* expr ::= CAST LP expr AS typetoken RP */
      case 195: /* expr ::= CAST LP expr AS typetoken RP */
{
  yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy346.pExpr, 0, &yymsp[-1].minor.yy0);
  spanSet(&yygotominor.yy346,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
}
        break;
      case 195: /* expr ::= ID|INDEXED LP distinct exprlist RP */
      case 196: /* expr ::= ID|INDEXED LP distinct exprlist RP */
{
  if( yymsp[-1].minor.yy14 && yymsp[-1].minor.yy14->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
    sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
  }
  yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy14, &yymsp[-4].minor.yy0);
  spanSet(&yygotominor.yy346,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
  if( yymsp[-2].minor.yy381==SF_Distinct && yygotominor.yy346.pExpr ){
    yygotominor.yy346.pExpr->flags |= EP_Distinct;
  }
}
        break;
      case 196: /* expr ::= ID|INDEXED LP STAR RP */
      case 197: /* expr ::= ID|INDEXED LP STAR RP */
{
  yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
  spanSet(&yygotominor.yy346,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
}
        break;
      case 197: /* term ::= CTIME_KW */
      case 198: /* term ::= CTIME_KW */
{
  yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);
  spanSet(&yygotominor.yy346, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
}
        break;
      case 198: /* expr ::= expr AND expr */
      case 199: /* expr ::= expr OR expr */ yytestcase(yyruleno==199);
      case 200: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==200);
      case 201: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==201);
      case 202: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==202);
      case 203: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==203);
      case 204: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==204);
      case 205: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==205);
      case 199: /* expr ::= expr AND expr */
      case 200: /* expr ::= expr OR expr */ yytestcase(yyruleno==200);
      case 201: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==201);
      case 202: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==202);
      case 203: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==203);
      case 204: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==204);
      case 205: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==205);
      case 206: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==206);
{spanBinaryExpr(&yygotominor.yy346,pParse,yymsp[-1].major,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy346);}
        break;
      case 206: /* likeop ::= LIKE_KW|MATCH */
      case 207: /* likeop ::= LIKE_KW|MATCH */
{yygotominor.yy96.eOperator = yymsp[0].minor.yy0; yygotominor.yy96.bNot = 0;}
        break;
      case 207: /* likeop ::= NOT LIKE_KW|MATCH */
      case 208: /* likeop ::= NOT LIKE_KW|MATCH */
{yygotominor.yy96.eOperator = yymsp[0].minor.yy0; yygotominor.yy96.bNot = 1;}
        break;
      case 208: /* expr ::= expr likeop expr */
      case 209: /* expr ::= expr likeop expr */
{
  ExprList *pList;
  pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy346.pExpr);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy346.pExpr);
  yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy96.eOperator);
  if( yymsp[-1].minor.yy96.bNot ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
  yygotominor.yy346.zStart = yymsp[-2].minor.yy346.zStart;
  yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
  if( yygotominor.yy346.pExpr ) yygotominor.yy346.pExpr->flags |= EP_InfixFunc;
}
        break;
      case 209: /* expr ::= expr likeop expr ESCAPE expr */
      case 210: /* expr ::= expr likeop expr ESCAPE expr */
{
  ExprList *pList;
  pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy346.pExpr);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy346.pExpr);
  yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy96.eOperator);
  if( yymsp[-3].minor.yy96.bNot ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
  yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
  yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
  if( yygotominor.yy346.pExpr ) yygotominor.yy346.pExpr->flags |= EP_InfixFunc;
}
        break;
      case 210: /* expr ::= expr ISNULL|NOTNULL */
      case 211: /* expr ::= expr ISNULL|NOTNULL */
{spanUnaryPostfix(&yygotominor.yy346,pParse,yymsp[0].major,&yymsp[-1].minor.yy346,&yymsp[0].minor.yy0);}
        break;
      case 211: /* expr ::= expr NOT NULL */
      case 212: /* expr ::= expr NOT NULL */
{spanUnaryPostfix(&yygotominor.yy346,pParse,TK_NOTNULL,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy0);}
        break;
      case 212: /* expr ::= expr IS expr */
      case 213: /* expr ::= expr IS expr */
{
  spanBinaryExpr(&yygotominor.yy346,pParse,TK_IS,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy346);
  binaryToUnaryIfNull(pParse, yymsp[0].minor.yy346.pExpr, yygotominor.yy346.pExpr, TK_ISNULL);
}
        break;
      case 213: /* expr ::= expr IS NOT expr */
      case 214: /* expr ::= expr IS NOT expr */
{
  spanBinaryExpr(&yygotominor.yy346,pParse,TK_ISNOT,&yymsp[-3].minor.yy346,&yymsp[0].minor.yy346);
  binaryToUnaryIfNull(pParse, yymsp[0].minor.yy346.pExpr, yygotominor.yy346.pExpr, TK_NOTNULL);
}
        break;
      case 214: /* expr ::= NOT expr */
      case 215: /* expr ::= BITNOT expr */ yytestcase(yyruleno==215);
      case 215: /* expr ::= NOT expr */
      case 216: /* expr ::= BITNOT expr */ yytestcase(yyruleno==216);
{spanUnaryPrefix(&yygotominor.yy346,pParse,yymsp[-1].major,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
        break;
      case 216: /* expr ::= MINUS expr */
      case 217: /* expr ::= MINUS expr */
{spanUnaryPrefix(&yygotominor.yy346,pParse,TK_UMINUS,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
        break;
      case 217: /* expr ::= PLUS expr */
      case 218: /* expr ::= PLUS expr */
{spanUnaryPrefix(&yygotominor.yy346,pParse,TK_UPLUS,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
        break;
      case 220: /* expr ::= expr between_op expr AND expr */
      case 221: /* expr ::= expr between_op expr AND expr */
{
  ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
  pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy346.pExpr);
  yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy346.pExpr, 0, 0);
  if( yygotominor.yy346.pExpr ){
    yygotominor.yy346.pExpr->x.pList = pList;
  }else{
    sqlite3ExprListDelete(pParse->db, pList);
  } 
  if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
  yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
  yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
}
        break;
      case 223: /* expr ::= expr in_op LP exprlist RP */
      case 224: /* expr ::= expr in_op LP exprlist RP */
{
    if( yymsp[-1].minor.yy14==0 ){
      /* Expressions of the form
      **
      **      expr1 IN ()
      **      expr1 NOT IN ()
      **
127604
127605
127606
127607
127608
127609
127610
127611

127612
127613
127614
127615
127616
127617
127618
127619
127620
127621
127622
127623
127624
127625

127626
127627
127628
127629
127630
127631
127632
127633
127634
127635
127636
127637
127638
127639
127640

127641
127642
127643
127644
127645
127646
127647
127648
127649
127650
127651
127652
127653
127654
127655
127656

127657
127658
127659
127660
127661
127662
127663
127664
127665
127666
127667
127668
127669
127670

127671
127672
127673
127674
127675
127676
127677
127678
127679
127680
127681
127682
127683
127684

127685
127686
127687
127688
127689
127690

127691
127692
127693
127694
127695
127696

127697
127698
127699

127700
127701
127702

127703
127704
127705
127706
127707
127708
127709
127710


127711
127712
127713

127714
127715
127716

127717
127718
127719
127720

127721
127722
127723
127724
127725

127726
127727
127728
127729

127730
127731
127732
127733
127734
127735
127736
127737

127738
127739
127740
127741


127742
127743
127744

127745
127746
127747

127748
127749
127750

127751
127752
127753

127754
127755
127756

127757
127758
127759

127760
127761
127762
127763
127764
127765
127766
127767

127768
127769
127770
127771
127772
127773
127774


127775
127776
127777

127778
127779
127780

127781
127782
127783
127784


127785
127786
127787

127788
127789
127790
127791


127792
127793
127794
127795


127796
127797
127798

127799
127800
127801
127802
127803
127804
127805
127806

127807
127808
127809
127810
127811
127812
127813

127814
127815
127816
127817
127818
127819
127820
127821

127822
127823
127824
127825
127826
127827
127828

127829
127830
127831
127832
127833
127834
127835

127836
127837
127838

127839
127840
127841

127842
127843
127844

127845
127846
127847

127848
127849
127850
127851
127852
127853
127854
127855
127856
127857

127858
127859
127860
127861
127862
127863
127864
127865
127866
127867

127868
127869
127870

127871
127872
127873

127874
127875
127876
127877
127878

127879
127880
127881
127882
127883

127884
127885
127886
127887
127888

127889
127890
127891

127892
127893
127894

127895
127896
127897

127898
127899
127900

127901
127902
127903
127904
127905

127906
127907
127908
127909
127910

127911
127912
127913
127914
127915
127916

127917
127918
127919

127920
127921
127922

127923
127924
127925
127926
127927

127928
127929
127930
127931
127932



127933
127934
127935

127936
127937
127938
127939


127940
127941
127942

127943
127944
127945
127946
127947

127948
127949
127950
127951
127952
127953
127954
128049
128050
128051
128052
128053
128054
128055

128056
128057
128058
128059
128060
128061
128062
128063
128064
128065
128066
128067
128068
128069

128070
128071
128072
128073
128074
128075
128076
128077
128078
128079
128080
128081
128082
128083
128084

128085
128086
128087
128088
128089
128090
128091
128092
128093
128094
128095
128096
128097
128098
128099
128100

128101
128102
128103
128104
128105
128106
128107
128108
128109
128110
128111
128112
128113
128114

128115
128116
128117
128118
128119
128120
128121
128122
128123
128124
128125
128126
128127
128128

128129
128130
128131
128132
128133
128134

128135
128136
128137
128138
128139
128140

128141
128142
128143

128144
128145
128146

128147
128148
128149
128150
128151
128152
128153


128154
128155
128156
128157

128158
128159
128160

128161
128162



128163


128164
128165

128166
128167



128168


128169
128170




128171
128172
128173


128174
128175
128176
128177

128178
128179
128180

128181
128182
128183

128184
128185
128186

128187
128188
128189

128190
128191
128192

128193
128194
128195
128196
128197
128198
128199
128200

128201
128202
128203
128204
128205
128206


128207
128208
128209
128210

128211
128212
128213

128214
128215
128216


128217
128218
128219
128220

128221
128222
128223


128224
128225
128226
128227


128228
128229
128230
128231

128232
128233
128234
128235
128236
128237
128238
128239

128240
128241
128242
128243
128244
128245
128246

128247
128248
128249
128250
128251
128252
128253
128254

128255
128256
128257
128258
128259
128260
128261

128262
128263
128264
128265
128266
128267
128268

128269
128270
128271

128272
128273
128274

128275
128276
128277

128278
128279
128280

128281
128282
128283
128284
128285
128286
128287
128288
128289
128290

128291
128292
128293
128294
128295
128296
128297
128298
128299
128300

128301
128302
128303

128304
128305
128306

128307
128308
128309
128310
128311

128312
128313
128314
128315
128316

128317
128318
128319
128320
128321

128322
128323
128324

128325
128326
128327

128328
128329
128330

128331
128332
128333

128334
128335
128336
128337
128338

128339
128340
128341
128342
128343

128344
128345
128346
128347
128348
128349

128350
128351
128352

128353
128354
128355

128356
128357
128358
128359
128360

128361
128362
128363



128364
128365
128366
128367
128368

128369
128370
128371


128372
128373
128374
128375

128376
128377
128378
128379
128380

128381
128382
128383
128384
128385
128386
128387
128388







-
+













-
+














-
+















-
+













-
+













-
+





-
+





-
+


-
+


-
+






-
-
+
+


-
+


-
+

-
-
-
+
-
-


-
+

-
-
-
+
-
-


-
-
-
-
+


-
-
+
+


-
+


-
+


-
+


-
+


-
+


-
+







-
+





-
-
+
+


-
+


-
+


-
-
+
+


-
+


-
-
+
+


-
-
+
+


-
+







-
+






-
+







-
+






-
+






-
+


-
+


-
+


-
+


-
+









-
+









-
+


-
+


-
+




-
+




-
+




-
+


-
+


-
+


-
+


-
+




-
+




-
+





-
+


-
+


-
+




-
+


-
-
-
+
+
+


-
+


-
-
+
+


-
+




-
+







      }
      if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
    }
    yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
    yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
  }
        break;
      case 224: /* expr ::= LP select RP */
      case 225: /* expr ::= LP select RP */
{
    yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
    if( yygotominor.yy346.pExpr ){
      yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
      ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
      sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
    }else{
      sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
    }
    yygotominor.yy346.zStart = yymsp[-2].minor.yy0.z;
    yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
  }
        break;
      case 225: /* expr ::= expr in_op LP select RP */
      case 226: /* expr ::= expr in_op LP select RP */
{
    yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy346.pExpr, 0, 0);
    if( yygotominor.yy346.pExpr ){
      yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
      ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
      sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
    }else{
      sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
    }
    if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
    yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
    yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
  }
        break;
      case 226: /* expr ::= expr in_op nm dbnm */
      case 227: /* expr ::= expr in_op nm dbnm */
{
    SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
    yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy346.pExpr, 0, 0);
    if( yygotominor.yy346.pExpr ){
      yygotominor.yy346.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
      ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
      sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
    }else{
      sqlite3SrcListDelete(pParse->db, pSrc);
    }
    if( yymsp[-2].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
    yygotominor.yy346.zStart = yymsp[-3].minor.yy346.zStart;
    yygotominor.yy346.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
  }
        break;
      case 227: /* expr ::= EXISTS LP select RP */
      case 228: /* expr ::= EXISTS LP select RP */
{
    Expr *p = yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
    if( p ){
      p->x.pSelect = yymsp[-1].minor.yy3;
      ExprSetProperty(p, EP_xIsSelect|EP_Subquery);
      sqlite3ExprSetHeightAndFlags(pParse, p);
    }else{
      sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy3);
    }
    yygotominor.yy346.zStart = yymsp[-3].minor.yy0.z;
    yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
  }
        break;
      case 228: /* expr ::= CASE case_operand case_exprlist case_else END */
      case 229: /* expr ::= CASE case_operand case_exprlist case_else END */
{
  yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy132, 0, 0);
  if( yygotominor.yy346.pExpr ){
    yygotominor.yy346.pExpr->x.pList = yymsp[-1].minor.yy132 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[-1].minor.yy132) : yymsp[-2].minor.yy14;
    sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
  }else{
    sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy14);
    sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy132);
  }
  yygotominor.yy346.zStart = yymsp[-4].minor.yy0.z;
  yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
}
        break;
      case 229: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
      case 230: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
{
  yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy14, yymsp[-2].minor.yy346.pExpr);
  yygotominor.yy14 = sqlite3ExprListAppend(pParse,yygotominor.yy14, yymsp[0].minor.yy346.pExpr);
}
        break;
      case 230: /* case_exprlist ::= WHEN expr THEN expr */
      case 231: /* case_exprlist ::= WHEN expr THEN expr */
{
  yygotominor.yy14 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
  yygotominor.yy14 = sqlite3ExprListAppend(pParse,yygotominor.yy14, yymsp[0].minor.yy346.pExpr);
}
        break;
      case 237: /* nexprlist ::= nexprlist COMMA expr */
      case 238: /* nexprlist ::= nexprlist COMMA expr */
{yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[0].minor.yy346.pExpr);}
        break;
      case 238: /* nexprlist ::= expr */
      case 239: /* nexprlist ::= expr */
{yygotominor.yy14 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy346.pExpr);}
        break;
      case 239: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt */
      case 240: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
{
  sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, 
                     sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy14, yymsp[-10].minor.yy328,
                      &yymsp[-11].minor.yy0, yymsp[0].minor.yy132, SQLITE_SO_ASC, yymsp[-8].minor.yy328);
}
        break;
      case 240: /* uniqueflag ::= UNIQUE */
      case 291: /* raisetype ::= ABORT */ yytestcase(yyruleno==291);
      case 241: /* uniqueflag ::= UNIQUE */
      case 292: /* raisetype ::= ABORT */ yytestcase(yyruleno==292);
{yygotominor.yy328 = OE_Abort;}
        break;
      case 241: /* uniqueflag ::= */
      case 242: /* uniqueflag ::= */
{yygotominor.yy328 = OE_None;}
        break;
      case 244: /* idxlist ::= idxlist COMMA nm collate sortorder */
      case 245: /* eidlist ::= eidlist COMMA nm collate sortorder */
{
  Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0, 1);
  yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy14, p);
  sqlite3ExprListSetName(pParse,yygotominor.yy14,&yymsp[-2].minor.yy0,1);
  yygotominor.yy14 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy14, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy328, yymsp[0].minor.yy328);
  sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
  if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
}
        break;
      case 245: /* idxlist ::= nm collate sortorder */
      case 246: /* eidlist ::= nm collate sortorder */
{
  Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0, 1);
  yygotominor.yy14 = sqlite3ExprListAppend(pParse,0, p);
  sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
  yygotominor.yy14 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy328, yymsp[0].minor.yy328);
  sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
  if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
}
        break;
      case 246: /* collate ::= */
{yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
        break;
      case 248: /* cmd ::= DROP INDEX ifexists fullname */
      case 249: /* cmd ::= DROP INDEX ifexists fullname */
{sqlite3DropIndex(pParse, yymsp[0].minor.yy65, yymsp[-1].minor.yy328);}
        break;
      case 249: /* cmd ::= VACUUM */
      case 250: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==250);
      case 250: /* cmd ::= VACUUM */
      case 251: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==251);
{sqlite3Vacuum(pParse);}
        break;
      case 251: /* cmd ::= PRAGMA nm dbnm */
      case 252: /* cmd ::= PRAGMA nm dbnm */
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
        break;
      case 252: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
      case 253: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
        break;
      case 253: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
      case 254: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
        break;
      case 254: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
      case 255: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
        break;
      case 255: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
      case 256: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
        break;
      case 264: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
      case 265: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
{
  Token all;
  all.z = yymsp[-3].minor.yy0.z;
  all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
  sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy473, &all);
}
        break;
      case 265: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
      case 266: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
{
  sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy328, yymsp[-4].minor.yy378.a, yymsp[-4].minor.yy378.b, yymsp[-2].minor.yy65, yymsp[0].minor.yy132, yymsp[-10].minor.yy328, yymsp[-8].minor.yy328);
  yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
}
        break;
      case 266: /* trigger_time ::= BEFORE */
      case 269: /* trigger_time ::= */ yytestcase(yyruleno==269);
      case 267: /* trigger_time ::= BEFORE */
      case 270: /* trigger_time ::= */ yytestcase(yyruleno==270);
{ yygotominor.yy328 = TK_BEFORE; }
        break;
      case 267: /* trigger_time ::= AFTER */
      case 268: /* trigger_time ::= AFTER */
{ yygotominor.yy328 = TK_AFTER;  }
        break;
      case 268: /* trigger_time ::= INSTEAD OF */
      case 269: /* trigger_time ::= INSTEAD OF */
{ yygotominor.yy328 = TK_INSTEAD;}
        break;
      case 270: /* trigger_event ::= DELETE|INSERT */
      case 271: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==271);
      case 271: /* trigger_event ::= DELETE|INSERT */
      case 272: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==272);
{yygotominor.yy378.a = yymsp[0].major; yygotominor.yy378.b = 0;}
        break;
      case 272: /* trigger_event ::= UPDATE OF idlist */
      case 273: /* trigger_event ::= UPDATE OF idlist */
{yygotominor.yy378.a = TK_UPDATE; yygotominor.yy378.b = yymsp[0].minor.yy408;}
        break;
      case 275: /* when_clause ::= */
      case 296: /* key_opt ::= */ yytestcase(yyruleno==296);
      case 276: /* when_clause ::= */
      case 297: /* key_opt ::= */ yytestcase(yyruleno==297);
{ yygotominor.yy132 = 0; }
        break;
      case 276: /* when_clause ::= WHEN expr */
      case 297: /* key_opt ::= KEY expr */ yytestcase(yyruleno==297);
      case 277: /* when_clause ::= WHEN expr */
      case 298: /* key_opt ::= KEY expr */ yytestcase(yyruleno==298);
{ yygotominor.yy132 = yymsp[0].minor.yy346.pExpr; }
        break;
      case 277: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
      case 278: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
{
  assert( yymsp[-2].minor.yy473!=0 );
  yymsp[-2].minor.yy473->pLast->pNext = yymsp[-1].minor.yy473;
  yymsp[-2].minor.yy473->pLast = yymsp[-1].minor.yy473;
  yygotominor.yy473 = yymsp[-2].minor.yy473;
}
        break;
      case 278: /* trigger_cmd_list ::= trigger_cmd SEMI */
      case 279: /* trigger_cmd_list ::= trigger_cmd SEMI */
{ 
  assert( yymsp[-1].minor.yy473!=0 );
  yymsp[-1].minor.yy473->pLast = yymsp[-1].minor.yy473;
  yygotominor.yy473 = yymsp[-1].minor.yy473;
}
        break;
      case 280: /* trnm ::= nm DOT nm */
      case 281: /* trnm ::= nm DOT nm */
{
  yygotominor.yy0 = yymsp[0].minor.yy0;
  sqlite3ErrorMsg(pParse, 
        "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
        "statements within triggers");
}
        break;
      case 282: /* tridxby ::= INDEXED BY nm */
      case 283: /* tridxby ::= INDEXED BY nm */
{
  sqlite3ErrorMsg(pParse,
        "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
        "within triggers");
}
        break;
      case 283: /* tridxby ::= NOT INDEXED */
      case 284: /* tridxby ::= NOT INDEXED */
{
  sqlite3ErrorMsg(pParse,
        "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
        "within triggers");
}
        break;
      case 284: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
      case 285: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
{ yygotominor.yy473 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy14, yymsp[0].minor.yy132, yymsp[-5].minor.yy186); }
        break;
      case 285: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
      case 286: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */
{yygotominor.yy473 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy408, yymsp[0].minor.yy3, yymsp[-4].minor.yy186);}
        break;
      case 286: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
      case 287: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
{yygotominor.yy473 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy132);}
        break;
      case 287: /* trigger_cmd ::= select */
      case 288: /* trigger_cmd ::= select */
{yygotominor.yy473 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy3); }
        break;
      case 288: /* expr ::= RAISE LP IGNORE RP */
      case 289: /* expr ::= RAISE LP IGNORE RP */
{
  yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0); 
  if( yygotominor.yy346.pExpr ){
    yygotominor.yy346.pExpr->affinity = OE_Ignore;
  }
  yygotominor.yy346.zStart = yymsp[-3].minor.yy0.z;
  yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
}
        break;
      case 289: /* expr ::= RAISE LP raisetype COMMA nm RP */
      case 290: /* expr ::= RAISE LP raisetype COMMA nm RP */
{
  yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0); 
  if( yygotominor.yy346.pExpr ) {
    yygotominor.yy346.pExpr->affinity = (char)yymsp[-3].minor.yy328;
  }
  yygotominor.yy346.zStart = yymsp[-5].minor.yy0.z;
  yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
}
        break;
      case 290: /* raisetype ::= ROLLBACK */
      case 291: /* raisetype ::= ROLLBACK */
{yygotominor.yy328 = OE_Rollback;}
        break;
      case 292: /* raisetype ::= FAIL */
      case 293: /* raisetype ::= FAIL */
{yygotominor.yy328 = OE_Fail;}
        break;
      case 293: /* cmd ::= DROP TRIGGER ifexists fullname */
      case 294: /* cmd ::= DROP TRIGGER ifexists fullname */
{
  sqlite3DropTrigger(pParse,yymsp[0].minor.yy65,yymsp[-1].minor.yy328);
}
        break;
      case 294: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
      case 295: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
{
  sqlite3Attach(pParse, yymsp[-3].minor.yy346.pExpr, yymsp[-1].minor.yy346.pExpr, yymsp[0].minor.yy132);
}
        break;
      case 295: /* cmd ::= DETACH database_kw_opt expr */
      case 296: /* cmd ::= DETACH database_kw_opt expr */
{
  sqlite3Detach(pParse, yymsp[0].minor.yy346.pExpr);
}
        break;
      case 300: /* cmd ::= REINDEX */
      case 301: /* cmd ::= REINDEX */
{sqlite3Reindex(pParse, 0, 0);}
        break;
      case 301: /* cmd ::= REINDEX nm dbnm */
      case 302: /* cmd ::= REINDEX nm dbnm */
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
        break;
      case 302: /* cmd ::= ANALYZE */
      case 303: /* cmd ::= ANALYZE */
{sqlite3Analyze(pParse, 0, 0);}
        break;
      case 303: /* cmd ::= ANALYZE nm dbnm */
      case 304: /* cmd ::= ANALYZE nm dbnm */
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
        break;
      case 304: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
      case 305: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
{
  sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy65,&yymsp[0].minor.yy0);
}
        break;
      case 305: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
      case 306: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
{
  sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
}
        break;
      case 306: /* add_column_fullname ::= fullname */
      case 307: /* add_column_fullname ::= fullname */
{
  pParse->db->lookaside.bEnabled = 0;
  sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy65);
}
        break;
      case 309: /* cmd ::= create_vtab */
      case 310: /* cmd ::= create_vtab */
{sqlite3VtabFinishParse(pParse,0);}
        break;
      case 310: /* cmd ::= create_vtab LP vtabarglist RP */
      case 311: /* cmd ::= create_vtab LP vtabarglist RP */
{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
        break;
      case 311: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
      case 312: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
{
    sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy328);
}
        break;
      case 314: /* vtabarg ::= */
      case 315: /* vtabarg ::= */
{sqlite3VtabArgInit(pParse);}
        break;
      case 316: /* vtabargtoken ::= ANY */
      case 317: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==317);
      case 318: /* lp ::= LP */ yytestcase(yyruleno==318);
      case 317: /* vtabargtoken ::= ANY */
      case 318: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==318);
      case 319: /* lp ::= LP */ yytestcase(yyruleno==319);
{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
        break;
      case 322: /* with ::= */
      case 323: /* with ::= */
{yygotominor.yy59 = 0;}
        break;
      case 323: /* with ::= WITH wqlist */
      case 324: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==324);
      case 324: /* with ::= WITH wqlist */
      case 325: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==325);
{ yygotominor.yy59 = yymsp[0].minor.yy59; }
        break;
      case 325: /* wqlist ::= nm idxlist_opt AS LP select RP */
      case 326: /* wqlist ::= nm eidlist_opt AS LP select RP */
{
  yygotominor.yy59 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy14, yymsp[-1].minor.yy3);
}
        break;
      case 326: /* wqlist ::= wqlist COMMA nm idxlist_opt AS LP select RP */
      case 327: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
{
  yygotominor.yy59 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy59, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy14, yymsp[-1].minor.yy3);
}
        break;
      default:
      /* (0) input ::= cmdlist */ yytestcase(yyruleno==0);
      /* (1) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==1);
127968
127969
127970
127971
127972
127973
127974
127975
127976
127977
127978
127979
127980
127981
127982
127983
127984
127985
127986
127987













127988
127989
127990
127991
127992
127993
127994
127995
127996
127997



127998
127999
128000
128001
128002
128003
128004
128005
128006

128007

128008
128009
128010
128011
128012
128013

128014
128015
128016
128017
128018
128019
128020
128402
128403
128404
128405
128406
128407
128408













128409
128410
128411
128412
128413
128414
128415
128416
128417
128418
128419
128420
128421
128422
128423
128424
128425
128426
128427
128428



128429
128430
128431
128432
128433
128434
128435
128436
128437
128438
128439
128440
128441

128442


128443
128444
128445

128446
128447
128448
128449
128450
128451
128452
128453







-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+







-
-
-
+
+
+









+
-
+
-
-



-
+







      /* (51) signed ::= minus_num */ yytestcase(yyruleno==51);
      /* (52) carglist ::= carglist ccons */ yytestcase(yyruleno==52);
      /* (53) carglist ::= */ yytestcase(yyruleno==53);
      /* (60) ccons ::= NULL onconf */ yytestcase(yyruleno==60);
      /* (88) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==88);
      /* (89) conslist ::= tcons */ yytestcase(yyruleno==89);
      /* (91) tconscomma ::= */ yytestcase(yyruleno==91);
      /* (273) foreach_clause ::= */ yytestcase(yyruleno==273);
      /* (274) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==274);
      /* (281) tridxby ::= */ yytestcase(yyruleno==281);
      /* (298) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==298);
      /* (299) database_kw_opt ::= */ yytestcase(yyruleno==299);
      /* (307) kwcolumn_opt ::= */ yytestcase(yyruleno==307);
      /* (308) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==308);
      /* (312) vtabarglist ::= vtabarg */ yytestcase(yyruleno==312);
      /* (313) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==313);
      /* (315) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==315);
      /* (319) anylist ::= */ yytestcase(yyruleno==319);
      /* (320) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==320);
      /* (321) anylist ::= anylist ANY */ yytestcase(yyruleno==321);
      /* (274) foreach_clause ::= */ yytestcase(yyruleno==274);
      /* (275) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==275);
      /* (282) tridxby ::= */ yytestcase(yyruleno==282);
      /* (299) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==299);
      /* (300) database_kw_opt ::= */ yytestcase(yyruleno==300);
      /* (308) kwcolumn_opt ::= */ yytestcase(yyruleno==308);
      /* (309) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==309);
      /* (313) vtabarglist ::= vtabarg */ yytestcase(yyruleno==313);
      /* (314) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==314);
      /* (316) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==316);
      /* (320) anylist ::= */ yytestcase(yyruleno==320);
      /* (321) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==321);
      /* (322) anylist ::= anylist ANY */ yytestcase(yyruleno==322);
        break;
  };
  assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
  yygoto = yyRuleInfo[yyruleno].lhs;
  yysize = yyRuleInfo[yyruleno].nrhs;
  yypParser->yyidx -= yysize;
  yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
  if( yyact < YYNSTATE ){
#ifdef NDEBUG
    /* If we are not debugging and the reduce action popped at least
  if( yyact <= YY_MAX_SHIFTREDUCE ){
    if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
    /* If the reduce action popped at least
    ** one element off the stack, then we can push the new element back
    ** onto the stack here, and skip the stack overflow test in yy_shift().
    ** That gives a significant speed improvement. */
    if( yysize ){
      yypParser->yyidx++;
      yymsp -= yysize-1;
      yymsp->stateno = (YYACTIONTYPE)yyact;
      yymsp->major = (YYCODETYPE)yygoto;
      yymsp->minor = yygotominor;
      yyTraceShift(yypParser, yyact);
    }else
    }else{
#endif
    {
      yy_shift(yypParser,yyact,yygoto,&yygotominor);
    }
  }else{
    assert( yyact == YYNSTATE + YYNRULE + 1 );
    assert( yyact == YY_ACCEPT_ACTION );
    yy_accept(yypParser);
  }
}

/*
** The following code executes when the parse fails
*/
128131
128132
128133
128134
128135
128136
128137
128138


128139
128140
128141
128142
128143


128144
128145
128146
128147
128148
128149
128150
128564
128565
128566
128567
128568
128569
128570

128571
128572
128573
128574
128575


128576
128577
128578
128579
128580
128581
128582
128583
128584







-
+
+



-
-
+
+







  if( yyTraceFILE ){
    fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
  }
#endif

  do{
    yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
    if( yyact<YYNSTATE ){
    if( yyact <= YY_MAX_SHIFTREDUCE ){
      if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
      yy_shift(yypParser,yyact,yymajor,&yyminorunion);
      yypParser->yyerrcnt--;
      yymajor = YYNOCODE;
    }else if( yyact < YYNSTATE + YYNRULE ){
      yy_reduce(yypParser,yyact-YYNSTATE);
    }else if( yyact <= YY_MAX_REDUCE ){
      yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
    }else{
      assert( yyact == YY_ERROR_ACTION );
#ifdef YYERRORSYMBOL
      int yymx;
#endif
#ifndef NDEBUG
      if( yyTraceFILE ){
128186
128187
128188
128189
128190
128191
128192
128193

128194
128195
128196
128197
128198
128199
128200
128620
128621
128622
128623
128624
128625
128626

128627
128628
128629
128630
128631
128632
128633
128634







-
+







        yymajor = YYNOCODE;
      }else{
         while(
          yypParser->yyidx >= 0 &&
          yymx != YYERRORSYMBOL &&
          (yyact = yy_find_reduce_action(
                        yypParser->yystack[yypParser->yyidx].stateno,
                        YYERRORSYMBOL)) >= YYNSTATE
                        YYERRORSYMBOL)) >= YY_MIN_REDUCE
        ){
          yy_pop_parser_stack(yypParser);
        }
        if( yypParser->yyidx < 0 || yymajor==0 ){
          yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
          yy_parse_failed(yypParser);
          yymajor = YYNOCODE;
128236
128237
128238
128239
128240
128241
128242





128243
128244
128245
128246
128247
128248
128249
128670
128671
128672
128673
128674
128675
128676
128677
128678
128679
128680
128681
128682
128683
128684
128685
128686
128687
128688







+
+
+
+
+







      if( yyendofinput ){
        yy_parse_failed(yypParser);
      }
      yymajor = YYNOCODE;
#endif
    }
  }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
#ifndef NDEBUG
  if( yyTraceFILE ){
    fprintf(yyTraceFILE,"%sReturn\n",yyTracePrompt);
  }
#endif
  return;
}

/************** End of parse.c ***********************************************/
/************** Begin file tokenize.c ****************************************/
/*
** 2001 September 15
128924
128925
128926
128927
128928
128929
128930

128931
128932
128933
128934
128935
128936
128937
129363
129364
129365
129366
129367
129368
129369
129370
129371
129372
129373
129374
129375
129376
129377







+







  if( db->nVdbeActive==0 ){
    db->u1.isInterrupted = 0;
  }
  pParse->rc = SQLITE_OK;
  pParse->zTail = zSql;
  i = 0;
  assert( pzErrMsg!=0 );
  /* sqlite3ParserTrace(stdout, "parser: "); */
  pEngine = sqlite3ParserAlloc(sqlite3Malloc);
  if( pEngine==0 ){
    db->mallocFailed = 1;
    return SQLITE_NOMEM;
  }
  assert( pParse->pNewTable==0 );
  assert( pParse->pNewTrigger==0 );
130368
130369
130370
130371
130372
130373
130374

130375
130376
130377
130378
130379
130380
130381
130382
130383
130384






130385
130386
130387
130388
130389
130390
130391
130808
130809
130810
130811
130812
130813
130814
130815
130816
130817
130818
130819

130820
130821
130822
130823
130824
130825
130826
130827
130828
130829
130830
130831
130832
130833
130834
130835
130836
130837







+




-





+
+
+
+
+
+







/*
** Disconnect all sqlite3_vtab objects that belong to database connection
** db. This is called when db is being closed.
*/
static void disconnectAllVtab(sqlite3 *db){
#ifndef SQLITE_OMIT_VIRTUALTABLE
  int i;
  HashElem *p;
  sqlite3BtreeEnterAll(db);
  for(i=0; i<db->nDb; i++){
    Schema *pSchema = db->aDb[i].pSchema;
    if( db->aDb[i].pSchema ){
      HashElem *p;
      for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
        Table *pTab = (Table *)sqliteHashData(p);
        if( IsVirtual(pTab) ) sqlite3VtabDisconnect(db, pTab);
      }
    }
  }
  for(p=sqliteHashFirst(&db->aModule); p; p=sqliteHashNext(p)){
    Module *pMod = (Module *)sqliteHashData(p);
    if( pMod->pEpoTab ){
      sqlite3VtabDisconnect(db, pMod->pEpoTab);
    }
  }
  sqlite3VtabUnlockList(db);
  sqlite3BtreeLeaveAll(db);
#else
  UNUSED_PARAMETER(db);
#endif
}
130556
130557
130558
130559
130560
130561
130562

130563
130564
130565
130566
130567
130568
130569
131002
131003
131004
131005
131006
131007
131008
131009
131010
131011
131012
131013
131014
131015
131016







+







  sqlite3HashClear(&db->aCollSeq);
#ifndef SQLITE_OMIT_VIRTUALTABLE
  for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
    Module *pMod = (Module *)sqliteHashData(i);
    if( pMod->xDestroy ){
      pMod->xDestroy(pMod->pAux);
    }
    sqlite3VtabEponymousTableClear(db, pMod);
    sqlite3DbFree(db, pMod);
  }
  sqlite3HashClear(&db->aModule);
#endif

  sqlite3Error(db, SQLITE_OK); /* Deallocates any cached error strings. */
  sqlite3ValueFree(db->pErr);
156960
156961
156962
156963
156964
156965
156966
156967
156968
156969
156970
156971
156972
156973
156974
156975
156976
156977
157407
157408
157409
157410
157411
157412
157413




157414
157415
157416
157417
157418
157419
157420







-
-
-
-







** 
*/

/* #include <assert.h> */
/* #include <string.h> */
/* #include <stdio.h> */

#if !defined(_WIN32)
/* #  include <unistd.h> */
#endif

/* #include "sqlite3.h" */

#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU)
/************** Include sqlite3rbu.h in the middle of sqlite3rbu.c ***********/
/************** Begin file sqlite3rbu.h **************************************/
/*
** 2014 August 30
157068
157069
157070
157071
157072
157073
157074












157075
157076
157077
157078
157079
157080
157081
157511
157512
157513
157514
157515
157516
157517
157518
157519
157520
157521
157522
157523
157524
157525
157526
157527
157528
157529
157530
157531
157532
157533
157534
157535
157536







+
+
+
+
+
+
+
+
+
+
+
+







**
** Then the RBU database should contain:
**
**   CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control);
**
** The order of the columns in the data_% table does not matter.
**
** Instead of a regular table, the RBU database may also contain virtual
** tables or view named using the data_<target> naming scheme. 
**
** Instead of the plain data_<target> naming scheme, RBU database tables 
** may also be named data<integer>_<target>, where <integer> is any sequence
** of zero or more numeric characters (0-9). This can be significant because
** tables within the RBU database are always processed in order sorted by 
** name. By judicious selection of the the <integer> portion of the names
** of the RBU tables the user can therefore control the order in which they
** are processed. This can be useful, for example, to ensure that "external
** content" FTS4 tables are updated before their underlying content tables.
**
** If the target database table is a virtual table or a table that has no
** PRIMARY KEY declaration, the data_% table must also contain a column 
** named "rbu_rowid". This column is mapped to the tables implicit primary 
** key column - "rowid". Virtual tables for which the "rowid" column does 
** not function like a primary key value cannot be updated using RBU. For 
** example, if the target db contains either of the following:
**
157147
157148
157149
157150
157151
157152
157153








157154
157155
157156
157157
157158
157159
157160
157602
157603
157604
157605
157606
157607
157608
157609
157610
157611
157612
157613
157614
157615
157616
157617
157618
157619
157620
157621
157622
157623







+
+
+
+
+
+
+
+







** For example, this row:
**
**   INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d');
**
** is similar to an UPDATE statement such as: 
**
**   UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4;
**
** Finally, if an 'f' character appears in place of a 'd' or 's' in an 
** ota_control string, the contents of the data_xxx table column is assumed
** to be a "fossil delta" - a patch to be applied to a blob value in the
** format used by the fossil source-code management system. In this case
** the existing value within the target database table must be of type BLOB. 
** It is replaced by the result of applying the specified fossil delta to
** itself.
**
** If the target database table is a virtual table or a table with no PRIMARY
** KEY, the rbu_control value should not include a character corresponding 
** to the rbu_rowid value. For example, this:
**
**   INSERT INTO data_ft1(a, b, rbu_rowid, rbu_control) 
**       VALUES(NULL, 'usa', 12, '.x');
157305
157306
157307
157308
157309
157310
157311












157312
157313
157314
157315
157316
157317
157318
157768
157769
157770
157771
157772
157773
157774
157775
157776
157777
157778
157779
157780
157781
157782
157783
157784
157785
157786
157787
157788
157789
157790
157791
157792
157793







+
+
+
+
+
+
+
+
+
+
+
+







**
** Once a call to sqlite3rbu_step() has returned a value other than
** SQLITE_OK, all subsequent calls on the same RBU handle are no-ops
** that immediately return the same value.
*/
SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *pRbu);

/*
** Force RBU to save its state to disk.
**
** If a power failure or application crash occurs during an update, following
** system recovery RBU may resume the update from the point at which the state
** was last saved. In other words, from the most recent successful call to 
** sqlite3rbu_close() or this function.
**
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
*/
SQLITE_API int SQLITE_STDCALL sqlite3rbu_savestate(sqlite3rbu *pRbu);

/*
** Close an RBU handle. 
**
** If the RBU update has been completely applied, mark the RBU database
** as fully applied. Otherwise, assuming no error has occurred, save the
** current state of the RBU update appliation to the RBU database.
**
157537
157538
157539
157540
157541
157542
157543

157544
157545
157546
157547
157548
157549
157550
157551
157552
157553
157554

157555
157556
157557
157558
157559
157560
157561
158012
158013
158014
158015
158016
158017
158018
158019
158020
158021
158022
158023
158024
158025
158026
158027
158028
158029

158030
158031
158032
158033
158034
158035
158036
158037







+










-
+







  u8 *abNotNull;                  /* Array of flags, set on NOT NULL columns */
  u8 *abIndexed;                  /* Array of flags, set on indexed & PK cols */
  int eType;                      /* Table type - an RBU_PK_XXX value */

  /* Output variables. zTbl==0 implies EOF. */
  int bCleanup;                   /* True in "cleanup" state */
  const char *zTbl;               /* Name of target db table */
  const char *zDataTbl;           /* Name of rbu db table (or null) */
  const char *zIdx;               /* Name of target db index (or null) */
  int iTnum;                      /* Root page of current object */
  int iPkTnum;                    /* If eType==EXTERNAL, root of PK index */
  int bUnique;                    /* Current index is unique */

  /* Statements created by rbuObjIterPrepareAll() */
  int nCol;                       /* Number of columns in current object */
  sqlite3_stmt *pSelect;          /* Source data */
  sqlite3_stmt *pInsert;          /* Statement for INSERT operations */
  sqlite3_stmt *pDelete;          /* Statement for DELETE ops */
  sqlite3_stmt *pTmpInsert;       /* Insert into rbu_tmp_$zTbl */
  sqlite3_stmt *pTmpInsert;       /* Insert into rbu_tmp_$zDataTbl */

  /* Last UPDATE used (for PK b-tree updates only), or NULL. */
  RbuUpdateStmt *pRbuUpdate;
};

/*
** Values for RbuObjIter.eType
157657
157658
157659
157660
157661
157662
157663






















































































































































































































































157664
157665
157666
157667
157668
157669
157670
158133
158134
158135
158136
158137
158138
158139
158140
158141
158142
158143
158144
158145
158146
158147
158148
158149
158150
158151
158152
158153
158154
158155
158156
158157
158158
158159
158160
158161
158162
158163
158164
158165
158166
158167
158168
158169
158170
158171
158172
158173
158174
158175
158176
158177
158178
158179
158180
158181
158182
158183
158184
158185
158186
158187
158188
158189
158190
158191
158192
158193
158194
158195
158196
158197
158198
158199
158200
158201
158202
158203
158204
158205
158206
158207
158208
158209
158210
158211
158212
158213
158214
158215
158216
158217
158218
158219
158220
158221
158222
158223
158224
158225
158226
158227
158228
158229
158230
158231
158232
158233
158234
158235
158236
158237
158238
158239
158240
158241
158242
158243
158244
158245
158246
158247
158248
158249
158250
158251
158252
158253
158254
158255
158256
158257
158258
158259
158260
158261
158262
158263
158264
158265
158266
158267
158268
158269
158270
158271
158272
158273
158274
158275
158276
158277
158278
158279
158280
158281
158282
158283
158284
158285
158286
158287
158288
158289
158290
158291
158292
158293
158294
158295
158296
158297
158298
158299
158300
158301
158302
158303
158304
158305
158306
158307
158308
158309
158310
158311
158312
158313
158314
158315
158316
158317
158318
158319
158320
158321
158322
158323
158324
158325
158326
158327
158328
158329
158330
158331
158332
158333
158334
158335
158336
158337
158338
158339
158340
158341
158342
158343
158344
158345
158346
158347
158348
158349
158350
158351
158352
158353
158354
158355
158356
158357
158358
158359
158360
158361
158362
158363
158364
158365
158366
158367
158368
158369
158370
158371
158372
158373
158374
158375
158376
158377
158378
158379
158380
158381
158382
158383
158384
158385
158386
158387
158388
158389
158390
158391
158392







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  char *zDel;                     /* Delete this when closing file */

  const char *zWal;               /* Wal filename for this main db file */
  rbu_file *pWalFd;               /* Wal file descriptor for this main db */
  rbu_file *pMainNext;            /* Next MAIN_DB file */
};


/*************************************************************************
** The following three functions, found below:
**
**   rbuDeltaGetInt()
**   rbuDeltaChecksum()
**   rbuDeltaApply()
**
** are lifted from the fossil source code (http://fossil-scm.org). They
** are used to implement the scalar SQL function rbu_fossil_delta().
*/

/*
** Read bytes from *pz and convert them into a positive integer.  When
** finished, leave *pz pointing to the first character past the end of
** the integer.  The *pLen parameter holds the length of the string
** in *pz and is decremented once for each character in the integer.
*/
static unsigned int rbuDeltaGetInt(const char **pz, int *pLen){
  static const signed char zValue[] = {
    -1, -1, -1, -1, -1, -1, -1, -1,   -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,   -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1,   -1, -1, -1, -1, -1, -1, -1, -1,
     0,  1,  2,  3,  4,  5,  6,  7,    8,  9, -1, -1, -1, -1, -1, -1,
    -1, 10, 11, 12, 13, 14, 15, 16,   17, 18, 19, 20, 21, 22, 23, 24,
    25, 26, 27, 28, 29, 30, 31, 32,   33, 34, 35, -1, -1, -1, -1, 36,
    -1, 37, 38, 39, 40, 41, 42, 43,   44, 45, 46, 47, 48, 49, 50, 51,
    52, 53, 54, 55, 56, 57, 58, 59,   60, 61, 62, -1, -1, -1, 63, -1,
  };
  unsigned int v = 0;
  int c;
  unsigned char *z = (unsigned char*)*pz;
  unsigned char *zStart = z;
  while( (c = zValue[0x7f&*(z++)])>=0 ){
     v = (v<<6) + c;
  }
  z--;
  *pLen -= z - zStart;
  *pz = (char*)z;
  return v;
}

/*
** Compute a 32-bit checksum on the N-byte buffer.  Return the result.
*/
static unsigned int rbuDeltaChecksum(const char *zIn, size_t N){
  const unsigned char *z = (const unsigned char *)zIn;
  unsigned sum0 = 0;
  unsigned sum1 = 0;
  unsigned sum2 = 0;
  unsigned sum3 = 0;
  while(N >= 16){
    sum0 += ((unsigned)z[0] + z[4] + z[8] + z[12]);
    sum1 += ((unsigned)z[1] + z[5] + z[9] + z[13]);
    sum2 += ((unsigned)z[2] + z[6] + z[10]+ z[14]);
    sum3 += ((unsigned)z[3] + z[7] + z[11]+ z[15]);
    z += 16;
    N -= 16;
  }
  while(N >= 4){
    sum0 += z[0];
    sum1 += z[1];
    sum2 += z[2];
    sum3 += z[3];
    z += 4;
    N -= 4;
  }
  sum3 += (sum2 << 8) + (sum1 << 16) + (sum0 << 24);
  switch(N){
    case 3:   sum3 += (z[2] << 8);
    case 2:   sum3 += (z[1] << 16);
    case 1:   sum3 += (z[0] << 24);
    default:  ;
  }
  return sum3;
}

/*
** Apply a delta.
**
** The output buffer should be big enough to hold the whole output
** file and a NUL terminator at the end.  The delta_output_size()
** routine will determine this size for you.
**
** The delta string should be null-terminated.  But the delta string
** may contain embedded NUL characters (if the input and output are
** binary files) so we also have to pass in the length of the delta in
** the lenDelta parameter.
**
** This function returns the size of the output file in bytes (excluding
** the final NUL terminator character).  Except, if the delta string is
** malformed or intended for use with a source file other than zSrc,
** then this routine returns -1.
**
** Refer to the delta_create() documentation above for a description
** of the delta file format.
*/
static int rbuDeltaApply(
  const char *zSrc,      /* The source or pattern file */
  int lenSrc,            /* Length of the source file */
  const char *zDelta,    /* Delta to apply to the pattern */
  int lenDelta,          /* Length of the delta */
  char *zOut             /* Write the output into this preallocated buffer */
){
  unsigned int limit;
  unsigned int total = 0;
#ifndef FOSSIL_OMIT_DELTA_CKSUM_TEST
  char *zOrigOut = zOut;
#endif

  limit = rbuDeltaGetInt(&zDelta, &lenDelta);
  if( *zDelta!='\n' ){
    /* ERROR: size integer not terminated by "\n" */
    return -1;
  }
  zDelta++; lenDelta--;
  while( *zDelta && lenDelta>0 ){
    unsigned int cnt, ofst;
    cnt = rbuDeltaGetInt(&zDelta, &lenDelta);
    switch( zDelta[0] ){
      case '@': {
        zDelta++; lenDelta--;
        ofst = rbuDeltaGetInt(&zDelta, &lenDelta);
        if( lenDelta>0 && zDelta[0]!=',' ){
          /* ERROR: copy command not terminated by ',' */
          return -1;
        }
        zDelta++; lenDelta--;
        total += cnt;
        if( total>limit ){
          /* ERROR: copy exceeds output file size */
          return -1;
        }
        if( (int)(ofst+cnt) > lenSrc ){
          /* ERROR: copy extends past end of input */
          return -1;
        }
        memcpy(zOut, &zSrc[ofst], cnt);
        zOut += cnt;
        break;
      }
      case ':': {
        zDelta++; lenDelta--;
        total += cnt;
        if( total>limit ){
          /* ERROR:  insert command gives an output larger than predicted */
          return -1;
        }
        if( (int)cnt>lenDelta ){
          /* ERROR: insert count exceeds size of delta */
          return -1;
        }
        memcpy(zOut, zDelta, cnt);
        zOut += cnt;
        zDelta += cnt;
        lenDelta -= cnt;
        break;
      }
      case ';': {
        zDelta++; lenDelta--;
        zOut[0] = 0;
#ifndef FOSSIL_OMIT_DELTA_CKSUM_TEST
        if( cnt!=rbuDeltaChecksum(zOrigOut, total) ){
          /* ERROR:  bad checksum */
          return -1;
        }
#endif
        if( total!=limit ){
          /* ERROR: generated size does not match predicted size */
          return -1;
        }
        return total;
      }
      default: {
        /* ERROR: unknown delta operator */
        return -1;
      }
    }
  }
  /* ERROR: unterminated delta */
  return -1;
}

static int rbuDeltaOutputSize(const char *zDelta, int lenDelta){
  int size;
  size = rbuDeltaGetInt(&zDelta, &lenDelta);
  if( *zDelta!='\n' ){
    /* ERROR: size integer not terminated by "\n" */
    return -1;
  }
  return size;
}

/*
** End of code taken from fossil.
*************************************************************************/

/*
** Implementation of SQL scalar function rbu_fossil_delta().
**
** This function applies a fossil delta patch to a blob. Exactly two
** arguments must be passed to this function. The first is the blob to
** patch and the second the patch to apply. If no error occurs, this
** function returns the patched blob.
*/
static void rbuFossilDeltaFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  const char *aDelta;
  int nDelta;
  const char *aOrig;
  int nOrig;

  int nOut;
  int nOut2;
  char *aOut;

  assert( argc==2 );

  nOrig = sqlite3_value_bytes(argv[0]);
  aOrig = (const char*)sqlite3_value_blob(argv[0]);
  nDelta = sqlite3_value_bytes(argv[1]);
  aDelta = (const char*)sqlite3_value_blob(argv[1]);

  /* Figure out the size of the output */
  nOut = rbuDeltaOutputSize(aDelta, nDelta);
  if( nOut<0 ){
    sqlite3_result_error(context, "corrupt fossil delta", -1);
    return;
  }

  aOut = sqlite3_malloc(nOut+1);
  if( aOut==0 ){
    sqlite3_result_error_nomem(context);
  }else{
    nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
    if( nOut2!=nOut ){
      sqlite3_result_error(context, "corrupt fossil delta", -1);
    }else{
      sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
    }
  }
}


/*
** Prepare the SQL statement in buffer zSql against database handle db.
** If successful, set *ppStmt to point to the new statement and return
** SQLITE_OK. 
**
** Otherwise, if an error does occur, set *ppStmt to NULL and return
157824
157825
157826
157827
157828
157829
157830

157831

157832
157833
157834
157835
157836
157837
157838
158546
158547
158548
158549
158550
158551
158552
158553

158554
158555
158556
158557
158558
158559
158560
158561







+
-
+







        pIter->bCleanup = 0;
        rc = sqlite3_step(pIter->pTblIter);
        if( rc!=SQLITE_ROW ){
          rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
          pIter->zTbl = 0;
        }else{
          pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
          pIter->zDataTbl = (const char*)sqlite3_column_text(pIter->pTblIter,1);
          rc = pIter->zTbl ? SQLITE_OK : SQLITE_NOMEM;
          rc = (pIter->zDataTbl && pIter->zTbl) ? SQLITE_OK : SQLITE_NOMEM;
        }
      }else{
        if( pIter->zIdx==0 ){
          sqlite3_stmt *pIdx = pIter->pIdxIter;
          rc = sqlite3_bind_text(pIdx, 1, pIter->zTbl, -1, SQLITE_STATIC);
        }
        if( rc==SQLITE_OK ){
157855
157856
157857
157858
157859
157860
157861


































157862
157863
157864
157865
157866
157867
157868
157869
157870
157871
157872
157873
157874
157875
157876



157877
157878
157879
157880
157881
157882
157883
158578
158579
158580
158581
158582
158583
158584
158585
158586
158587
158588
158589
158590
158591
158592
158593
158594
158595
158596
158597
158598
158599
158600
158601
158602
158603
158604
158605
158606
158607
158608
158609
158610
158611
158612
158613
158614
158615
158616
158617
158618
158619
158620
158621
158622
158623
158624
158625
158626
158627
158628
158629
158630
158631


158632
158633
158634
158635
158636
158637
158638
158639
158640
158641







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













-
-
+
+
+







  if( rc!=SQLITE_OK ){
    rbuObjIterFinalize(pIter);
    p->rc = rc;
  }
  return rc;
}


/*
** The implementation of the rbu_target_name() SQL function. This function
** accepts one argument - the name of a table in the RBU database. If the
** table name matches the pattern:
**
**     data[0-9]_<name>
**
** where <name> is any sequence of 1 or more characters, <name> is returned.
** Otherwise, if the only argument does not match the above pattern, an SQL
** NULL is returned.
**
**     "data_t1"     -> "t1"
**     "data0123_t2" -> "t2"
**     "dataAB_t3"   -> NULL
*/
static void rbuTargetNameFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  const char *zIn;
  assert( argc==1 );

  zIn = (const char*)sqlite3_value_text(argv[0]);
  if( zIn && strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
    int i;
    for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
    if( zIn[i]=='_' && zIn[i+1] ){
      sqlite3_result_text(context, &zIn[i+1], -1, SQLITE_STATIC);
    }
  }
}

/*
** Initialize the iterator structure passed as the second argument.
**
** If no error occurs, SQLITE_OK is returned and the iterator is left 
** pointing to the first entry. Otherwise, an error code and message is 
** left in the RBU handle passed as the first argument. A copy of the 
** error code is returned.
*/
static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
  int rc;
  memset(pIter, 0, sizeof(RbuObjIter));

  rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg, 
      "SELECT substr(name, 6) FROM sqlite_master "
      "WHERE type IN ('table', 'view') AND name LIKE 'data_%'"
      "SELECT rbu_target_name(name) AS target, name FROM sqlite_master "
      "WHERE type IN ('table', 'view') AND target IS NOT NULL "
      "ORDER BY name"
  );

  if( rc==SQLITE_OK ){
    rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
        "SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
        "  FROM main.sqlite_master "
        "  WHERE type='index' AND tbl_name = ?"
158136
158137
158138
158139
158140
158141
158142
158143

158144
158145
158146
158147
158148
158149
158150
158894
158895
158896
158897
158898
158899
158900

158901
158902
158903
158904
158905
158906
158907
158908







-
+







        goto rbuTableType_end;
      }
    }
    *peType = RBU_PK_NONE;
  }

rbuTableType_end: {
    int i;
    unsigned int i;
    for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
      rbuFinalize(p, aStmt[i]);
    }
  }
}

/*
158215
158216
158217
158218
158219
158220
158221
158222

158223
158224
158225
158226
158227
158228
158229
158973
158974
158975
158976
158977
158978
158979

158980
158981
158982
158983
158984
158985
158986
158987







-
+







         || pIter->eType==RBU_PK_VTAB
    );

    /* Populate the azTblCol[] and nTblCol variables based on the columns
    ** of the input table. Ignore any input table columns that begin with
    ** "rbu_".  */
    p->rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg, 
        sqlite3_mprintf("SELECT * FROM 'data_%q'", pIter->zTbl)
        sqlite3_mprintf("SELECT * FROM '%q'", pIter->zDataTbl)
    );
    if( p->rc==SQLITE_OK ){
      nCol = sqlite3_column_count(pStmt);
      rbuAllocateIterArrays(p, pIter, nCol);
    }
    for(i=0; p->rc==SQLITE_OK && i<nCol; i++){
      const char *zName = (const char*)sqlite3_column_name(pStmt, i);
158240
158241
158242
158243
158244
158245
158246
158247

158248
158249
158250
158251
158252
158253
158254
158255
158256
158257
158258
158259
158260
158261
158262
158263
158264
158265
158266
158267
158268
158269


158270
158271
158272
158273
158274
158275
158276
158998
158999
159000
159001
159002
159003
159004

159005
159006
159007
159008
159009
159010
159011
159012
159013
159014
159015
159016
159017
159018
159019
159020
159021
159022
159023
159024
159025


159026
159027
159028
159029
159030
159031
159032
159033
159034







-
+




















-
-
+
+







    pStmt = 0;

    if( p->rc==SQLITE_OK
     && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
    ){
      p->rc = SQLITE_ERROR;
      p->zErrmsg = sqlite3_mprintf(
          "table data_%q %s rbu_rowid column", pIter->zTbl,
          "table %q %s rbu_rowid column", pIter->zDataTbl,
          (bRbuRowid ? "may not have" : "requires")
      );
    }

    /* Check that all non-HIDDEN columns in the destination table are also
    ** present in the input table. Populate the abTblPk[], azTblType[] and
    ** aiTblOrder[] arrays at the same time.  */
    if( p->rc==SQLITE_OK ){
      p->rc = prepareFreeAndCollectError(p->dbMain, &pStmt, &p->zErrmsg, 
          sqlite3_mprintf("PRAGMA table_info(%Q)", pIter->zTbl)
      );
    }
    while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
      const char *zName = (const char*)sqlite3_column_text(pStmt, 1);
      if( zName==0 ) break;  /* An OOM - finalize() below returns S_NOMEM */
      for(i=iOrder; i<pIter->nTblCol; i++){
        if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
      }
      if( i==pIter->nTblCol ){
        p->rc = SQLITE_ERROR;
        p->zErrmsg = sqlite3_mprintf("column missing from data_%q: %s",
            pIter->zTbl, zName
        p->zErrmsg = sqlite3_mprintf("column missing from %q: %s",
            pIter->zDataTbl, zName
        );
      }else{
        int iPk = sqlite3_column_int(pStmt, 5);
        int bNotNull = sqlite3_column_int(pStmt, 3);
        const char *zType = (const char*)sqlite3_column_text(pStmt, 2);

        if( i!=iOrder ){
158549
158550
158551
158552
158553
158554
158555
158556

158557
158558
158559
158560
158561
158562
158563
158564
158565
158566
158567
158568

158569
158570
158571
158572






158573
158574
158575
158576
158577
158578
158579
159307
159308
159309
159310
159311
159312
159313

159314
159315
159316
159317
159318
159319
159320
159321
159322
159323
159324
159325

159326
159327
159328
159329
159330
159331
159332
159333
159334
159335
159336
159337
159338
159339
159340
159341
159342
159343







-
+











-
+




+
+
+
+
+
+







  RbuObjIter *pIter,
  const char *zMask
){
  char *zList = 0;
  if( p->rc==SQLITE_OK ){
    int i;

    if( strlen(zMask)!=pIter->nTblCol ){
    if( (int)strlen(zMask)!=pIter->nTblCol ){
      rbuBadControlError(p);
    }else{
      const char *zSep = "";
      for(i=0; i<pIter->nTblCol; i++){
        char c = zMask[pIter->aiSrcOrder[i]];
        if( c=='x' ){
          zList = rbuMPrintf(p, "%z%s\"%w\"=?%d", 
              zList, zSep, pIter->azTblCol[i], i+1
          );
          zSep = ", ";
        }
        if( c=='d' ){
        else if( c=='d' ){
          zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_delta(\"%w\", ?%d)", 
              zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
          );
          zSep = ", ";
        }
        else if( c=='f' ){
          zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_fossil_delta(\"%w\", ?%d)", 
              zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
          );
          zSep = ", ";
        }
      }
    }
  }
  return zList;
}

158817
158818
158819
158820
158821
158822
158823
158824

158825
158826
158827
158828
158829
158830
158831
159581
159582
159583
159584
159585
159586
159587

159588
159589
159590
159591
159592
159593
159594
159595







-
+







  int bRbuRowid = (pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE);
  char *zBind = rbuObjIterGetBindlist(p, pIter->nTblCol + 1 + bRbuRowid);
  if( zBind ){
    assert( pIter->pTmpInsert==0 );
    p->rc = prepareFreeAndCollectError(
        p->dbRbu, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
          "INSERT INTO %s.'rbu_tmp_%q'(rbu_control,%s%s) VALUES(%z)", 
          p->zStateDb, pIter->zTbl, zCollist, zRbuRowid, zBind
          p->zStateDb, pIter->zDataTbl, zCollist, zRbuRowid, zBind
    ));
  }
}

static void rbuTmpInsertFunc(
  sqlite3_context *pCtx, 
  int nVal,
158913
158914
158915
158916
158917
158918
158919
158920

158921
158922
158923
158924
158925

158926
158927
158928
158929
158930
158931


158932
158933
158934
158935
158936
158937
158938
159677
159678
159679
159680
159681
159682
159683

159684
159685
159686
159687
159688

159689
159690
159691
159692
159693


159694
159695
159696
159697
159698
159699
159700
159701
159702







-
+




-
+




-
-
+
+








      /* Create the SELECT statement to read keys in sorted order */
      if( p->rc==SQLITE_OK ){
        char *zSql;
        if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
          zSql = sqlite3_mprintf(
              "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
              zCollist, p->zStateDb, pIter->zTbl,
              zCollist, p->zStateDb, pIter->zDataTbl,
              zCollist, zLimit
          );
        }else{
          zSql = sqlite3_mprintf(
              "SELECT %s, rbu_control FROM 'data_%q' "
              "SELECT %s, rbu_control FROM '%q' "
              "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
              "UNION ALL "
              "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
              "ORDER BY %s%s",
              zCollist, pIter->zTbl, 
              zCollist, p->zStateDb, pIter->zTbl, 
              zCollist, pIter->zDataTbl, 
              zCollist, p->zStateDb, pIter->zDataTbl, 
              zCollist, zLimit
          );
        }
        p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
      }

      sqlite3_free(zImposterCols);
158948
158949
158950
158951
158952
158953
158954
158955
158956
158957
158958
158959
158960
158961
158962
158963
158964
158965
158966
158967
158968
158969
158970
158971
159712
159713
159714
159715
159716
159717
159718










159719
159720
159721
159722
159723
159724
159725







-
-
-
-
-
-
-
-
-
-







      char *zWhere = rbuObjIterGetWhere(p, pIter);
      char *zOldlist = rbuObjIterGetOldlist(p, pIter, "old");
      char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new");

      zCollist = rbuObjIterGetCollist(p, pIter);
      pIter->nCol = pIter->nTblCol;

      /* Create the SELECT statement to read keys from data_xxx */
      if( p->rc==SQLITE_OK ){
        p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
            sqlite3_mprintf(
              "SELECT %s, rbu_control%s FROM 'data_%q'%s", 
              zCollist, (bRbuRowid ? ", rbu_rowid" : ""), zTbl, zLimit
            )
        );
      }

      /* Create the imposter table or tables (if required). */
      rbuCreateImposterTable(p, pIter);
      rbuCreateImposterTable2(p, pIter);
      zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_");

      /* Create the INSERT statement to write to the target PK b-tree */
      if( p->rc==SQLITE_OK ){
158991
158992
158993
158994
158995
158996
158997
158998
158999
159000
159001




159002
159003
159004
159005
159006
159007
159008
159745
159746
159747
159748
159749
159750
159751




159752
159753
159754
159755
159756
159757
159758
159759
159760
159761
159762







-
-
-
-
+
+
+
+







        if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
          zRbuRowid = ", rbu_rowid";
        }

        /* Create the rbu_tmp_xxx table and the triggers to populate it. */
        rbuMPrintfExec(p, p->dbRbu,
            "CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS "
            "SELECT *%s FROM 'data_%q' WHERE 0;"
            , p->zStateDb
            , zTbl, (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
            , zTbl
            "SELECT *%s FROM '%q' WHERE 0;"
            , p->zStateDb, pIter->zDataTbl
            , (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
            , pIter->zDataTbl
        );

        rbuMPrintfExec(p, p->dbMain,
            "CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" "
            "BEGIN "
            "  SELECT rbu_tmp_insert(2, %s);"
            "END;"
159029
159030
159031
159032
159033
159034
159035











159036
159037
159038
159039
159040
159041
159042
159783
159784
159785
159786
159787
159788
159789
159790
159791
159792
159793
159794
159795
159796
159797
159798
159799
159800
159801
159802
159803
159804
159805
159806
159807







+
+
+
+
+
+
+
+
+
+
+







              "END;",
              zWrite, zTbl, zNewlist
          );
        }

        rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
      }

      /* Create the SELECT statement to read keys from data_xxx */
      if( p->rc==SQLITE_OK ){
        p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
            sqlite3_mprintf(
              "SELECT %s, rbu_control%s FROM '%q'%s", 
              zCollist, (bRbuRowid ? ", rbu_rowid" : ""), 
              pIter->zDataTbl, zLimit
            )
        );
      }

      sqlite3_free(zWhere);
      sqlite3_free(zOldlist);
      sqlite3_free(zNewlist);
      sqlite3_free(zBindings);
    }
    sqlite3_free(zCollist);
159159
159160
159161
159162
159163
159164
159165












159166
159167
159168
159169
159170
159171
159172
159924
159925
159926
159927
159928
159929
159930
159931
159932
159933
159934
159935
159936
159937
159938
159939
159940
159941
159942
159943
159944
159945
159946
159947
159948
159949







+
+
+
+
+
+
+
+
+
+
+
+







  }

  if( p->rc==SQLITE_OK ){
    p->rc = sqlite3_create_function(p->dbMain, 
        "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
    );
  }

  if( p->rc==SQLITE_OK ){
    p->rc = sqlite3_create_function(p->dbMain, 
        "rbu_fossil_delta", 2, SQLITE_UTF8, 0, rbuFossilDeltaFunc, 0, 0
    );
  }

  if( p->rc==SQLITE_OK ){
    p->rc = sqlite3_create_function(p->dbRbu, 
        "rbu_target_name", 1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
    );
  }

  if( p->rc==SQLITE_OK ){
    p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
  }
  rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");

  /* Mark the database file just opened as an RBU target database. If 
159589
159590
159591
159592
159593
159594
159595
159596

159597
159598
159599
159600
159601
159602
159603
160366
160367
160368
160369
160370
160371
160372

160373
160374
160375
160376
160377
160378
160379
160380







-
+







      sqlite3_stmt *pUpdate = 0;
      assert( eType==RBU_UPDATE );
      rbuGetUpdateStmt(p, pIter, zMask, &pUpdate);
      if( pUpdate ){
        for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
          char c = zMask[pIter->aiSrcOrder[i]];
          pVal = sqlite3_column_value(pIter->pSelect, i);
          if( pIter->abTblPk[i] || c=='x' || c=='d' ){
          if( pIter->abTblPk[i] || c!='.' ){
            p->rc = sqlite3_bind_value(pUpdate, i+1, pVal);
          }
        }
        if( p->rc==SQLITE_OK 
         && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) 
        ){
          /* Bind the rbu_rowid value to column _rowid_ */
159701
159702
159703
159704
159705
159706
159707
159708

159709
159710
159711
159712
159713
159714
159715
160478
160479
160480
160481
160482
160483
160484

160485
160486
160487
160488
160489
160490
160491
160492







-
+








          if( pIter->bCleanup ){
            /* Clean up the rbu_tmp_xxx table for the previous table. It 
            ** cannot be dropped as there are currently active SQL statements.
            ** But the contents can be deleted.  */
            if( pIter->abIndexed ){
              rbuMPrintfExec(p, p->dbRbu, 
                  "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zTbl
                  "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
              );
            }
          }else{
            rbuObjIterPrepareAll(p, pIter, 0);

            /* Advance to the next row to process. */
            if( p->rc==SQLITE_OK ){
159924
159925
159926
159927
159928
159929
159930
159931
159932
159933
159934







159935
159936
159937
159938
159939
159940
159941
160701
160702
160703
160704
160705
160706
160707




160708
160709
160710
160711
160712
160713
160714
160715
160716
160717
160718
160719
160720
160721







-
-
-
-
+
+
+
+
+
+
+








/*
** If there is a "*-oal" file in the file-system corresponding to the
** target database in the file-system, delete it. If an error occurs,
** leave an error code and error message in the rbu handle.
*/
static void rbuDeleteOalFile(sqlite3rbu *p){
  char *zOal = sqlite3_mprintf("%s-oal", p->zTarget);
  assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
  unlink(zOal);
  sqlite3_free(zOal);
  char *zOal = rbuMPrintf(p, "%s-oal", p->zTarget);
  if( zOal ){
    sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
    assert( pVfs && p->rc==SQLITE_OK && p->zErrmsg==0 );
    pVfs->xDelete(pVfs, zOal, 0);
    sqlite3_free(zOal);
  }
}

/*
** Allocate a private rbu VFS for the rbu handle passed as the only
** argument. This VFS will be used unless the call to sqlite3rbu_open()
** specified a URI with a vfs=? option in place of a target database
** file name.
160040
160041
160042
160043
160044
160045
160046

160047
160048
160049
160050

160051
160052
160053
160054











160055
160056
160057
160058
160059
160060
160061
160820
160821
160822
160823
160824
160825
160826
160827
160828
160829
160830

160831
160832
160833
160834

160835
160836
160837
160838
160839
160840
160841
160842
160843
160844
160845
160846
160847
160848
160849
160850
160851
160852







+



-
+



-
+
+
+
+
+
+
+
+
+
+
+







      ** page 1 of the database file. */
      p->rc = SQLITE_BUSY;
      p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
    }

    if( p->rc==SQLITE_OK ){
      if( p->eStage==RBU_STAGE_OAL ){
        sqlite3 *db = p->dbMain;

        /* Open transactions both databases. The *-oal file is opened or
        ** created at this point. */
        p->rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
        p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
        if( p->rc==SQLITE_OK ){
          p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
        }
  

        /* Check if the main database is a zipvfs db. If it is, set the upper
        ** level pager to use "journal_mode=off". This prevents it from 
        ** generating a large journal using a temp file.  */
        if( p->rc==SQLITE_OK ){
          int frc = sqlite3_file_control(db, "main", SQLITE_FCNTL_ZIPVFS, 0);
          if( frc==SQLITE_OK ){
            p->rc = sqlite3_exec(db, "PRAGMA journal_mode=off",0,0,&p->zErrmsg);
          }
        }

        /* Point the object iterator at the first object */
        if( p->rc==SQLITE_OK ){
          p->rc = rbuObjIterFirst(p, &p->objiter);
        }

        /* If the RBU database contains no data_xxx tables, declare the RBU
        ** update finished.  */
160160
160161
160162
160163
160164
160165
160166


























160167
160168
160169
160170
160171
160172
160173
160951
160952
160953
160954
160955
160956
160957
160958
160959
160960
160961
160962
160963
160964
160965
160966
160967
160968
160969
160970
160971
160972
160973
160974
160975
160976
160977
160978
160979
160980
160981
160982
160983
160984
160985
160986
160987
160988
160989
160990







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







** Return the total number of key-value operations (inserts, deletes or 
** updates) that have been performed on the target database since the
** current RBU update was started.
*/
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu){
  return pRbu->nProgress;
}

SQLITE_API int SQLITE_STDCALL sqlite3rbu_savestate(sqlite3rbu *p){
  int rc = p->rc;
  
  if( rc==SQLITE_DONE ) return SQLITE_OK;

  assert( p->eStage>=RBU_STAGE_OAL && p->eStage<=RBU_STAGE_DONE );
  if( p->eStage==RBU_STAGE_OAL ){
    assert( rc!=SQLITE_DONE );
    if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0);
  }

  p->rc = rc;
  rbuSaveState(p, p->eStage);
  rc = p->rc;

  if( p->eStage==RBU_STAGE_OAL ){
    assert( rc!=SQLITE_DONE );
    if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
    if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, 0);
    if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0,0);
  }

  p->rc = rc;
  return rc;
}

/**************************************************************************
** Beginning of RBU VFS shim methods. The VFS shim modifies the behaviour
** of a standard VFS in the following ways:
**
** 1. Whenever the first page of a main database file is read or 
**    written, the value of the change-counter cookie is stored in
160640
160641
160642
160643
160644
160645
160646
160647


160648
160649
160650
160651
160652
160653
160654
161457
161458
161459
161460
161461
161462
161463

161464
161465
161466
161467
161468
161469
161470
161471
161472







-
+
+







    rbuVfsCheckReservedLock,      /* xCheckReservedLock */
    rbuVfsFileControl,            /* xFileControl */
    rbuVfsSectorSize,             /* xSectorSize */
    rbuVfsDeviceCharacteristics,  /* xDeviceCharacteristics */
    rbuVfsShmMap,                 /* xShmMap */
    rbuVfsShmLock,                /* xShmLock */
    rbuVfsShmBarrier,             /* xShmBarrier */
    rbuVfsShmUnmap                /* xShmUnmap */
    rbuVfsShmUnmap,               /* xShmUnmap */
    0, 0                          /* xFetch, xUnfetch */
  };
  rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
  sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
  rbu_file *pFd = (rbu_file *)pFile;
  int rc = SQLITE_OK;
  const char *zOpen = zName;

160982
160983
160984
160985
160986
160987
160988



160989
160990
160991
160992
160993
160994
160995
161800
161801
161802
161803
161804
161805
161806
161807
161808
161809
161810
161811
161812
161813
161814
161815
161816







+
+
+







**
** This file contains an implementation of the "dbstat" virtual table.
**
** The dbstat virtual table is used to extract low-level formatting
** information from an SQLite database in order to implement the
** "sqlite3_analyzer" utility.  See the ../tool/spaceanal.tcl script
** for an example implementation.
**
** Additional information is available on the "dbstat.html" page of the
** official SQLite documentation.
*/

/* #include "sqliteInt.h"   ** Requires access to internal data structures ** */
#if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
    && !defined(SQLITE_OMIT_VIRTUALTABLE)

/*
161030
161031
161032
161033
161034
161035
161036
161037


161038
161039
161040
161041
161042
161043
161044
161851
161852
161853
161854
161855
161856
161857

161858
161859
161860
161861
161862
161863
161864
161865
161866







-
+
+







  "  pageno     INTEGER,          /* Page number */"                        \
  "  pagetype   STRING,           /* 'internal', 'leaf' or 'overflow' */"   \
  "  ncell      INTEGER,          /* Cells on page (0 for overflow) */"     \
  "  payload    INTEGER,          /* Bytes of payload on this page */"      \
  "  unused     INTEGER,          /* Bytes of unused space on this page */" \
  "  mx_payload INTEGER,          /* Largest payload size of all cells */"  \
  "  pgoffset   INTEGER,          /* Offset of page in file */"             \
  "  pgsize     INTEGER           /* Size of the page */"                   \
  "  pgsize     INTEGER,          /* Size of the page */"                   \
  "  schema     TEXT HIDDEN       /* Database schema being analyzed */"     \
  ");"


typedef struct StatTable StatTable;
typedef struct StatCursor StatCursor;
typedef struct StatPage StatPage;
typedef struct StatCell StatCell;
161068
161069
161070
161071
161072
161073
161074

161075
161076
161077
161078
161079
161080
161081
161890
161891
161892
161893
161894
161895
161896
161897
161898
161899
161900
161901
161902
161903
161904







+







  int nMxPayload;                 /* Largest payload of any cell on this page */
};

struct StatCursor {
  sqlite3_vtab_cursor base;
  sqlite3_stmt *pStmt;            /* Iterates through set of root pages */
  int isEof;                      /* After pStmt has returned SQLITE_DONE */
  int iDb;                        /* Schema used for this query */

  StatPage aPage[32];
  int iPage;                      /* Current entry in aPage[] */

  /* Values to return. */
  char *zName;                    /* Value of 'name' column */
  char *zPath;                    /* Value of 'path' column */
161145
161146
161147
161148
161149
161150
161151
161152




161153
161154




















161155
161156
161157
161158
161159
161160
161161
161162
161163
161164
161165
161166
161167
161168
161169
161170
161171
161172
161173
161174
161175
161176
161177
161178
161179
161180
161181
161182
161183
161184
161185
161186
161187
161188

161189
161190
161191
161192
161193

161194
161195
161196
161197
161198
161199
161200
161201
161202
161203
161204
161205
161206
161207
161208
161209
161210
161211
161212
161213

161214
161215
161216
161217
161218
161219
161220
161968
161969
161970
161971
161972
161973
161974

161975
161976
161977
161978
161979
161980
161981
161982
161983
161984
161985
161986
161987
161988
161989
161990
161991
161992
161993
161994
161995
161996
161997
161998
161999
162000
162001
162002
162003
162004
162005
162006
162007
162008
162009
162010
162011
162012
162013
162014
162015
162016
162017
162018
162019

162020
162021
162022
162023
162024
162025
162026
162027
162028

162029
162030
162031

162032
162033

162034
162035

162036
















162037
162038
162039

162040
162041
162042
162043
162044
162045
162046
162047







-
+
+
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



















-









-



-
+

-


-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+







static int statDisconnect(sqlite3_vtab *pVtab){
  sqlite3_free(pVtab);
  return SQLITE_OK;
}

/*
** There is no "best-index". This virtual table always does a linear
** scan of the binary VFS log file.
** scan.  However, a schema=? constraint should cause this table to
** operate on a different database schema, so check for it.
**
** idxNum is normally 0, but will be 1 if a schema=? constraint exists.
*/
static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
  int i;

  pIdxInfo->estimatedCost = 1.0e6;  /* Initial cost estimate */

  /* Look for a valid schema=? constraint.  If found, change the idxNum to
  ** 1 and request the value of that constraint be sent to xFilter.  And
  ** lower the cost estimate to encourage the constrained version to be
  ** used.
  */
  for(i=0; i<pIdxInfo->nConstraint; i++){
    if( pIdxInfo->aConstraint[i].usable==0 ) continue;
    if( pIdxInfo->aConstraint[i].op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
    if( pIdxInfo->aConstraint[i].iColumn!=10 ) continue;
    pIdxInfo->idxNum = 1;
    pIdxInfo->estimatedCost = 1.0;
    pIdxInfo->aConstraintUsage[i].argvIndex = 1;
    pIdxInfo->aConstraintUsage[i].omit = 1;
    break;
  }


  /* Records are always returned in ascending order of (name, path). 
  ** If this will satisfy the client, set the orderByConsumed flag so that 
  ** SQLite does not do an external sort.
  */
  if( ( pIdxInfo->nOrderBy==1
     && pIdxInfo->aOrderBy[0].iColumn==0
     && pIdxInfo->aOrderBy[0].desc==0
     ) ||
      ( pIdxInfo->nOrderBy==2
     && pIdxInfo->aOrderBy[0].iColumn==0
     && pIdxInfo->aOrderBy[0].desc==0
     && pIdxInfo->aOrderBy[1].iColumn==1
     && pIdxInfo->aOrderBy[1].desc==0
     )
  ){
    pIdxInfo->orderByConsumed = 1;
  }

  pIdxInfo->estimatedCost = 10.0;
  return SQLITE_OK;
}

/*
** Open a new statvfs cursor.
*/
static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
  StatTable *pTab = (StatTable *)pVTab;
  StatCursor *pCsr;
  int rc;

  pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
  if( pCsr==0 ){
    rc = SQLITE_NOMEM;
    return SQLITE_NOMEM;
  }else{
    char *zSql;
    memset(pCsr, 0, sizeof(StatCursor));
    pCsr->base.pVtab = pVTab;

    pCsr->iDb = pTab->iDb;
    zSql = sqlite3_mprintf(
        "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
        "  UNION ALL  "
        "SELECT name, rootpage, type"
        "  FROM \"%w\".sqlite_master WHERE rootpage!=0"
        "  ORDER BY name", pTab->db->aDb[pTab->iDb].zName);
    if( zSql==0 ){
      rc = SQLITE_NOMEM;
    }else{
      rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
      sqlite3_free(zSql);
    }
    if( rc!=SQLITE_OK ){
      sqlite3_free(pCsr);
      pCsr = 0;
    }
  }

  *ppCursor = (sqlite3_vtab_cursor *)pCsr;
  return rc;
  return SQLITE_OK;
}

static void statClearPage(StatPage *p){
  int i;
  if( p->aCell ){
    for(i=0; i<p->nCell; i++){
      sqlite3_free(p->aCell[i].aOvfl);
161231
161232
161233
161234
161235
161236
161237

161238
161239
161240
161241
161242
161243
161244
162058
162059
162060
162061
162062
162063
162064
162065
162066
162067
162068
162069
162070
162071
162072







+







  sqlite3_reset(pCsr->pStmt);
  for(i=0; i<ArraySize(pCsr->aPage); i++){
    statClearPage(&pCsr->aPage[i]);
  }
  pCsr->iPage = 0;
  sqlite3_free(pCsr->zPath);
  pCsr->zPath = 0;
  pCsr->isEof = 0;
}

/*
** Close a statvfs cursor.
*/
static int statClose(sqlite3_vtab_cursor *pCursor){
  StatCursor *pCsr = (StatCursor *)pCursor;
161393
161394
161395
161396
161397
161398
161399
161400

161401
161402
161403
161404
161405
161406
161407
162221
162222
162223
162224
162225
162226
162227

162228
162229
162230
162231
162232
162233
162234
162235







-
+







*/
static int statNext(sqlite3_vtab_cursor *pCursor){
  int rc;
  int nPayload;
  char *z;
  StatCursor *pCsr = (StatCursor *)pCursor;
  StatTable *pTab = (StatTable *)pCursor->pVtab;
  Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
  Btree *pBt = pTab->db->aDb[pCsr->iDb].pBt;
  Pager *pPager = sqlite3BtreePager(pBt);

  sqlite3_free(pCsr->zPath);
  pCsr->zPath = 0;

statNextRestart:
  if( pCsr->aPage[0].pPg==0 ){
161531
161532
161533
161534
161535
161536
161537




161538











161539

















161540



161541
161542
161543
161544
161545
161546
161547
162359
162360
162361
162362
162363
162364
162365
162366
162367
162368
162369
162370
162371
162372
162373
162374
162375
162376
162377
162378
162379
162380
162381
162382
162383
162384
162385
162386
162387
162388
162389
162390
162391
162392
162393
162394
162395
162396
162397
162398
162399

162400
162401
162402
162403
162404
162405
162406
162407
162408
162409







+
+
+
+

+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+








static int statFilter(
  sqlite3_vtab_cursor *pCursor, 
  int idxNum, const char *idxStr,
  int argc, sqlite3_value **argv
){
  StatCursor *pCsr = (StatCursor *)pCursor;
  StatTable *pTab = (StatTable*)(pCursor->pVtab);
  char *zSql;
  int rc = SQLITE_OK;
  char *zMaster;

  if( idxNum==1 ){
    const char *zDbase = (const char*)sqlite3_value_text(argv[0]);
    pCsr->iDb = sqlite3FindDbName(pTab->db, zDbase);
    if( pCsr->iDb<0 ){
      sqlite3_free(pCursor->pVtab->zErrMsg);
      pCursor->pVtab->zErrMsg = sqlite3_mprintf("no such schema: %s", zDbase);
      return pCursor->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM;
    }
  }else{
    pCsr->iDb = pTab->iDb;
  }
  statResetCsr(pCsr);
  sqlite3_finalize(pCsr->pStmt);
  pCsr->pStmt = 0;
  zMaster = pCsr->iDb==1 ? "sqlite_temp_master" : "sqlite_master";
  zSql = sqlite3_mprintf(
      "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
      "  UNION ALL  "
      "SELECT name, rootpage, type"
      "  FROM \"%w\".%s WHERE rootpage!=0"
      "  ORDER BY name", pTab->db->aDb[pCsr->iDb].zName, zMaster);
  if( zSql==0 ){
    return SQLITE_NOMEM;
  }else{
    rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
    sqlite3_free(zSql);
  }

  if( rc==SQLITE_OK ){
  return statNext(pCursor);
    rc = statNext(pCursor);
  }
  return rc;
}

static int statColumn(
  sqlite3_vtab_cursor *pCursor, 
  sqlite3_context *ctx, 
  int i
){
161570
161571
161572
161573
161574
161575
161576
161577

161578
161579
161580






161581
161582
161583
161584
161585
161586
161587
162432
162433
162434
162435
162436
162437
162438

162439

162440
162441
162442
162443
162444
162445
162446
162447
162448
162449
162450
162451
162452
162453
162454







-
+
-


+
+
+
+
+
+







      break;
    case 7:            /* mx_payload */
      sqlite3_result_int(ctx, pCsr->nMxPayload);
      break;
    case 8:            /* pgoffset */
      sqlite3_result_int64(ctx, pCsr->iOffset);
      break;
    default:           /* pgsize */
    case 9:            /* pgsize */
      assert( i==9 );
      sqlite3_result_int(ctx, pCsr->szPage);
      break;
    default: {          /* schema */
      sqlite3 *db = sqlite3_context_db_handle(ctx);
      int iDb = pCsr->iDb;
      sqlite3_result_text(ctx, db->aDb[iDb].zName, -1, SQLITE_STATIC);
      break;
    }
  }
  return SQLITE_OK;
}

static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
  StatCursor *pCsr = (StatCursor *)pCursor;
  *pRowid = pCsr->iPageno;
Changes to SQLite.Interop/src/core/sqlite3.h.
107
108
109
110
111
112
113
114
115
116



117
118
119
120
121
122
123
107
108
109
110
111
112
113



114
115
116
117
118
119
120
121
122
123







-
-
-
+
+
+







** string contains the date and time of the check-in (UTC) and an SHA1
** hash of the entire source tree.
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION        "3.8.11.1"
#define SQLITE_VERSION_NUMBER 3008011
#define SQLITE_SOURCE_ID      "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
#define SQLITE_VERSION        "3.8.12"
#define SQLITE_VERSION_NUMBER 3008012
#define SQLITE_SOURCE_ID      "2015-09-09 19:44:33 8d2ed150a7a15626965cf994ef48c3ab61eca6ec"

/*
** CAPI3REF: Run-Time Library Version Numbers
** KEYWORDS: sqlite3_version, sqlite3_sourceid
**
** These interfaces provide the same information as the [SQLITE_VERSION],
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
473
474
475
476
477
478
479

480
481
482
483
484
485
486
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487







+







#define SQLITE_IOERR_SHMLOCK           (SQLITE_IOERR | (20<<8))
#define SQLITE_IOERR_SHMMAP            (SQLITE_IOERR | (21<<8))
#define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
#define SQLITE_IOERR_DELETE_NOENT      (SQLITE_IOERR | (23<<8))
#define SQLITE_IOERR_MMAP              (SQLITE_IOERR | (24<<8))
#define SQLITE_IOERR_GETTEMPPATH       (SQLITE_IOERR | (25<<8))
#define SQLITE_IOERR_CONVPATH          (SQLITE_IOERR | (26<<8))
#define SQLITE_IOERR_VNODE             (SQLITE_IOERR | (27<<8))
#define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
#define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
#define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
#define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
#define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
#define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
#define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
3369
3370
3371
3372
3373
3374
3375
3376


3377
3378
3379
3380
3381
3382
3383
3370
3371
3372
3373
3374
3375
3376

3377
3378
3379
3380
3381
3382
3383
3384
3385







-
+
+








/*
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
** METHOD: sqlite3_stmt
**
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
** [prepared statement] S has been stepped at least once using 
** [sqlite3_step(S)] but has not run to completion and/or has not 
** [sqlite3_step(S)] but has neither run to completion (returned
** [SQLITE_DONE] from [sqlite3_step(S)]) nor
** been reset using [sqlite3_reset(S)].  ^The sqlite3_stmt_busy(S)
** interface returns false if S is a NULL pointer.  If S is not a 
** NULL pointer and is not a pointer to a valid [prepared statement]
** object, then the behavior is undefined and probably undesirable.
**
** This interface can be used in combination [sqlite3_next_stmt()]
** to locate all prepared statements associated with a database 
Changes to SQLite.Interop/src/core/sqlite3ext.h.
408
409
410
411
412
413
414

415
416
417
418
419
420
421
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422







+







#define sqlite3_value_numeric_type     sqlite3_api->value_numeric_type
#define sqlite3_value_text             sqlite3_api->value_text
#define sqlite3_value_text16           sqlite3_api->value_text16
#define sqlite3_value_text16be         sqlite3_api->value_text16be
#define sqlite3_value_text16le         sqlite3_api->value_text16le
#define sqlite3_value_type             sqlite3_api->value_type
#define sqlite3_vmprintf               sqlite3_api->vmprintf
#define sqlite3_vsnprintf              sqlite3_api->vsnprintf
#define sqlite3_overload_function      sqlite3_api->overload_function
#define sqlite3_prepare_v2             sqlite3_api->prepare_v2
#define sqlite3_prepare16_v2           sqlite3_api->prepare16_v2
#define sqlite3_clear_bindings         sqlite3_api->clear_bindings
#define sqlite3_bind_zeroblob          sqlite3_api->bind_zeroblob
#define sqlite3_blob_bytes             sqlite3_api->blob_bytes
#define sqlite3_blob_close             sqlite3_api->blob_close
Changes to SQLite.Interop/src/ext/fts5.c.
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
225
226
227
228
229
230
231

232
233
234
235
236
237
238
239







-
+







  int (*xColumnCount)(Fts5Context*);
  int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow);
  int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken);

  int (*xTokenize)(Fts5Context*, 
    const char *pText, int nText, /* Text to tokenize */
    void *pCtx,                   /* Context passed to xToken() */
    int (*xToken)(void*, const char*, int, int, int)       /* Callback */
    int (*xToken)(void*, int, const char*, int, int, int)       /* Callback */
  );

  int (*xPhraseCount)(Fts5Context*);
  int (*xPhraseSize)(Fts5Context*, int iPhrase);

  int (*xInstCount)(Fts5Context*, int *pnInst);
  int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff);
286
287
288
289
290
291
292
293
294
295



296
























297
298
299
300
301
302




303




304
305
306
307
308
309
310
311
312
313
314
315










































































































316
317
318
319
320
321
322
323

324
325
326

327
328
329
330
331
332
333
334










335
336
337
338
339
340
341
342
343
344

345
346
347
348
349
350
351
286
287
288
289
290
291
292



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322




323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
497







-
-
-
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
+
+
+
+

+
+
+
+












+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








+



+








+
+
+
+
+
+
+
+
+
+









-
+







** xDelete:
**   This function is invoked to delete a tokenizer handle previously
**   allocated using xCreate(). Fts5 guarantees that this function will
**   be invoked exactly once for each successful call to xCreate().
**
** xTokenize:
**   This function is expected to tokenize the nText byte string indicated 
**   by argument pText. pText may not be nul-terminated. The first argument
**   passed to this function is a pointer to an Fts5Tokenizer object returned 
**   by an earlier call to xCreate().
**   by argument pText. pText may or may not be nul-terminated. The first
**   argument passed to this function is a pointer to an Fts5Tokenizer object
**   returned by an earlier call to xCreate().
**
**   The second argument indicates the reason that FTS5 is requesting
**   tokenization of the supplied text. This is always one of the following
**   four values:
**
**   <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into
**            or removed from the FTS table. The tokenizer is being invoked to
**            determine the set of tokens to add to (or delete from) the
**            FTS index.
**
**       <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed 
**            against the FTS index. The tokenizer is being called to tokenize 
**            a bareword or quoted string specified as part of the query.
**
**       <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as
**            FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is
**            followed by a "*" character, indicating that the last token
**            returned by the tokenizer will be treated as a token prefix.
**
**       <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to 
**            satisfy an fts5_api.xTokenize() request made by an auxiliary
**            function. Or an fts5_api.xColumnSize() request made by the same
**            on a columnsize=0 database.  
**   </ul>
**
**   For each token in the input string, the supplied callback xToken() must
**   be invoked. The first argument to it should be a copy of the pointer
**   passed as the second argument to xTokenize(). The next two arguments
**   are a pointer to a buffer containing the token text, and the size of
**   the token in bytes. The 4th and 5th arguments are the byte offsets of
**   the first byte of and first byte immediately following the text from 
**   passed as the second argument to xTokenize(). The third and fourth
**   arguments are a pointer to a buffer containing the token text, and the
**   size of the token in bytes. The 4th and 5th arguments are the byte offsets
**   of the first byte of and first byte immediately following the text from
**   which the token is derived within the input.
**
**   The second argument passed to the xToken() callback ("tflags") should
**   normally be set to 0. The exception is if the tokenizer supports 
**   synonyms. In this case see the discussion below for details.
**
**   FTS5 assumes the xToken() callback is invoked for each token in the 
**   order that they occur within the input text.
**
**   If an xToken() callback returns any value other than SQLITE_OK, then
**   the tokenization should be abandoned and the xTokenize() method should
**   immediately return a copy of the xToken() return value. Or, if the
**   input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally,
**   if an error occurs with the xTokenize() implementation itself, it
**   may abandon the tokenization and return any error code other than
**   SQLITE_OK or SQLITE_DONE.
**
** SYNONYM SUPPORT
**
**   Custom tokenizers may also support synonyms. Consider a case in which a
**   user wishes to query for a phrase such as "first place". Using the 
**   built-in tokenizers, the FTS5 query 'first + place' will match instances
**   of "first place" within the document set, but not alternative forms
**   such as "1st place". In some applications, it would be better to match
**   all instances of "first place" or "1st place" regardless of which form
**   the user specified in the MATCH query text.
**
**   There are several ways to approach this in FTS5:
**
**   <ol><li> By mapping all synonyms to a single token. In this case, the 
**            In the above example, this means that the tokenizer returns the
**            same token for inputs "first" and "1st". Say that token is in
**            fact "first", so that when the user inserts the document "I won
**            1st place" entries are added to the index for tokens "i", "won",
**            "first" and "place". If the user then queries for '1st + place',
**            the tokenizer substitutes "first" for "1st" and the query works
**            as expected.
**
**       <li> By adding multiple synonyms for a single term to the FTS index.
**            In this case, when tokenizing query text, the tokenizer may 
**            provide multiple synonyms for a single term within the document.
**            FTS5 then queries the index for each synonym individually. For
**            example, faced with the query:
**
**   <codeblock>
**     ... MATCH 'first place'</codeblock>
**
**            the tokenizer offers both "1st" and "first" as synonyms for the
**            first token in the MATCH query and FTS5 effectively runs a query 
**            similar to:
**
**   <codeblock>
**     ... MATCH '(first OR 1st) place'</codeblock>
**
**            except that, for the purposes of auxiliary functions, the query
**            still appears to contain just two phrases - "(first OR 1st)" 
**            being treated as a single phrase.
**
**       <li> By adding multiple synonyms for a single term to the FTS index.
**            Using this method, when tokenizing document text, the tokenizer
**            provides multiple synonyms for each token. So that when a 
**            document such as "I won first place" is tokenized, entries are
**            added to the FTS index for "i", "won", "first", "1st" and
**            "place".
**
**            This way, even if the tokenizer does not provide synonyms
**            when tokenizing query text (it should not - to do would be
**            inefficient), it doesn't matter if the user queries for 
**            'first + place' or '1st + place', as there are entires in the
**            FTS index corresponding to both forms of the first token.
**   </ol>
**
**   Whether is is parsing document or query text, any call to xToken that
**   specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit
**   is considered to supply a synonym for the previous token. For example,
**   when parsing the document "I won first place", a tokenizer that supports
**   synonyms would call xToken() 5 times, as follows:
**
**   <codeblock>
**       xToken(pCtx, 0, "i",                      1,  0,  1);
**       xToken(pCtx, 0, "won",                    3,  2,  5);
**       xToken(pCtx, 0, "first",                  5,  6, 11);
**       xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3,  6, 11);
**       xToken(pCtx, 0, "place",                  5, 12, 17);
**</codeblock>
**
**   It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time
**   xToken() is called. Multiple synonyms may be specified for a single token
**   by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence. 
**   There is no limit to the number of synonyms that may be provided for a
**   single token.
**
**   In many cases, method (1) above is the best approach. It does not add 
**   extra data to the FTS index or require FTS5 to query for multiple terms,
**   so it is efficient in terms of disk space and query speed. However, it
**   does not support prefix queries very well. If, as suggested above, the
**   token "first" is subsituted for "1st" by the tokenizer, then the query:
**
**   <codeblock>
**     ... MATCH '1s*'</codeblock>
**
**   will not match documents that contain the token "1st" (as the tokenizer
**   will probably not map "1s" to any prefix of "first").
**
**   For full prefix support, method (3) may be preferred. In this case, 
**   because the index contains entries for both "first" and "1st", prefix
**   queries such as 'fi*' or '1s*' will match correctly. However, because
**   extra entries are added to the FTS index, this method uses more space
**   within the database.
**
**   Method (2) offers a midpoint between (1) and (3). Using this method,
**   a query such as '1s*' will match documents that contain the literal 
**   token "1st", but not "first" (assuming the tokenizer is not able to
**   provide synonyms for prefixes). However, a non-prefix query like '1st'
**   will match against "1st" and "first". This method does not require
**   extra disk space, as no extra entries are added to the FTS index. 
**   On the other hand, it may require more CPU cycles to run MATCH queries,
**   as separate queries of the FTS index are required for each synonym.
**
**   When using methods (2) or (3), it is important that the tokenizer only
**   provide synonyms when tokenizing document text (method (2)) or query
**   text (method (3)), not both. Doing so will not cause any errors, but is
**   inefficient.
*/
typedef struct Fts5Tokenizer Fts5Tokenizer;
typedef struct fts5_tokenizer fts5_tokenizer;
struct fts5_tokenizer {
  int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
  void (*xDelete)(Fts5Tokenizer*);
  int (*xTokenize)(Fts5Tokenizer*, 
      void *pCtx,
      int flags,            /* Mask of FTS5_TOKENIZE_* flags */
      const char *pText, int nText, 
      int (*xToken)(
        void *pCtx,         /* Copy of 2nd argument to xTokenize() */
        int tflags,         /* Mask of FTS5_TOKEN_* flags */
        const char *pToken, /* Pointer to buffer containing token */
        int nToken,         /* Size of token in bytes */
        int iStart,         /* Byte offset of token within input text */
        int iEnd            /* Byte offset of end of token within input text */
      )
  );
};

/* Flags that may be passed as the third argument to xTokenize() */
#define FTS5_TOKENIZE_QUERY     0x0001
#define FTS5_TOKENIZE_PREFIX    0x0002
#define FTS5_TOKENIZE_DOCUMENT  0x0004
#define FTS5_TOKENIZE_AUX       0x0008

/* Flags that may be passed by the tokenizer implementation back to FTS5
** as the third argument to the supplied xToken callback. */
#define FTS5_TOKEN_COLOCATED    0x0001      /* Same position as prev. token */

/*
** END OF CUSTOM TOKENIZERS
*************************************************************************/

/*************************************************************************
** FTS5 EXTENSION REGISTRATION API
*/
typedef struct fts5_api fts5_api;
struct fts5_api {
  int iVersion;                   /* Currently always set to 1 */
  int iVersion;                   /* Currently always set to 2 */

  /* Create a new tokenizer */
  int (*xCreateTokenizer)(
    fts5_api *pApi,
    const char *zName,
    void *pContext,
    fts5_tokenizer *pTokenizer,
541
542
543
544
545
546
547

548
549
550

551
552
553
554
555
556
557
687
688
689
690
691
692
693
694
695
696

697
698
699
700
701
702
703
704







+


-
+







);
static void sqlite3Fts5ConfigFree(Fts5Config*);

static int sqlite3Fts5ConfigDeclareVtab(Fts5Config *pConfig);

static int sqlite3Fts5Tokenize(
  Fts5Config *pConfig,            /* FTS5 Configuration object */
  int flags,                      /* FTS5_TOKENIZE_* flags */
  const char *pText, int nText,   /* Text to tokenize */
  void *pCtx,                     /* Context passed to xToken() */
  int (*xToken)(void*, const char*, int, int, int)    /* Callback */
  int (*xToken)(void*, int, const char*, int, int, int)    /* Callback */
);

static void sqlite3Fts5Dequote(char *z);

/* Load the contents of the %_config table */
static int sqlite3Fts5ConfigLoad(Fts5Config*, int);

609
610
611
612
613
614
615


616
617

618
619
620
621
622
623
624
756
757
758
759
760
761
762
763
764
765

766
767
768
769
770
771
772
773







+
+

-
+







struct Fts5PoslistReader {
  /* Variables used only by sqlite3Fts5PoslistIterXXX() functions. */
  int iCol;                       /* If (iCol>=0), this column only */
  const u8 *a;                    /* Position list to iterate through */
  int n;                          /* Size of buffer at a[] in bytes */
  int i;                          /* Current offset in a[] */

  u8 bFlag;                       /* For client use (any custom purpose) */

  /* Output variables */
  int bEof;                       /* Set to true at EOF */
  u8 bEof;                        /* Set to true at EOF */
  i64 iPos;                       /* (iCol<<32) + iPos */
};
static int sqlite3Fts5PoslistReaderInit(
  int iCol,                       /* If (iCol>=0), this column only */
  const u8 *a, int n,             /* Poslist buffer to iterate through */
  Fts5PoslistReader *pIter        /* Iterator object to initialize */
);
756
757
758
759
760
761
762
763

764
765

766
767
768
769
770
771
772
905
906
907
908
909
910
911

912
913

914
915
916
917
918
919
920
921







-
+

-
+







/*
** Retrieve and clear the current error code, respectively.
*/
static int sqlite3Fts5IndexErrcode(Fts5Index*);
static void sqlite3Fts5IndexReset(Fts5Index*);

/*
** Get or set the "averages" record.
** Get or set the "averages" values.
*/
static int sqlite3Fts5IndexGetAverages(Fts5Index *p, Fts5Buffer *pBuf);
static int sqlite3Fts5IndexGetAverages(Fts5Index *p, i64 *pnRow, i64 *anSize);
static int sqlite3Fts5IndexSetAverages(Fts5Index *p, const u8*, int);

/*
** Functions called by the storage module as part of integrity-check.
*/
static u64 sqlite3Fts5IndexCksum(Fts5Config*,i64,int,int,const char*,int);
static int sqlite3Fts5IndexIntegrityCheck(Fts5Index*, u64 cksum);
971
972
973
974
975
976
977
978

979
980
981
982
983
984
985
1120
1121
1122
1123
1124
1125
1126

1127
1128
1129
1130
1131
1132
1133
1134







-
+







/* Called during startup to register a UDF with SQLite */
static int sqlite3Fts5ExprInit(Fts5Global*, sqlite3*);

static int sqlite3Fts5ExprPhraseCount(Fts5Expr*);
static int sqlite3Fts5ExprPhraseSize(Fts5Expr*, int iPhrase);
static int sqlite3Fts5ExprPoslist(Fts5Expr*, int, const u8 **);

static int sqlite3Fts5ExprPhraseExpr(Fts5Config*, Fts5Expr*, int, Fts5Expr**);
static int sqlite3Fts5ExprClonePhrase(Fts5Config*, Fts5Expr*, int, Fts5Expr**);

/*******************************************
** The fts5_expr.c API above this point is used by the other hand-written
** C code in this module. The interfaces below this point are called by
** the parser code in fts5parse.y.  */

static void sqlite3Fts5ParseError(Fts5Parse *pParse, const char *zFmt, ...);
1239
1240
1241
1242
1243
1244
1245

1246
1247
1248
1249
1250
1251
1252



1253

1254
1255
1256
1257
1258
1259
1260
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405

1406
1407
1408
1409
1410
1411
1412
1413







+







+
+
+
-
+







}

/*
** Tokenizer callback used by implementation of highlight() function.
*/
static int fts5HighlightCb(
  void *pContext,                 /* Pointer to HighlightContext object */
  int tflags,                     /* Mask of FTS5_TOKEN_* flags */
  const char *pToken,             /* Buffer containing token */
  int nToken,                     /* Size of token in bytes */
  int iStartOff,                  /* Start offset of token */
  int iEndOff                     /* End offset of token */
){
  HighlightContext *p = (HighlightContext*)pContext;
  int rc = SQLITE_OK;
  int iPos;

  if( tflags & FTS5_TOKEN_COLOCATED ) return SQLITE_OK;
  int iPos = p->iPos++;
  iPos = p->iPos++;

  if( p->iRangeEnd>0 ){
    if( iPos<p->iRangeStart || iPos>p->iRangeEnd ) return SQLITE_OK;
    if( p->iRangeStart && iPos==p->iRangeStart ) p->iOff = iStartOff;
  }

  if( iPos==p->iter.iStart ){
2600
2601
2602
2603
2604
2605
2606

2607
2608
2609

2610
2611
2612



2613
2614
2615
2616
2617
2618
2619
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762

2763
2764
2765

2766
2767
2768
2769
2770
2771
2772
2773
2774
2775







+


-
+


-
+
+
+







** the callback returned SQLITE_DONE, this is not an error and this function
** still returns SQLITE_OK. Or, if the tokenization was abandoned early
** because the callback returned another non-zero value, it is assumed
** to be an SQLite error code and returned to the caller.
*/
static int sqlite3Fts5Tokenize(
  Fts5Config *pConfig,            /* FTS5 Configuration object */
  int flags,                      /* FTS5_TOKENIZE_* flags */
  const char *pText, int nText,   /* Text to tokenize */
  void *pCtx,                     /* Context passed to xToken() */
  int (*xToken)(void*, const char*, int, int, int)    /* Callback */
  int (*xToken)(void*, int, const char*, int, int, int)    /* Callback */
){
  if( pText==0 ) return SQLITE_OK;
  return pConfig->pTokApi->xTokenize(pConfig->pTok, pCtx, pText, nText, xToken);
  return pConfig->pTokApi->xTokenize(
      pConfig->pTok, pCtx, flags, pText, nText, xToken
  );
}

/*
** Argument pIn points to the first character in what is expected to be
** a comma-separated list of SQL literals followed by a ')' character.
** If it actually is this, return a pointer to the ')'. Otherwise, return
** NULL to indicate a parse error.
2839
2840
2841
2842
2843
2844
2845


2846
2847
2848
2849
2850
2851
2852
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010







+
+









/*
** All token types in the generated fts5parse.h file are greater than 0.
*/
#define FTS5_EOF 0

#define FTS5_LARGEST_INT64  (0xffffffff|(((i64)0x7fffffff)<<32))

typedef struct Fts5ExprTerm Fts5ExprTerm;

/*
** Functions generated by lemon from fts5parse.y.
*/
static void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(u64));
static void sqlite3Fts5ParserFree(void*, void (*freeProc)(void*));
2890
2891
2892
2893
2894
2895
2896

2897
2898
2899
2900
2901
2902
2903
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062







+







** An instance of the following structure represents a single search term
** or term prefix.
*/
struct Fts5ExprTerm {
  int bPrefix;                    /* True for a prefix term */
  char *zTerm;                    /* nul-terminated term */
  Fts5IndexIter *pIter;           /* Iterator for this term */
  Fts5ExprTerm *pSynonym;         /* Pointer to first in list of synonyms */
};

/*
** A phrase. One or more terms that must appear in a contiguous sequence
** within a document for it to match.
*/
struct Fts5ExprPhrase {
2998
2999
3000
3001
3002
3003
3004




3005
3006
3007
3008
3009
3010
3011
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174







+
+
+
+







      }
      pToken->n = (z2 - z);
      break;
    }

    default: {
      const char *z2;
      if( sqlite3Fts5IsBareword(z[0])==0 ){
        sqlite3Fts5ParseError(pParse, "fts5: syntax error near \"%.1s\"", z);
        return FTS5_EOF;
      }
      tok = FTS5_STRING;
      for(z2=&z[1]; sqlite3Fts5IsBareword(*z2); z2++);
      pToken->n = (z2 - z);
      if( pToken->n==2 && memcmp(pToken->p, "OR", 2)==0 )  tok = FTS5_OR;
      if( pToken->n==3 && memcmp(pToken->p, "NOT", 3)==0 ) tok = FTS5_NOT;
      if( pToken->n==3 && memcmp(pToken->p, "AND", 3)==0 ) tok = FTS5_AND;
      break;
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3224
3225
3226
3227
3228
3229
3230









































































3231
3232
3233
3234
3235
3236
3237







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







  }

  sqlite3_free(sParse.apPhrase);
  *pzErr = sParse.zErr;
  return sParse.rc;
}

/*
** Create a new FTS5 expression by cloning phrase iPhrase of the
** expression passed as the second argument.
*/
static int sqlite3Fts5ExprPhraseExpr(
  Fts5Config *pConfig,
  Fts5Expr *pExpr, 
  int iPhrase, 
  Fts5Expr **ppNew
){
  int rc = SQLITE_OK;             /* Return code */
  Fts5ExprPhrase *pOrig;          /* The phrase extracted from pExpr */
  Fts5ExprPhrase *pCopy;          /* Copy of pOrig */
  Fts5Expr *pNew = 0;             /* Expression to return via *ppNew */

  pOrig = pExpr->apExprPhrase[iPhrase];
  pCopy = (Fts5ExprPhrase*)sqlite3Fts5MallocZero(&rc, 
      sizeof(Fts5ExprPhrase) + sizeof(Fts5ExprTerm) * pOrig->nTerm
  );
  if( pCopy ){
    int i;                          /* Used to iterate through phrase terms */
    Fts5ExprPhrase **apPhrase;
    Fts5ExprNode *pNode;
    Fts5ExprNearset *pNear;

    pNew = (Fts5Expr*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5Expr));
    apPhrase = (Fts5ExprPhrase**)sqlite3Fts5MallocZero(&rc, 
        sizeof(Fts5ExprPhrase*)
    );
    pNode = (Fts5ExprNode*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5ExprNode));
    pNear = (Fts5ExprNearset*)sqlite3Fts5MallocZero(&rc, 
        sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*)
    );

    for(i=0; i<pOrig->nTerm; i++){
      pCopy->aTerm[i].zTerm = sqlite3Fts5Strndup(&rc, pOrig->aTerm[i].zTerm,-1);
      pCopy->aTerm[i].bPrefix = pOrig->aTerm[i].bPrefix;
    }

    if( rc==SQLITE_OK ){
      /* All the allocations succeeded. Put the expression object together. */
      pNew->pIndex = pExpr->pIndex;
      pNew->pRoot = pNode;
      pNew->nPhrase = 1;
      pNew->apExprPhrase = apPhrase;
      pNew->apExprPhrase[0] = pCopy;

      pNode->eType = (pOrig->nTerm==1 ? FTS5_TERM : FTS5_STRING);
      pNode->pNear = pNear;

      pNear->nPhrase = 1;
      pNear->apPhrase[0] = pCopy;

      pCopy->nTerm = pOrig->nTerm;
      pCopy->pNode = pNode;
    }else{
      /* At least one allocation failed. Free them all. */
      for(i=0; i<pOrig->nTerm; i++){
        sqlite3_free(pCopy->aTerm[i].zTerm);
      }
      sqlite3_free(pCopy);
      sqlite3_free(pNear);
      sqlite3_free(pNode);
      sqlite3_free(apPhrase);
      sqlite3_free(pNew);
      pNew = 0;
    }
  }

  *ppNew = pNew;
  return rc;
}

/*
** Free the expression node object passed as the only argument.
*/
static void sqlite3Fts5ParseNodeFree(Fts5ExprNode *p){
  if( p ){
    int i;
    for(i=0; i<p->nChild; i++){
3166
3167
3168
3169
3170
3171
3172













































































































3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186

3187
3188
3189
3190
3191
3192
3193
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384

3385
3386
3387
3388
3389
3390
3391
3392







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













-
+







static int fts5ExprColsetTest(Fts5ExprColset *pColset, int iCol){
  int i;
  for(i=0; i<pColset->nCol; i++){
    if( pColset->aiCol[i]==iCol ) return 1;
  }
  return 0;
}

/*
** Argument pTerm must be a synonym iterator. Return the current rowid
** that it points to.
*/
static i64 fts5ExprSynonymRowid(Fts5ExprTerm *pTerm, int bDesc, int *pbEof){
  i64 iRet = 0;
  int bRetValid = 0;
  Fts5ExprTerm *p;

  assert( pTerm->pSynonym );
  assert( bDesc==0 || bDesc==1 );
  for(p=pTerm; p; p=p->pSynonym){
    if( 0==sqlite3Fts5IterEof(p->pIter) ){
      i64 iRowid = sqlite3Fts5IterRowid(p->pIter);
      if( bRetValid==0 || (bDesc!=(iRowid<iRet)) ){
        iRet = iRowid;
        bRetValid = 1;
      }
    }
  }

  if( pbEof && bRetValid==0 ) *pbEof = 1;
  return iRet;
}

/*
** Argument pTerm must be a synonym iterator.
*/
static int fts5ExprSynonymPoslist(
  Fts5ExprTerm *pTerm, 
  i64 iRowid,
  int *pbDel,                     /* OUT: Caller should sqlite3_free(*pa) */
  u8 **pa, int *pn
){
  Fts5PoslistWriter writer = {0};
  Fts5PoslistReader aStatic[4];
  Fts5PoslistReader *aIter = aStatic;
  int nIter = 0;
  int nAlloc = 4;
  int rc = SQLITE_OK;
  Fts5ExprTerm *p;

  assert( pTerm->pSynonym );
  for(p=pTerm; p; p=p->pSynonym){
    Fts5IndexIter *pIter = p->pIter;
    if( sqlite3Fts5IterEof(pIter)==0 && sqlite3Fts5IterRowid(pIter)==iRowid ){
      const u8 *a;
      int n;
      i64 dummy;
      rc = sqlite3Fts5IterPoslist(pIter, &a, &n, &dummy);
      if( rc!=SQLITE_OK ) goto synonym_poslist_out;
      if( nIter==nAlloc ){
        int nByte = sizeof(Fts5PoslistReader) * nAlloc * 2;
        Fts5PoslistReader *aNew = (Fts5PoslistReader*)sqlite3_malloc(nByte);
        if( aNew==0 ){
          rc = SQLITE_NOMEM;
          goto synonym_poslist_out;
        }
        memcpy(aNew, aIter, sizeof(Fts5PoslistReader) * nIter);
        nAlloc = nAlloc*2;
        if( aIter!=aStatic ) sqlite3_free(aIter);
        aIter = aNew;
      }
      sqlite3Fts5PoslistReaderInit(-1, a, n, &aIter[nIter]);
      assert( aIter[nIter].bEof==0 );
      nIter++;
    }
  }

  assert( *pbDel==0 );
  if( nIter==1 ){
    *pa = (u8*)aIter[0].a;
    *pn = aIter[0].n;
  }else{
    Fts5PoslistWriter writer = {0};
    Fts5Buffer buf = {0,0,0};
    i64 iPrev = -1;
    while( 1 ){
      int i;
      i64 iMin = FTS5_LARGEST_INT64;
      for(i=0; i<nIter; i++){
        if( aIter[i].bEof==0 ){
          if( aIter[i].iPos==iPrev ){
            if( sqlite3Fts5PoslistReaderNext(&aIter[i]) ) continue;
          }
          if( aIter[i].iPos<iMin ){
            iMin = aIter[i].iPos;
          }
        }
      }
      if( iMin==FTS5_LARGEST_INT64 || rc!=SQLITE_OK ) break;
      rc = sqlite3Fts5PoslistWriterAppend(&buf, &writer, iMin);
      iPrev = iMin;
    }
    if( rc ){
      sqlite3_free(buf.p);
    }else{
      *pa = buf.p;
      *pn = buf.n;
      *pbDel = 1;
    }
  }

 synonym_poslist_out:
  if( aIter!=aStatic ) sqlite3_free(aIter);
  return rc;
}


/*
** All individual term iterators in pPhrase are guaranteed to be valid and
** pointing to the same rowid when this function is called. This function 
** checks if the current rowid really is a match, and if so populates
** the pPhrase->poslist buffer accordingly. Output parameter *pbMatch
** is set to true if this is really a match, or false otherwise.
**
** SQLITE_OK is returned if an error occurs, or an SQLite error code 
** otherwise. It is not considered an error code if the current rowid is 
** not a match.
*/
static int fts5ExprPhraseIsMatch(
  Fts5Expr *pExpr,                /* Expression pPhrase belongs to */
  Fts5ExprNode *pNode,            /* Node pPhrase belongs to */
  Fts5ExprColset *pColset,        /* Restrict matches to these columns */
  Fts5ExprPhrase *pPhrase,        /* Phrase object to initialize */
  int *pbMatch                    /* OUT: Set to true if really a match */
){
  Fts5PoslistWriter writer = {0};
  Fts5PoslistReader aStatic[4];
  Fts5PoslistReader *aIter = aStatic;
3205
3206
3207
3208
3209
3210
3211

3212
3213
3214

3215
3216
3217
3218
3219
3220












3221
3222
3223
3224
3225
3226
3227
3228
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416





3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428

3429
3430
3431
3432
3433
3434
3435







+



+

-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-







  /* If the aStatic[] array is not large enough, allocate a large array
  ** using sqlite3_malloc(). This approach could be improved upon. */
  if( pPhrase->nTerm>(sizeof(aStatic) / sizeof(aStatic[0])) ){
    int nByte = sizeof(Fts5PoslistReader) * pPhrase->nTerm;
    aIter = (Fts5PoslistReader*)sqlite3_malloc(nByte);
    if( !aIter ) return SQLITE_NOMEM;
  }
  memset(aIter, 0, sizeof(Fts5PoslistReader) * pPhrase->nTerm);

  /* Initialize a term iterator for each term in the phrase */
  for(i=0; i<pPhrase->nTerm; i++){
    Fts5ExprTerm *pTerm = &pPhrase->aTerm[i];
    i64 dummy;
    int n;
    const u8 *a;
    rc = sqlite3Fts5IterPoslist(pPhrase->aTerm[i].pIter, &a, &n, &dummy);
    if( rc || sqlite3Fts5PoslistReaderInit(iCol, a, n, &aIter[i]) ){
      goto ismatch_out;
    int n = 0;
    int bFlag = 0;
    const u8 *a = 0;
    if( pTerm->pSynonym ){
      rc = fts5ExprSynonymPoslist(pTerm, pNode->iRowid, &bFlag, (u8**)&a, &n);
    }else{
      rc = sqlite3Fts5IterPoslist(pTerm->pIter, &a, &n, &dummy);
    }
    if( rc!=SQLITE_OK ) goto ismatch_out;
    sqlite3Fts5PoslistReaderInit(iCol, a, n, &aIter[i]);
    aIter[i].bFlag = bFlag;
    if( aIter[i].bEof ) goto ismatch_out;
    }
  }

  while( 1 ){
    int bMatch;
    i64 iPos = aIter[0].iPos;
    do {
      bMatch = 1;
3248
3249
3250
3251
3252
3253
3254



3255
3256
3257
3258
3259
3260
3261
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471







+
+
+







    for(i=0; i<pPhrase->nTerm; i++){
      if( sqlite3Fts5PoslistReaderNext(&aIter[i]) ) goto ismatch_out;
    }
  }

 ismatch_out:
  *pbMatch = (pPhrase->poslist.n>0);
  for(i=0; i<pPhrase->nTerm; i++){
    if( aIter[i].bFlag ) sqlite3_free((u8*)aIter[i].a);
  }
  if( aIter!=aStatic ) sqlite3_free(aIter);
  return rc;
}

typedef struct Fts5LookaheadReader Fts5LookaheadReader;
struct Fts5LookaheadReader {
  const u8 *a;                    /* Buffer containing position list */
3415
3416
3417
3418
3419
3420
3421
3422
3423


3424




































3425
3426
3427
3428
3429
3430






3431
3432



3433
3434
3435
3436
3437
3438
3439
3625
3626
3627
3628
3629
3630
3631


3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670






3671
3672
3673
3674
3675
3676
3677

3678
3679
3680
3681
3682
3683
3684
3685
3686
3687







-
-
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+

-
+
+
+







*/
static int fts5ExprNearAdvanceFirst(
  Fts5Expr *pExpr,                /* Expression pPhrase belongs to */
  Fts5ExprNode *pNode,            /* FTS5_STRING or FTS5_TERM node */
  int bFromValid,
  i64 iFrom 
){
  Fts5IndexIter *pIter = pNode->pNear->apPhrase[0]->aTerm[0].pIter;
  int rc;
  Fts5ExprTerm *pTerm = &pNode->pNear->apPhrase[0]->aTerm[0];
  int rc = SQLITE_OK;

  if( pTerm->pSynonym ){
    int bEof = 1;
    Fts5ExprTerm *p;

    /* Find the firstest rowid any synonym points to. */
    i64 iRowid = fts5ExprSynonymRowid(pTerm, pExpr->bDesc, 0);

    /* Advance each iterator that currently points to iRowid. Or, if iFrom
    ** is valid - each iterator that points to a rowid before iFrom.  */
    for(p=pTerm; p; p=p->pSynonym){
      if( sqlite3Fts5IterEof(p->pIter)==0 ){
        i64 ii = sqlite3Fts5IterRowid(p->pIter);
        if( ii==iRowid 
         || (bFromValid && ii!=iFrom && (ii>iFrom)==pExpr->bDesc) 
        ){
          if( bFromValid ){
            rc = sqlite3Fts5IterNextFrom(p->pIter, iFrom);
          }else{
            rc = sqlite3Fts5IterNext(p->pIter);
          }
          if( rc!=SQLITE_OK ) break;
          if( sqlite3Fts5IterEof(p->pIter)==0 ){
            bEof = 0;
          }
        }else{
          bEof = 0;
        }
      }
    }

    /* Set the EOF flag if either all synonym iterators are at EOF or an
    ** error has occurred.  */
    pNode->bEof = (rc || bEof);
  }else{
    Fts5IndexIter *pIter = pTerm->pIter;

  assert( Fts5NodeIsString(pNode) );
  if( bFromValid ){
    rc = sqlite3Fts5IterNextFrom(pIter, iFrom);
  }else{
    rc = sqlite3Fts5IterNext(pIter);
  }
    assert( Fts5NodeIsString(pNode) );
    if( bFromValid ){
      rc = sqlite3Fts5IterNextFrom(pIter, iFrom);
    }else{
      rc = sqlite3Fts5IterNext(pIter);
    }

  pNode->bEof = (rc || sqlite3Fts5IterEof(pIter));
    pNode->bEof = (rc || sqlite3Fts5IterEof(pIter));
  }

  return rc;
}

/*
** Advance iterator pIter until it points to a value equal to or laster
** than the initial value of *piLast. If this means the iterator points
** to a value laster than *piLast, update *piLast to the new lastest value.
3463
3464
3465
3466
3467
3468
3469





























3470
3471
3472
3473
3474
3475
3476
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    iRowid = sqlite3Fts5IterRowid(pIter);
    assert( (bDesc==0 && iRowid>=iLast) || (bDesc==1 && iRowid<=iLast) );
  }
  *piLast = iRowid;

  return 0;
}

static int fts5ExprSynonymAdvanceto(
  Fts5ExprTerm *pTerm,            /* Term iterator to advance */
  int bDesc,                      /* True if iterator is "rowid DESC" */
  i64 *piLast,                    /* IN/OUT: Lastest rowid seen so far */
  int *pRc                        /* OUT: Error code */
){
  int rc = SQLITE_OK;
  i64 iLast = *piLast;
  Fts5ExprTerm *p;
  int bEof = 0;

  for(p=pTerm; rc==SQLITE_OK && p; p=p->pSynonym){
    if( sqlite3Fts5IterEof(p->pIter)==0 ){
      i64 iRowid = sqlite3Fts5IterRowid(p->pIter);
      if( (bDesc==0 && iLast>iRowid) || (bDesc && iLast<iRowid) ){
        rc = sqlite3Fts5IterNextFrom(p->pIter, iLast);
      }
    }
  }

  if( rc!=SQLITE_OK ){
    *pRc = rc;
    bEof = 1;
  }else{
    *piLast = fts5ExprSynonymRowid(pTerm, bDesc, &bEof);
  }
  return bEof;
}

/*
** IN/OUT parameter (*pa) points to a position list n bytes in size. If
** the position list contains entries for column iCol, then (*pa) is set
** to point to the sub-position-list for that column and the number of
** bytes in it returned. Or, if the argument position list does not
** contain any entries for column iCol, return 0.
3534
3535
3536
3537
3538
3539
3540
3541

3542
3543

3544
3545
3546
3547
3548
3549
3550
3811
3812
3813
3814
3815
3816
3817

3818
3819

3820
3821
3822
3823
3824
3825
3826
3827







-
+

-
+







  int i;

  /* Check that each phrase in the nearset matches the current row.
  ** Populate the pPhrase->poslist buffers at the same time. If any
  ** phrase is not a match, break out of the loop early.  */
  for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){
    Fts5ExprPhrase *pPhrase = pNear->apPhrase[i];
    if( pPhrase->nTerm>1 || pNear->pColset ){
    if( pPhrase->nTerm>1 || pPhrase->aTerm[0].pSynonym || pNear->pColset ){
      int bMatch = 0;
      rc = fts5ExprPhraseIsMatch(pExpr, pNear->pColset, pPhrase, &bMatch);
      rc = fts5ExprPhraseIsMatch(pNode, pNear->pColset, pPhrase, &bMatch);
      if( bMatch==0 ) break;
    }else{
      rc = sqlite3Fts5IterPoslistBuffer(
          pPhrase->aTerm[0].pIter, &pPhrase->poslist
      );
    }
  }
3572
3573
3574
3575
3576
3577
3578

3579
3580
3581
3582
3583
3584
3585
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863







+







  Fts5ExprColset *pColset = pNear->pColset;
  const u8 *pPos;
  int nPos;
  int rc;

  assert( pNode->eType==FTS5_TERM );
  assert( pNear->nPhrase==1 && pPhrase->nTerm==1 );
  assert( pPhrase->aTerm[0].pSynonym==0 );

  rc = sqlite3Fts5IterPoslist(pIter, &pPos, &nPos, &pNode->iRowid);

  /* If the term may match any column, then this must be a match. 
  ** Return immediately in this case. Otherwise, try to find the
  ** part of the poslist that corresponds to the required column.
  ** If it can be found, return. If it cannot, the next iteration
3618
3619
3620
3621
3622
3623
3624

3625

3626




3627
3628
3629
3630
3631



3632


3633
3634
3635
3636
3637
3638











3639
3640
3641
3642
3643







3644
3645
3646
3647
3648
3649
3650

3651
3652
3653
3654
3655
3656
3657
3658


3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671

3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685






















3686
3687

3688
3689
3690
3691
3692
3693
3694
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905

3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917

3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936





3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948

3949
3950
3951
3952
3953
3954
3955
3956


3957
3958
3959
3960
3961
3962
3963
3964


3965
3966
3967
3968

3969
3970













3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993

3994
3995
3996
3997
3998
3999
4000
4001







+

+
-
+
+
+
+





+
+
+
-
+
+






+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+





-

+






-
-
+
+






-
-




-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+







){
  Fts5ExprNearset *pNear = pNode->pNear;
  Fts5ExprPhrase *pLeft = pNear->apPhrase[0];
  int rc = SQLITE_OK;
  i64 iLast;                      /* Lastest rowid any iterator points to */
  int i, j;                       /* Phrase and token index, respectively */
  int bMatch;                     /* True if all terms are at the same rowid */
  const int bDesc = pExpr->bDesc;

  /* Check that this node should not be FTS5_TERM */
  assert( pNear->nPhrase>1 || pNear->apPhrase[0]->nTerm>1 );
  assert( pNear->nPhrase>1 
       || pNear->apPhrase[0]->nTerm>1 
       || pNear->apPhrase[0]->aTerm[0].pSynonym
  );

  /* Initialize iLast, the "lastest" rowid any iterator points to. If the
  ** iterator skips through rowids in the default ascending order, this means
  ** the maximum rowid. Or, if the iterator is "ORDER BY rowid DESC", then it
  ** means the minimum rowid.  */
  if( pLeft->aTerm[0].pSynonym ){
    iLast = fts5ExprSynonymRowid(&pLeft->aTerm[0], bDesc, 0);
  }else{
  iLast = sqlite3Fts5IterRowid(pLeft->aTerm[0].pIter);
    iLast = sqlite3Fts5IterRowid(pLeft->aTerm[0].pIter);
  }

  do {
    bMatch = 1;
    for(i=0; i<pNear->nPhrase; i++){
      Fts5ExprPhrase *pPhrase = pNear->apPhrase[i];
      for(j=0; j<pPhrase->nTerm; j++){
        Fts5ExprTerm *pTerm = &pPhrase->aTerm[j];
        if( pTerm->pSynonym ){
          int bEof = 1;
          i64 iRowid = fts5ExprSynonymRowid(pTerm, bDesc, 0);
          if( iRowid==iLast ) continue;
          bMatch = 0;
          if( fts5ExprSynonymAdvanceto(pTerm, bDesc, &iLast, &rc) ){
            pNode->bEof = 1;
            return rc;
          }
        }else{
        Fts5IndexIter *pIter = pPhrase->aTerm[j].pIter;
        i64 iRowid = sqlite3Fts5IterRowid(pIter);
        if( iRowid!=iLast ) bMatch = 0;
        if( fts5ExprAdvanceto(pIter, pExpr->bDesc, &iLast,&rc,&pNode->bEof) ){
          return rc;
          Fts5IndexIter *pIter = pPhrase->aTerm[j].pIter;
          i64 iRowid = sqlite3Fts5IterRowid(pIter);
          if( iRowid==iLast ) continue;
          bMatch = 0;
          if( fts5ExprAdvanceto(pIter, bDesc, &iLast, &rc, &pNode->bEof) ){
            return rc;
          }
        }
      }
    }
  }while( bMatch==0 );

  pNode->bNomatch = (0==fts5ExprNearTest(&rc, pExpr, pNode));
  pNode->iRowid = iLast;
  pNode->bNomatch = (0==fts5ExprNearTest(&rc, pExpr, pNode));

  return rc;
}

/*
** Initialize all term iterators in the pNear object. If any term is found
** to match no documents at all, set *pbEof to true and return immediately,
** without initializing any further iterators.
** to match no documents at all, return immediately without initializing any
** further iterators.
*/
static int fts5ExprNearInitAll(
  Fts5Expr *pExpr,
  Fts5ExprNode *pNode
){
  Fts5ExprNearset *pNear = pNode->pNear;
  Fts5ExprTerm *pTerm;
  Fts5ExprPhrase *pPhrase;
  int i, j;
  int rc = SQLITE_OK;

  for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){
    pPhrase = pNear->apPhrase[i];
    Fts5ExprPhrase *pPhrase = pNear->apPhrase[i];
    for(j=0; j<pPhrase->nTerm; j++){
      pTerm = &pPhrase->aTerm[j];
      if( pTerm->pIter ){
        sqlite3Fts5IterClose(pTerm->pIter);
        pTerm->pIter = 0;
      }
      rc = sqlite3Fts5IndexQuery(
          pExpr->pIndex, pTerm->zTerm, strlen(pTerm->zTerm),
          (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) |
          (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0),
          &pTerm->pIter
      );
      assert( rc==SQLITE_OK || pTerm->pIter==0 );
      if( pTerm->pIter==0 || sqlite3Fts5IterEof(pTerm->pIter) ){
      Fts5ExprTerm *pTerm = &pPhrase->aTerm[j];
      Fts5ExprTerm *p;
      int bEof = 1;

      for(p=pTerm; p && rc==SQLITE_OK; p=p->pSynonym){
        if( p->pIter ){
          sqlite3Fts5IterClose(p->pIter);
          p->pIter = 0;
        }
        rc = sqlite3Fts5IndexQuery(
            pExpr->pIndex, p->zTerm, strlen(p->zTerm),
            (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) |
            (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0),
            &p->pIter
        );
        assert( rc==SQLITE_OK || p->pIter==0 );
        if( p->pIter && 0==sqlite3Fts5IterEof(p->pIter) ){
          bEof = 0;
        }
      }

      if( bEof ){
        pNode->bEof = 1;
        break;
        return rc;
      }
    }
  }

  return rc;
}

3846
3847
3848
3849
3850
3851
3852

3853
3854






3855
3856


3857
3858
3859
3860
3861
3862
3863
4153
4154
4155
4156
4157
4158
4159
4160


4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177







+
-
-
+
+
+
+
+
+


+
+







    switch( pNode->eType ){
      case FTS5_STRING: {
        rc = fts5ExprNearAdvanceFirst(pExpr, pNode, bFromValid, iFrom);
        break;
      };

      case FTS5_TERM: {
        Fts5IndexIter *pIter = pNode->pNear->apPhrase[0]->aTerm[0].pIter;
        rc = fts5ExprNearAdvanceFirst(pExpr, pNode, bFromValid, iFrom);
        if( pNode->bEof==0 ){
        if( bFromValid ){
          rc = sqlite3Fts5IterNextFrom(pIter, iFrom);
        }else{
          rc = sqlite3Fts5IterNext(pIter);
        }
        if( rc==SQLITE_OK && sqlite3Fts5IterEof(pIter)==0 ){
          assert( rc==SQLITE_OK );
          rc = fts5ExprTokenTest(pExpr, pNode);
        }else{
          pNode->bEof = 1;
        }
        return rc;
      };

      case FTS5_AND: {
        Fts5ExprNode *pLeft = pNode->apChild[0];
        rc = fts5ExprNodeNext(pExpr, pLeft, bFromValid, iFrom);
4083
4084
4085
4086
4087
4088
4089


4090
4091
4092
4093






4094
4095
4096
4097
4098
4099
4100
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407


4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420







+
+


-
-
+
+
+
+
+
+







/*
** Free the phrase object passed as the only argument.
*/
static void fts5ExprPhraseFree(Fts5ExprPhrase *pPhrase){
  if( pPhrase ){
    int i;
    for(i=0; i<pPhrase->nTerm; i++){
      Fts5ExprTerm *pSyn;
      Fts5ExprTerm *pNext;
      Fts5ExprTerm *pTerm = &pPhrase->aTerm[i];
      sqlite3_free(pTerm->zTerm);
      if( pTerm->pIter ){
        sqlite3Fts5IterClose(pTerm->pIter);
      sqlite3Fts5IterClose(pTerm->pIter);

      for(pSyn=pTerm->pSynonym; pSyn; pSyn=pNext){
        pNext = pSyn->pSynonym;
        sqlite3Fts5IterClose(pSyn->pIter);
        sqlite3_free(pSyn);
      }
    }
    if( pPhrase->poslist.nSpace>0 ) fts5BufferFree(&pPhrase->poslist);
    sqlite3_free(pPhrase);
  }
}

4148
4149
4150
4151
4152
4153
4154

4155
4156
4157
4158
4159
4160
4161

4162
4163
4164
4165


4166
4167
4168
4169
4170






4171
4172
4173
4174
4175

















4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189




















4190
4191
4192
4193
4194
4195
4196
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485


4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498





4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516













4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543







+







+


-
-
+
+





+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  }
  return pRet;
}

typedef struct TokenCtx TokenCtx;
struct TokenCtx {
  Fts5ExprPhrase *pPhrase;
  int rc;
};

/*
** Callback for tokenizing terms used by ParseTerm().
*/
static int fts5ParseTokenize(
  void *pContext,                 /* Pointer to Fts5InsertCtx object */
  int tflags,                     /* Mask of FTS5_TOKEN_* flags */
  const char *pToken,             /* Buffer containing token */
  int nToken,                     /* Size of token in bytes */
  int iStart,                     /* Start offset of token */
  int iEnd                        /* End offset of token */
  int iUnused1,                   /* Start offset of token */
  int iUnused2                    /* End offset of token */
){
  int rc = SQLITE_OK;
  const int SZALLOC = 8;
  TokenCtx *pCtx = (TokenCtx*)pContext;
  Fts5ExprPhrase *pPhrase = pCtx->pPhrase;

  /* If an error has already occurred, this is a no-op */
  if( pCtx->rc!=SQLITE_OK ) return pCtx->rc;

  assert( pPhrase==0 || pPhrase->nTerm>0 );
  if( pPhrase && (tflags & FTS5_TOKEN_COLOCATED) ){
  Fts5ExprTerm *pTerm;

  if( pPhrase==0 || (pPhrase->nTerm % SZALLOC)==0 ){
    Fts5ExprPhrase *pNew;
    int nNew = SZALLOC + (pPhrase ? pPhrase->nTerm : 0);
    Fts5ExprTerm *pSyn;
    int nByte = sizeof(Fts5ExprTerm) + nToken+1;
    pSyn = (Fts5ExprTerm*)sqlite3_malloc(nByte);
    if( pSyn==0 ){
      rc = SQLITE_NOMEM;
    }else{
      memset(pSyn, 0, nByte);
      pSyn->zTerm = (char*)&pSyn[1];
      memcpy(pSyn->zTerm, pToken, nToken);
      pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
      pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn;
    }
  }else{
    Fts5ExprTerm *pTerm;
    if( pPhrase==0 || (pPhrase->nTerm % SZALLOC)==0 ){
      Fts5ExprPhrase *pNew;
      int nNew = SZALLOC + (pPhrase ? pPhrase->nTerm : 0);

    pNew = (Fts5ExprPhrase*)sqlite3_realloc(pPhrase, 
        sizeof(Fts5ExprPhrase) + sizeof(Fts5ExprTerm) * nNew
    );
    if( pNew==0 ) return SQLITE_NOMEM;
    if( pPhrase==0 ) memset(pNew, 0, sizeof(Fts5ExprPhrase));
    pCtx->pPhrase = pPhrase = pNew;
    pNew->nTerm = nNew - SZALLOC;
  }

  pTerm = &pPhrase->aTerm[pPhrase->nTerm++];
  memset(pTerm, 0, sizeof(Fts5ExprTerm));
  pTerm->zTerm = sqlite3Fts5Strndup(&rc, pToken, nToken);

      pNew = (Fts5ExprPhrase*)sqlite3_realloc(pPhrase, 
          sizeof(Fts5ExprPhrase) + sizeof(Fts5ExprTerm) * nNew
      );
      if( pNew==0 ){
        rc = SQLITE_NOMEM;
      }else{
        if( pPhrase==0 ) memset(pNew, 0, sizeof(Fts5ExprPhrase));
        pCtx->pPhrase = pPhrase = pNew;
        pNew->nTerm = nNew - SZALLOC;
      }
    }

    if( rc==SQLITE_OK ){
      pTerm = &pPhrase->aTerm[pPhrase->nTerm++];
      memset(pTerm, 0, sizeof(Fts5ExprTerm));
      pTerm->zTerm = sqlite3Fts5Strndup(&rc, pToken, nToken);
    }
  }

  pCtx->rc = rc;
  return rc;
}


/*
** Free the phrase object passed as the only argument.
*/
4234
4235
4236
4237
4238
4239
4240


4241

4242

4243
4244
4245

4246
4247
4248
4249
4250
4251
4252
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591

4592
4593
4594

4595
4596
4597
4598
4599
4600
4601
4602







+
+

+
-
+


-
+







  char *z = 0;

  memset(&sCtx, 0, sizeof(TokenCtx));
  sCtx.pPhrase = pAppend;

  rc = fts5ParseStringFromToken(pToken, &z);
  if( rc==SQLITE_OK ){
    int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_QUERY : 0);
    int n;
    sqlite3Fts5Dequote(z);
    n = strlen(z);
    rc = sqlite3Fts5Tokenize(pConfig, z, strlen(z), &sCtx, fts5ParseTokenize);
    rc = sqlite3Fts5Tokenize(pConfig, flags, z, n, &sCtx, fts5ParseTokenize);
  }
  sqlite3_free(z);
  if( rc ){
  if( rc || (rc = sCtx.rc) ){
    pParse->rc = rc;
    fts5ExprPhraseFree(sCtx.pPhrase);
    sCtx.pPhrase = 0;
  }else if( sCtx.pPhrase ){

    if( pAppend==0 ){
      if( (pParse->nPhrase % 8)==0 ){
4266
4267
4268
4269
4270
4271
4272









































































4273
4274
4275
4276
4277
4278
4279
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    pParse->apPhrase[pParse->nPhrase-1] = sCtx.pPhrase;
    assert( sCtx.pPhrase->nTerm>0 );
    sCtx.pPhrase->aTerm[sCtx.pPhrase->nTerm-1].bPrefix = bPrefix;
  }

  return sCtx.pPhrase;
}

/*
** Create a new FTS5 expression by cloning phrase iPhrase of the
** expression passed as the second argument.
*/
static int sqlite3Fts5ExprClonePhrase(
  Fts5Config *pConfig,
  Fts5Expr *pExpr, 
  int iPhrase, 
  Fts5Expr **ppNew
){
  int rc = SQLITE_OK;             /* Return code */
  Fts5ExprPhrase *pOrig;          /* The phrase extracted from pExpr */
  int i;                          /* Used to iterate through phrase terms */

  Fts5Expr *pNew = 0;             /* Expression to return via *ppNew */

  TokenCtx sCtx = {0,0};          /* Context object for fts5ParseTokenize */


  pOrig = pExpr->apExprPhrase[iPhrase];

  pNew = (Fts5Expr*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5Expr));
  if( rc==SQLITE_OK ){
    pNew->apExprPhrase = (Fts5ExprPhrase**)sqlite3Fts5MallocZero(&rc, 
        sizeof(Fts5ExprPhrase*));
  }
  if( rc==SQLITE_OK ){
    pNew->pRoot = (Fts5ExprNode*)sqlite3Fts5MallocZero(&rc, 
        sizeof(Fts5ExprNode));
  }
  if( rc==SQLITE_OK ){
    pNew->pRoot->pNear = (Fts5ExprNearset*)sqlite3Fts5MallocZero(&rc, 
        sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
  }

  for(i=0; rc==SQLITE_OK && i<pOrig->nTerm; i++){
    int tflags = 0;
    Fts5ExprTerm *p;
    for(p=&pOrig->aTerm[i]; p && rc==SQLITE_OK; p=p->pSynonym){
      const char *zTerm = p->zTerm;
      rc = fts5ParseTokenize((void*)&sCtx, tflags, zTerm, strlen(zTerm), 0, 0);
      tflags = FTS5_TOKEN_COLOCATED;
    }
    if( rc==SQLITE_OK ){
      sCtx.pPhrase->aTerm[i].bPrefix = pOrig->aTerm[i].bPrefix;
    }
  }

  if( rc==SQLITE_OK ){
    /* All the allocations succeeded. Put the expression object together. */
    pNew->pIndex = pExpr->pIndex;
    pNew->nPhrase = 1;
    pNew->apExprPhrase[0] = sCtx.pPhrase;
    pNew->pRoot->pNear->apPhrase[0] = sCtx.pPhrase;
    pNew->pRoot->pNear->nPhrase = 1;
    sCtx.pPhrase->pNode = pNew->pRoot;

    if( pOrig->nTerm==1 && pOrig->aTerm[0].pSynonym==0 ){
      pNew->pRoot->eType = FTS5_TERM;
    }else{
      pNew->pRoot->eType = FTS5_STRING;
    }
  }else{
    sqlite3Fts5ExprFree(pNew);
    fts5ExprPhraseFree(sCtx.pPhrase);
    pNew = 0;
  }

  *ppNew = pNew;
  return rc;
}


/*
** Token pTok has appeared in a MATCH expression where the NEAR operator
** is expected. If token pTok does not contain "NEAR", store an error
** in the pParse object.
*/
static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token *pTok){
4447
4448
4449
4450
4451
4452
4453
4454




4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473






4474




4475
4476

4477
4478
4479
4480
4481
4482
4483









4484
4485
4486
4487
4488
4489
4490
4870
4871
4872
4873
4874
4875
4876

4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905

4906
4907
4908
4909
4910
4911
4912







4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928







-
+
+
+
+



















+
+
+
+
+
+
-
+
+
+
+


+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+







      pRet->eType = eType;
      pRet->pNear = pNear;
      if( eType==FTS5_STRING ){
        int iPhrase;
        for(iPhrase=0; iPhrase<pNear->nPhrase; iPhrase++){
          pNear->apPhrase[iPhrase]->pNode = pRet;
        }
        if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1 ){
        if( pNear->nPhrase==1 
         && pNear->apPhrase[0]->nTerm==1 
         && pNear->apPhrase[0]->aTerm[0].pSynonym==0
        ){
          pRet->eType = FTS5_TERM;
        }
      }else{
        fts5ExprAddChildren(pRet, pLeft);
        fts5ExprAddChildren(pRet, pRight);
      }
    }
  }

  if( pRet==0 ){
    assert( pParse->rc!=SQLITE_OK );
    sqlite3Fts5ParseNodeFree(pLeft);
    sqlite3Fts5ParseNodeFree(pRight);
    sqlite3Fts5ParseNearsetFree(pNear);
  }
  return pRet;
}

static char *fts5ExprTermPrint(Fts5ExprTerm *pTerm){
  int nByte = 0;
  Fts5ExprTerm *p;
  char *zQuoted;

  /* Determine the maximum amount of space required. */
  for(p=pTerm; p; p=p->pSynonym){
  char *zQuoted = sqlite3_malloc(strlen(pTerm->zTerm) * 2 + 3 + 2);
    nByte += strlen(pTerm->zTerm) * 2 + 3 + 2;
  }
  zQuoted = sqlite3_malloc(nByte);

  if( zQuoted ){
    int i = 0;
    for(p=pTerm; p; p=p->pSynonym){
    char *zIn = pTerm->zTerm;
    zQuoted[i++] = '"';
    while( *zIn ){
      if( *zIn=='"' ) zQuoted[i++] = '"';
      zQuoted[i++] = *zIn++;
    }
    zQuoted[i++] = '"';
      char *zIn = p->zTerm;
      zQuoted[i++] = '"';
      while( *zIn ){
        if( *zIn=='"' ) zQuoted[i++] = '"';
        zQuoted[i++] = *zIn++;
      }
      zQuoted[i++] = '"';
      if( p->pSynonym ) zQuoted[i++] = '|';
    }
    if( pTerm->bPrefix ){
      zQuoted[i++] = ' ';
      zQuoted[i++] = '*';
    }
    zQuoted[i++] = '\0';
  }
  return zQuoted;
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
6065
6066
6067
6068
6069
6070
6071

6072
6073
6074
6075
6076
6077
6078







-







#define FTS5_DATA_ZERO_PADDING 8
#define FTS5_DATA_PADDING 20

typedef struct Fts5Data Fts5Data;
typedef struct Fts5DlidxIter Fts5DlidxIter;
typedef struct Fts5DlidxLvl Fts5DlidxLvl;
typedef struct Fts5DlidxWriter Fts5DlidxWriter;
typedef struct Fts5NodeIter Fts5NodeIter;
typedef struct Fts5PageWriter Fts5PageWriter;
typedef struct Fts5SegIter Fts5SegIter;
typedef struct Fts5DoclistIter Fts5DoclistIter;
typedef struct Fts5SegWriter Fts5SegWriter;
typedef struct Fts5Structure Fts5Structure;
typedef struct Fts5StructureLevel Fts5StructureLevel;
typedef struct Fts5StructureSegment Fts5StructureSegment;
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
6297
6298
6299
6300
6301
6302
6303


















6304
6305
6306
6307
6308
6309
6310







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








  i64 iSwitchRowid;               /* Firstest rowid of other than aFirst[1] */
  Fts5CResult *aFirst;            /* Current merge state (see above) */
  Fts5SegIter aSeg[1];            /* Array of segment iterators */
};


/*
** Object for iterating through the conents of a single internal node in 
** memory.
*/
struct Fts5NodeIter {
  /* Internal. Set and managed by fts5NodeIterXXX() functions. Except, 
  ** the EOF test for the iterator is (Fts5NodeIter.aData==0).  */
  const u8 *aData;
  int nData;
  int iOff;

  /* Output variables */
  Fts5Buffer term;
  int nEmpty;
  int iChild;
  int bDlidx;
};

/*
** An instance of the following type is used to iterate through the contents
** of a doclist-index record.
**
** pData:
**   Record containing the doclist-index data.
**
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
6326
6327
6328
6329
6330
6331
6332

















6333
6334
6335
6336
6337
6338
6339







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







};
struct Fts5DlidxIter {
  int nLvl;
  int iSegid;
  Fts5DlidxLvl aLvl[1];
};



/*
** The first argument passed to this macro is a pointer to an Fts5Buffer
** object.
*/
#define fts5BufferSize(pBuf,n) {                \
  if( pBuf->nSpace<n ) {                        \
    u8 *pNew = sqlite3_realloc(pBuf->p, n);     \
    if( pNew==0 ){                              \
      sqlite3_free(pBuf->p);                    \
    }                                           \
    pBuf->nSpace = n;                           \
    pBuf->p = pNew;                             \
  }                                             \
}

static void fts5PutU16(u8 *aOut, u16 iVal){
  aOut[0] = (iVal>>8);
  aOut[1] = (iVal&0xFF);
}

static u16 fts5GetU16(const u8 *aIn){
  return ((u16)aIn[0] << 8) + aIn[1];
5951
5952
5953
5954
5955
5956
5957

5958
5959
5960
5961
5962
5963
5964
5965
5966

5967
5968
5969
5970
5971
5972
5973
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368

6369
6370
6371
6372
6373
6374
6375
6376







+








-
+







** Compare the contents of the pLeft buffer with the pRight/nRight blob.
**
** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
** +ve if pRight is smaller than pLeft. In other words:
**
**     res = *pLeft - *pRight
*/
#ifdef SQLITE_DEBUG
static int fts5BufferCompareBlob(
  Fts5Buffer *pLeft,              /* Left hand side of comparison */
  const u8 *pRight, int nRight    /* Right hand side of comparison */
){
  int nCmp = MIN(pLeft->n, nRight);
  int res = memcmp(pLeft->p, pRight, nCmp);
  return (res==0 ? (pLeft->n - nRight) : res);
}

#endif

/*
** Compare the contents of the two buffers using memcmp(). If one buffer
** is a prefix of the other, it is considered the lesser.
**
** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
** +ve if pRight is smaller than pLeft. In other words:
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009








6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031


6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063







6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6402
6403
6404
6405
6406
6407
6408




6409
6410
6411
6412
6413
6414
6415
6416

6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435


6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454















6455
6456
6457
6458
6459
6460
6461

6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475











6476
6477
6478
6479












6480
6481
6482
6483
6484
6485
6486







-
-
-
-
+
+
+
+
+
+
+
+
-



















-
-
+
+

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-














-
-
-
-
-
-
-
-
-
-
-




-
-
-
-
-
-
-
-
-
-
-
-







  if( p->pReader ){
    sqlite3_blob *pReader = p->pReader;
    p->pReader = 0;
    sqlite3_blob_close(pReader);
  }
}

static Fts5Data *fts5DataReadOrBuffer(
  Fts5Index *p, 
  Fts5Buffer *pBuf, 
  i64 iRowid

/*
** Retrieve a record from the %_data table.
**
** If an error occurs, NULL is returned and an error left in the 
** Fts5Index object.
*/
static Fts5Data *fts5DataRead(Fts5Index *p, i64 iRowid){
){
  Fts5Data *pRet = 0;
  if( p->rc==SQLITE_OK ){
    int rc = SQLITE_OK;

    if( p->pReader ){
      /* This call may return SQLITE_ABORT if there has been a savepoint
      ** rollback since it was last used. In this case a new blob handle
      ** is required.  */
      sqlite3_blob *pBlob = p->pReader;
      p->pReader = 0;
      rc = sqlite3_blob_reopen(pBlob, iRowid);
      assert( p->pReader==0 );
      p->pReader = pBlob;
      if( rc!=SQLITE_OK ){
        fts5CloseReader(p);
      }
      if( rc==SQLITE_ABORT ) rc = SQLITE_OK;
    }

    /* If the blob handle is not yet open, open and seek it. Otherwise, use
    ** the blob_reopen() API to reseek the existing blob handle.  */
    /* If the blob handle is not open at this point, open it and seek 
    ** to the requested entry.  */
    if( p->pReader==0 && rc==SQLITE_OK ){
      Fts5Config *pConfig = p->pConfig;
      rc = sqlite3_blob_open(pConfig->db, 
          pConfig->zDb, p->zDataTbl, "block", iRowid, 0, &p->pReader
      );
    }

    /* If either of the sqlite3_blob_open() or sqlite3_blob_reopen() calls
    ** above returned SQLITE_ERROR, return SQLITE_CORRUPT_VTAB instead.
    ** All the reasons those functions might return SQLITE_ERROR - missing
    ** table, missing row, non-blob/text in block column - indicate 
    ** backing store corruption.  */
    if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT;

    if( rc==SQLITE_OK ){
      u8 *aOut = 0;               /* Read blob data into this buffer */
      int nByte = sqlite3_blob_bytes(p->pReader);
      if( pBuf ){
        fts5BufferSize(pBuf, MAX(nByte, p->pConfig->pgsz) + 20);
        pBuf->n = nByte;
        aOut = pBuf->p;
        if( aOut==0 ){
          rc = SQLITE_NOMEM;
        }
      }else{
        int nSpace = nByte + FTS5_DATA_PADDING;
        pRet = (Fts5Data*)sqlite3_malloc(nSpace+sizeof(Fts5Data));
        if( pRet ){
          pRet->n = nByte;
          aOut = pRet->p = (u8*)&pRet[1];
        }else{
          rc = SQLITE_NOMEM;
      int nAlloc = sizeof(Fts5Data) + nByte + FTS5_DATA_PADDING;
      pRet = (Fts5Data*)sqlite3_malloc(nAlloc);
      if( pRet ){
        pRet->n = nByte;
        aOut = pRet->p = (u8*)&pRet[1];
      }else{
        rc = SQLITE_NOMEM;
        }
      }

      if( rc==SQLITE_OK ){
        rc = sqlite3_blob_read(p->pReader, aOut, nByte, 0);
      }
      if( rc!=SQLITE_OK ){
        sqlite3_free(pRet);
        pRet = 0;
      }
    }
    p->rc = rc;
    p->nRead++;
  }

  return pRet;
}

/*
** Retrieve a record from the %_data table.
**
** If an error occurs, NULL is returned and an error left in the 
** Fts5Index object.
*/
static Fts5Data *fts5DataRead(Fts5Index *p, i64 iRowid){
  Fts5Data *pRet = fts5DataReadOrBuffer(p, 0, iRowid);
  assert( (pRet==0)==(p->rc!=SQLITE_OK) );
  return pRet;
}

/*
** Read a record from the %_data table into the buffer supplied as the
** second argument.
**
** If an error occurs, an error is left in the Fts5Index object. If an
** error has already occurred when this function is called, it is a 
** no-op.
*/
static void fts5DataBuffer(Fts5Index *p, Fts5Buffer *pBuf, i64 iRowid){
  (void)fts5DataReadOrBuffer(p, pBuf, iRowid);
}

/*
** Release a reference to data record returned by an earlier call to
** fts5DataRead().
*/
static void fts5DataRelease(Fts5Data *pData){
  sqlite3_free(pData);
}
6367
6368
6369
6370
6371
6372
6373

6374
6375
6376
6377


6378
6379
6380


6381
6382
6383
6384
6385
6386

6387
6388
6389
6390
6391
6392
6393
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750


6751
6752



6753
6754

6755
6756
6757
6758

6759
6760
6761
6762
6763
6764
6765
6766







+


-
-
+
+
-
-
-
+
+
-




-
+







** Fts5Index handle. If an error has already occurred when this function
** is called, it is a no-op.
*/
static Fts5Structure *fts5StructureRead(Fts5Index *p){
  Fts5Config *pConfig = p->pConfig;
  Fts5Structure *pRet = 0;        /* Object to return */
  int iCookie;                    /* Configuration cookie */
  Fts5Data *pData;
  Fts5Buffer buf = {0, 0, 0};

  fts5DataBuffer(p, &buf, FTS5_STRUCTURE_ROWID);
  if( buf.p==0 ) return 0;
  pData = fts5DataRead(p, FTS5_STRUCTURE_ROWID);
  if( p->rc ) return 0;
  assert( buf.nSpace>=(buf.n + FTS5_DATA_ZERO_PADDING) );
  memset(&buf.p[buf.n], 0, FTS5_DATA_ZERO_PADDING);
  p->rc = fts5StructureDecode(buf.p, buf.n, &iCookie, &pRet);
  memset(&pData->p[pData->n], 0, FTS5_DATA_PADDING);
  p->rc = fts5StructureDecode(pData->p, pData->n, &iCookie, &pRet);

  if( p->rc==SQLITE_OK && pConfig->iCookie!=iCookie ){
    p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie);
  }

  fts5BufferFree(&buf);
  fts5DataRelease(pData);
  if( p->rc!=SQLITE_OK ){
    fts5StructureRelease(pRet);
    pRet = 0;
  }
  return pRet;
}

6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6935
6936
6937
6938
6939
6940
6941
























































6942
6943
6944
6945
6946
6947
6948







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







      szPromote = szSeg;
    }
    fts5StructurePromoteTo(p, iPromote, szPromote, pStruct);
  }
}


/*
** If the pIter->iOff offset currently points to an entry indicating one
** or more term-less nodes, advance past it and set pIter->nEmpty to
** the number of empty child nodes.
*/
static void fts5NodeIterGobbleNEmpty(Fts5NodeIter *pIter){
  if( pIter->iOff<pIter->nData && 0==(pIter->aData[pIter->iOff] & 0xfe) ){
    pIter->bDlidx = pIter->aData[pIter->iOff] & 0x01;
    pIter->iOff++;
    pIter->iOff += fts5GetVarint32(&pIter->aData[pIter->iOff], pIter->nEmpty);
  }else{
    pIter->nEmpty = 0;
    pIter->bDlidx = 0;
  }
}

/*
** Advance to the next entry within the node.
*/
static void fts5NodeIterNext(int *pRc, Fts5NodeIter *pIter){
  if( pIter->iOff>=pIter->nData ){
    pIter->aData = 0;
    pIter->iChild += pIter->nEmpty;
  }else{
    int nPre, nNew;
    pIter->iOff += fts5GetVarint32(&pIter->aData[pIter->iOff], nPre);
    pIter->iOff += fts5GetVarint32(&pIter->aData[pIter->iOff], nNew);
    pIter->term.n = nPre-2;
    fts5BufferAppendBlob(pRc, &pIter->term, nNew, pIter->aData+pIter->iOff);
    pIter->iOff += nNew;
    pIter->iChild += (1 + pIter->nEmpty);
    fts5NodeIterGobbleNEmpty(pIter);
    if( *pRc ) pIter->aData = 0;
  }
}


/*
** Initialize the iterator object pIter to iterate through the internal
** segment node in pData.
*/
static void fts5NodeIterInit(const u8 *aData, int nData, Fts5NodeIter *pIter){
  memset(pIter, 0, sizeof(*pIter));
  pIter->aData = aData;
  pIter->nData = nData;
  pIter->iOff = fts5GetVarint32(aData, pIter->iChild);
  fts5NodeIterGobbleNEmpty(pIter);
}

/*
** Free any memory allocated by the iterator object.
*/
static void fts5NodeIterFree(Fts5NodeIter *pIter){
  fts5BufferFree(&pIter->term);
}

/*
** Advance the iterator passed as the only argument. If the end of the 
** doclist-index page is reached, return non-zero.
*/
static int fts5DlidxLvlNext(Fts5DlidxLvl *pLvl){
  Fts5Data *pData = pLvl->pData;

7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7692
7693
7694
7695
7696
7697
7698

















































































































7699
7700
7701
7702
7703
7704
7705







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







      iOff += nPos;
    }
  }

  pIter->pDlidx = fts5DlidxIterInit(p, bRev, iSeg, pIter->iTermLeafPgno);
}

#ifdef SQLITE_DEBUG
static void fts5AssertNodeSeekOk(
  Fts5Buffer *pNode,
  const u8 *pTerm, int nTerm,     /* Term to search for */
  int iExpectPg,
  int bExpectDlidx
){
  int bDlidx;
  int iPg;
  int rc = SQLITE_OK;
  Fts5NodeIter node;

  fts5NodeIterInit(pNode->p, pNode->n, &node);
  assert( node.term.n==0 );
  iPg = node.iChild;
  bDlidx = node.bDlidx;
  for(fts5NodeIterNext(&rc, &node);
      node.aData && fts5BufferCompareBlob(&node.term, pTerm, nTerm)<=0;
      fts5NodeIterNext(&rc, &node)
  ){
    iPg = node.iChild;
    bDlidx = node.bDlidx;
  }
  fts5NodeIterFree(&node);

  assert( rc!=SQLITE_OK || iPg==iExpectPg );
  assert( rc!=SQLITE_OK || bDlidx==bExpectDlidx );
}
#else
#define fts5AssertNodeSeekOk(v,w,x,y,z)
#endif

/*
** Argument pNode is an internal b-tree node. This function searches
** within the node for the largest term that is smaller than or equal
** to (pTerm/nTerm).
**
** It returns the associated page number. Or, if (pTerm/nTerm) is smaller
** than all terms within the node, the leftmost child page number. 
**
** Before returning, (*pbDlidx) is set to true if the last term on the
** returned child page number has a doclist-index. Or left as is otherwise.
*/
static int fts5NodeSeek(
  Fts5Buffer *pNode,              /* Node to search */
  const u8 *pTerm, int nTerm,     /* Term to search for */
  int *pbDlidx                    /* OUT: True if dlidx flag is set */
){
  int iPg;
  u8 *pPtr = pNode->p;
  u8 *pEnd = &pPtr[pNode->n];
  int nMatch = 0;                 /* Number of bytes of pTerm already matched */
  
  assert( *pbDlidx==0 );

  pPtr += fts5GetVarint32(pPtr, iPg);
  while( pPtr<pEnd ){
    int nEmpty = 0;
    int nKeep;
    int nNew;

    /* If there is a "no terms" record at pPtr, read it now. Store the
    ** number of termless pages in nEmpty. If it indicates a doclist-index, 
    ** set (*pbDlidx) to true.*/
    if( *pPtr<2 ){
      *pbDlidx = (*pPtr==0x01);
      pPtr++;
      pPtr += fts5GetVarint32(pPtr, nEmpty);
      if( pPtr>=pEnd ) break;
    }

    /* Read the next "term" pointer. Set nKeep to the number of bytes to
    ** keep from the previous term, and nNew to the number of bytes of
    ** new data that will be appended to it. */
    nKeep = (int)*pPtr++;
    nNew = (int)*pPtr++;
    if( (nKeep | nNew) & 0x0080 ){
      pPtr -= 2;
      pPtr += fts5GetVarint32(pPtr, nKeep);
      pPtr += fts5GetVarint32(pPtr, nNew);
    }
    nKeep -= 2;

    /* Compare (pTerm/nTerm) to the current term on the node (the one described
    ** by nKeep/nNew). If the node term is larger, break out of the while()
    ** loop. 
    **
    ** Otherwise, if (pTerm/nTerm) is larger or the two terms are equal, 
    ** leave variable nMatch set to the size of the largest prefix common to
    ** both terms in bytes.  */
    if( nKeep==nMatch ){
      int nTst = MIN(nNew, nTerm-nMatch);
      int i;
      for(i=0; i<nTst; i++){
        if( pTerm[nKeep+i]!=pPtr[i] ) break;
      }
      nMatch += i;
      assert( nMatch<=nTerm );

      if( i<nNew && (nMatch==nTerm || pPtr[i] > pTerm[nMatch]) ) break;
    }else if( nKeep<nMatch ){
      break;
    }

    iPg += 1 + nEmpty;
    *pbDlidx = 0;
    pPtr += nNew;
  }

  fts5AssertNodeSeekOk(pNode, pTerm, nTerm, iPg, *pbDlidx);
  return iPg;
}

#define fts5IndexGetVarint32(a, iOff, nVal) {     \
  nVal = a[iOff++];                               \
  if( nVal & 0x80 ){                              \
    iOff--;                                       \
    iOff += fts5GetVarint32(&a[iOff], nVal);      \
  }                                               \
}
8011
8012
8013
8014
8015
8016
8017
8018

8019
8020
8021
8022
8023
8024

8025
8026
8027
8028
8029
8030
8031
8215
8216
8217
8218
8219
8220
8221

8222
8223
8224
8225
8226
8227

8228
8229
8230
8231
8232
8233
8234
8235







-
+





-
+







    if( iLeafPgno<pIter->iLeafPgno ){
      pIter->iLeafPgno = iLeafPgno+1;
      fts5SegIterReverseNewPage(p, pIter);
      bMove = 0;
    }
  }

  while( p->rc==SQLITE_OK ){
  do{
    if( bMove ) fts5SegIterNext(p, pIter, 0);
    if( pIter->pLeaf==0 ) break;
    if( bRev==0 && pIter->iRowid>=iMatch ) break;
    if( bRev!=0 && pIter->iRowid<=iMatch ) break;
    bMove = 1;
  }
  }while( p->rc==SQLITE_OK );
}


/*
** Free the iterator object passed as the second argument.
*/
static void fts5MultiIterFree(Fts5Index *p, Fts5IndexIter *pIter){
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804

9805
9806
9807
9808
9809
9810
9811
9812
9813
9997
9998
9999
10000
10001
10002
10003




10004
10005
10006

10007
10008
10009
10010
10011
10012
10013







-
-
-
-

+

-







/*
** The %_data table is completely empty when this function is called. This
** function populates it with the initial structure objects for each index,
** and the initial version of the "averages" record (a zero-byte blob).
*/
static int sqlite3Fts5IndexReinit(Fts5Index *p){
  Fts5Structure s;

  assert( p->rc==SQLITE_OK );
  p->rc = sqlite3Fts5IndexSetAverages(p, (const u8*)"", 0);

  memset(&s, 0, sizeof(Fts5Structure));
  fts5DataWrite(p, FTS5_AVERAGES_ROWID, (const u8*)"", 0);
  fts5StructureWrite(p, &s);

  return fts5IndexReturn(p);
}

/*
** Open a new Fts5Index handle. If the bCreate argument is true, create
** and initialize the underlying %_data table.
**
10121
10122
10123
10124
10125
10126
10127
10128

10129
10130



10131
10132
10133
10134

















10135
10136
10137
10138
10139
10140
10141
10321
10322
10323
10324
10325
10326
10327

10328


10329
10330
10331
10332



10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356







-
+
-
-
+
+
+

-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    Fts5Index *pIndex = pIter->pIndex;
    fts5MultiIterFree(pIter->pIndex, pIter);
    fts5CloseReader(pIndex);
  }
}

/*
** Read the "averages" record into the buffer supplied as the second 
** Read and decode the "averages" record from the database. 
** argument. Return SQLITE_OK if successful, or an SQLite error code
** if an error occurs.
**
** Parameter anSize must point to an array of size nCol, where nCol is
** the number of user defined columns in the FTS table.
*/
static int sqlite3Fts5IndexGetAverages(Fts5Index *p, Fts5Buffer *pBuf){
  assert( p->rc==SQLITE_OK );
  fts5DataReadOrBuffer(p, pBuf, FTS5_AVERAGES_ROWID);
static int sqlite3Fts5IndexGetAverages(Fts5Index *p, i64 *pnRow, i64 *anSize){
  int nCol = p->pConfig->nCol;
  Fts5Data *pData;

  *pnRow = 0;
  memset(anSize, 0, sizeof(i64) * nCol);
  pData = fts5DataRead(p, FTS5_AVERAGES_ROWID);
  if( p->rc==SQLITE_OK && pData->n ){
    int i = 0;
    int iCol;
    i += fts5GetVarint(&pData->p[i], (u64*)pnRow);
    for(iCol=0; i<pData->n && iCol<nCol; iCol++){
      i += fts5GetVarint(&pData->p[i], (u64*)&anSize[iCol]);
    }
  }

  fts5DataRelease(pData);
  return fts5IndexReturn(p);
}

/*
** Replace the current "averages" record with the contents of the buffer 
** supplied as the second argument.
*/
10661
10662
10663
10664
10665
10666
10667
10668

10669
10670

10671
10672
10673
10674

10675
10676
10677
10678
10679
10680
10681
10876
10877
10878
10879
10880
10881
10882

10883
10884

10885
10886
10887
10888

10889
10890
10891
10892
10893
10894
10895
10896







-
+

-
+



-
+








static void fts5DebugRowid(int *pRc, Fts5Buffer *pBuf, i64 iKey){
  int iSegid, iHeight, iPgno, bDlidx;       /* Rowid compenents */
  fts5DecodeRowid(iKey, &iSegid, &bDlidx, &iHeight, &iPgno);

  if( iSegid==0 ){
    if( iKey==FTS5_AVERAGES_ROWID ){
      sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "(averages) ");
      sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "{averages} ");
    }else{
      sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "(structure)");
      sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "{structure}");
    }
  }
  else{
    sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "(%ssegid=%d h=%d pgno=%d)",
    sqlite3Fts5BufferAppendPrintf(pRc, pBuf, "{%ssegid=%d h=%d pgno=%d}",
        bDlidx ? "dlidx " : "", iSegid, iHeight, iPgno
    );
  }
}

static void fts5DebugStructure(
  int *pRc,                       /* IN/OUT: error code */
10821
10822
10823
10824
10825
10826
10827
10828
10829





10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844







10845
10846
10847
10848
10849
10850
10851
10852
10853








10854
10855
10856
10857
10858




10859
10860
10861
10862
10863
10864
10865
10866







10867
10868
10869
10870
10871
10872
10873
10874
10875
10876









10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
11036
11037
11038
11039
11040
11041
11042

11043
11044
11045
11046
11047
11048
11049
11050













11051
11052
11053
11054
11055
11056
11057
11058








11059
11060
11061
11062
11063
11064
11065
11066
11067




11068
11069
11070
11071
11072







11073
11074
11075
11076
11077
11078
11079
11080









11081
11082
11083
11084
11085
11086
11087
11088
11089


















11090
11091
11092
11093
11094
11095
11096







-

+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







  }else if( iSegid==0 ){
    if( iRowid==FTS5_AVERAGES_ROWID ){
      /* todo */
    }else{
      fts5DecodeStructure(&rc, &s, a, n);
    }
  }else{

    Fts5Buffer term;
    int iTermOff = 0;
    int iRowidOff = 0;
    int iOff;
    int nKeep = 0;

    memset(&term, 0, sizeof(Fts5Buffer));

    if( iHeight==0 ){
      int iTermOff = 0;
      int iRowidOff = 0;
      int iOff;
      int nKeep = 0;

      if( n>=4 ){
        iRowidOff = fts5GetU16(&a[0]);
        iTermOff = fts5GetU16(&a[2]);
      }else{
        sqlite3Fts5BufferSet(&rc, &s, 8, (const u8*)"corrupt");
        goto decode_out;
      }
    if( n>=4 ){
      iRowidOff = fts5GetU16(&a[0]);
      iTermOff = fts5GetU16(&a[2]);
    }else{
      sqlite3Fts5BufferSet(&rc, &s, 8, (const u8*)"corrupt");
      goto decode_out;
    }

      if( iRowidOff ){
        iOff = iRowidOff;
      }else if( iTermOff ){
        iOff = iTermOff;
      }else{
        iOff = n;
      }
      fts5DecodePoslist(&rc, &s, &a[4], iOff-4);
    if( iRowidOff ){
      iOff = iRowidOff;
    }else if( iTermOff ){
      iOff = iTermOff;
    }else{
      iOff = n;
    }
    fts5DecodePoslist(&rc, &s, &a[4], iOff-4);

      assert( iRowidOff==0 || iOff==iRowidOff );
      if( iRowidOff ){
        iOff += fts5DecodeDoclist(&rc, &s, &a[iOff], n-iOff);
      }
    assert( iRowidOff==0 || iOff==iRowidOff );
    if( iRowidOff ){
      iOff += fts5DecodeDoclist(&rc, &s, &a[iOff], n-iOff);
    }

      assert( iTermOff==0 || iOff==iTermOff );
      while( iOff<n ){
        int nByte;
        iOff += fts5GetVarint32(&a[iOff], nByte);
        term.n= nKeep;
        fts5BufferAppendBlob(&rc, &term, nByte, &a[iOff]);
        iOff += nByte;
    assert( iTermOff==0 || iOff==iTermOff );
    while( iOff<n ){
      int nByte;
      iOff += fts5GetVarint32(&a[iOff], nByte);
      term.n= nKeep;
      fts5BufferAppendBlob(&rc, &term, nByte, &a[iOff]);
      iOff += nByte;

        sqlite3Fts5BufferAppendPrintf(
            &rc, &s, " term=%.*s", term.n, (const char*)term.p
        );
        iOff += fts5DecodeDoclist(&rc, &s, &a[iOff], n-iOff);
        if( iOff<n ){
          iOff += fts5GetVarint32(&a[iOff], nKeep);
        }
      }
      fts5BufferFree(&term);
      sqlite3Fts5BufferAppendPrintf(
          &rc, &s, " term=%.*s", term.n, (const char*)term.p
          );
      iOff += fts5DecodeDoclist(&rc, &s, &a[iOff], n-iOff);
      if( iOff<n ){
        iOff += fts5GetVarint32(&a[iOff], nKeep);
      }
    }
    fts5BufferFree(&term);
    }else{
      Fts5NodeIter ss;
      for(fts5NodeIterInit(a, n, &ss); ss.aData; fts5NodeIterNext(&rc, &ss)){
        if( ss.term.n==0 ){
          sqlite3Fts5BufferAppendPrintf(&rc, &s, " left=%d", ss.iChild);
        }else{
          sqlite3Fts5BufferAppendPrintf(&rc,&s, " \"%.*s\"", 
              ss.term.n, ss.term.p
          );
        }
        if( ss.nEmpty ){
          sqlite3Fts5BufferAppendPrintf(&rc, &s, " empty=%d%s", ss.nEmpty,
              ss.bDlidx ? "*" : ""
          );
        }
      }
      fts5NodeIterFree(&ss);
    }
  }
  
 decode_out:
  sqlite3_free(a);
  if( rc==SQLITE_OK ){
    sqlite3_result_text(pCtx, (const char*)s.p, s.n, SQLITE_TRANSIENT);
  }else{
12458
12459
12460
12461
12462
12463
12464
12465

12466
12467
12468
12469



12470
12471
12472
12473
12474
12475
12476
12653
12654
12655
12656
12657
12658
12659

12660
12661
12662
12663

12664
12665
12666
12667
12668
12669
12670
12671
12672
12673







-
+



-
+
+
+







  return sqlite3Fts5StorageRowCount(pTab->pStorage, pnRow);
}

static int fts5ApiTokenize(
  Fts5Context *pCtx, 
  const char *pText, int nText, 
  void *pUserData,
  int (*xToken)(void*, const char*, int, int, int)
  int (*xToken)(void*, int, const char*, int, int, int)
){
  Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
  return sqlite3Fts5Tokenize(pTab->pConfig, pText, nText, pUserData, xToken);
  return sqlite3Fts5Tokenize(
      pTab->pConfig, FTS5_TOKENIZE_AUX, pText, nText, pUserData, xToken
  );
}

static int fts5ApiPhraseCount(Fts5Context *pCtx){
  Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  return sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
}

12615
12616
12617
12618
12619
12620
12621

12622
12623
12624
12625
12626
12627

12628


12629
12630
12631
12632
12633
12634
12635
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826

12827
12828
12829
12830
12831
12832
12833
12834
12835







+






+
-
+
+







    }
  }
  return rc;
}

static int fts5ColumnSizeCb(
  void *pContext,                 /* Pointer to int */
  int tflags,
  const char *pToken,             /* Buffer containing token */
  int nToken,                     /* Size of token in bytes */
  int iStart,                     /* Start offset of token */
  int iEnd                        /* End offset of token */
){
  int *pCnt = (int*)pContext;
  if( (tflags & FTS5_TOKEN_COLOCATED)==0 ){
  *pCnt = *pCnt + 1;
    (*pCnt)++;
  }
  return SQLITE_OK;
}

static int fts5ApiColumnSize(Fts5Context *pCtx, int iCol, int *pnToken){
  Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
  Fts5Config *pConfig = pTab->pConfig;
12651
12652
12653
12654
12655
12656
12657
12658



12659
12660
12661
12662
12663
12664
12665
12851
12852
12853
12854
12855
12856
12857

12858
12859
12860
12861
12862
12863
12864
12865
12866
12867







-
+
+
+







      for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
        if( pConfig->abUnindexed[i]==0 ){
          const char *z; int n;
          void *p = (void*)(&pCsr->aColumnSize[i]);
          pCsr->aColumnSize[i] = 0;
          rc = fts5ApiColumnText(pCtx, i, &z, &n);
          if( rc==SQLITE_OK ){
            rc = sqlite3Fts5Tokenize(pConfig, z, n, p, fts5ColumnSizeCb);
            rc = sqlite3Fts5Tokenize(
                pConfig, FTS5_TOKENIZE_AUX, z, n, p, fts5ColumnSizeCb
            );
          }
        }
      }
    }
    CsrFlagClear(pCsr, FTS5CSR_REQUIRE_DOCSIZE);
  }
  if( iCol<0 ){
12813
12814
12815
12816
12817
12818
12819
12820

12821
12822
12823
12824
12825
12826
12827
13015
13016
13017
13018
13019
13020
13021

13022
13023
13024
13025
13026
13027
13028
13029







-
+







  rc = fts5OpenMethod(pCsr->base.pVtab, (sqlite3_vtab_cursor**)&pNew);
  if( rc==SQLITE_OK ){
    Fts5Config *pConf = pTab->pConfig;
    pNew->ePlan = FTS5_PLAN_MATCH;
    pNew->iFirstRowid = SMALLEST_INT64;
    pNew->iLastRowid = LARGEST_INT64;
    pNew->base.pVtab = (sqlite3_vtab*)pTab;
    rc = sqlite3Fts5ExprPhraseExpr(pConf, pCsr->pExpr, iPhrase, &pNew->pExpr);
    rc = sqlite3Fts5ExprClonePhrase(pConf, pCsr->pExpr, iPhrase, &pNew->pExpr);
  }

  if( rc==SQLITE_OK ){
    for(rc = fts5CursorFirst(pTab, pNew, 0);
        rc==SQLITE_OK && CsrFlagTest(pNew, FTS5CSR_EOF)==0;
        rc = fts5NextMethod((sqlite3_vtab_cursor*)pNew)
    ){
13255
13256
13257
13258
13259
13260
13261
13262

13263
13264
13265
13266
13267
13268
13269
13457
13458
13459
13460
13461
13462
13463

13464
13465
13466
13467
13468
13469
13470
13471







-
+







*/
static void fts5SourceIdFunc(
  sqlite3_context *pCtx,          /* Function call context */
  int nArg,                       /* Number of args */
  sqlite3_value **apVal           /* Function arguments */
){
  assert( nArg==0 );
  sqlite3_result_text(pCtx, "fts5: 2015-08-18 19:09:28 8599402092537ab3df8926eb900661c12d738d4c", -1, SQLITE_TRANSIENT);
  sqlite3_result_text(pCtx, "fts5: 2015-09-09 19:44:33 8d2ed150a7a15626965cf994ef48c3ab61eca6ec", -1, SQLITE_TRANSIENT);
}

#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_fts5_init(
  sqlite3 *db,
13304
13305
13306
13307
13308
13309
13310
13311

13312
13313
13314
13315
13316
13317
13318
13506
13507
13508
13509
13510
13511
13512

13513
13514
13515
13516
13517
13518
13519
13520







-
+







  pGlobal = (Fts5Global*)sqlite3_malloc(sizeof(Fts5Global));
  if( pGlobal==0 ){
    rc = SQLITE_NOMEM;
  }else{
    void *p = (void*)pGlobal;
    memset(pGlobal, 0, sizeof(Fts5Global));
    pGlobal->db = db;
    pGlobal->api.iVersion = 1;
    pGlobal->api.iVersion = 2;
    pGlobal->api.xCreateFunction = fts5CreateAux;
    pGlobal->api.xCreateTokenizer = fts5CreateTokenizer;
    pGlobal->api.xFindTokenizer = fts5FindTokenizer;
    rc = sqlite3_create_module_v2(db, "fts5", &fts5Mod, p, fts5ModuleDestroy);
    if( rc==SQLITE_OK ) rc = sqlite3Fts5IndexInit(db);
    if( rc==SQLITE_OK ) rc = sqlite3Fts5ExprInit(pGlobal, db);
    if( rc==SQLITE_OK ) rc = sqlite3Fts5AuxInit(&pGlobal->api);
13702
13703
13704
13705
13706
13707
13708

13709
13710
13711
13712
13713
13714
13715

13716
13717



13718
13719
13720
13721
13722
13723
13724
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919


13920
13921
13922
13923
13924
13925
13926
13927
13928
13929







+







+
-
-
+
+
+







};

/*
** Tokenization callback used when inserting tokens into the FTS index.
*/
static int fts5StorageInsertCallback(
  void *pContext,                 /* Pointer to Fts5InsertCtx object */
  int tflags,
  const char *pToken,             /* Buffer containing token */
  int nToken,                     /* Size of token in bytes */
  int iStart,                     /* Start offset of token */
  int iEnd                        /* End offset of token */
){
  Fts5InsertCtx *pCtx = (Fts5InsertCtx*)pContext;
  Fts5Index *pIdx = pCtx->pStorage->pIndex;
  if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
  int iPos = pCtx->szCol++;
  return sqlite3Fts5IndexWrite(pIdx, pCtx->iCol, iPos, pToken, nToken);
    pCtx->szCol++;
  }
  return sqlite3Fts5IndexWrite(pIdx, pCtx->iCol, pCtx->szCol-1, pToken, nToken);
}

/*
** If a row with rowid iDel is present in the %_content table, add the
** delete-markers to the FTS index necessary to delete it. Do not actually
** remove the %_content row at this time though.
*/
13737
13738
13739
13740
13741
13742
13743

13744
13745
13746
13747
13748
13749
13750
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956







+







      ctx.pStorage = p;
      ctx.iCol = -1;
      rc = sqlite3Fts5IndexBeginWrite(p->pIndex, iDel);
      for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){
        if( pConfig->abUnindexed[iCol-1] ) continue;
        ctx.szCol = 0;
        rc = sqlite3Fts5Tokenize(pConfig, 
            FTS5_TOKENIZE_DOCUMENT,
            (const char*)sqlite3_column_text(pSeek, iCol),
            sqlite3_column_bytes(pSeek, iCol),
            (void*)&ctx,
            fts5StorageInsertCallback
        );
        p->aTotalSize[iCol-1] -= (i64)ctx.szCol;
      }
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807

13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
14000
14001
14002
14003
14004
14005
14006







14007









14008
14009
14010
14011
14012
14013
14014







-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-







**
** Return SQLITE_OK if successful, or an SQLite error code if an error
** occurs.
*/
static int fts5StorageLoadTotals(Fts5Storage *p, int bCache){
  int rc = SQLITE_OK;
  if( p->bTotalsValid==0 ){
    int nCol = p->pConfig->nCol;
    Fts5Buffer buf;
    memset(&buf, 0, sizeof(buf));

    memset(p->aTotalSize, 0, sizeof(i64) * nCol);
    p->nTotalRow = 0;
    rc = sqlite3Fts5IndexGetAverages(p->pIndex, &buf);
    rc = sqlite3Fts5IndexGetAverages(p->pIndex, &p->nTotalRow, p->aTotalSize);
    if( rc==SQLITE_OK && buf.n ){
      int i = 0;
      int iCol;
      i += fts5GetVarint(&buf.p[i], (u64*)&p->nTotalRow);
      for(iCol=0; i<buf.n && iCol<nCol; iCol++){
        i += fts5GetVarint(&buf.p[i], (u64*)&p->aTotalSize[iCol]);
      }
    }
    sqlite3_free(buf.p);
    p->bTotalsValid = bCache;
  }
  return rc;
}

/*
** Store the current contents of the p->nTotalRow and p->aTotalSize[] 
13908
13909
13910
13911
13912
13913
13914

13915
13916
13917
13918
13919
13920
13921
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113







+







    ctx.iCol = -1;

    rc = sqlite3Fts5IndexBeginWrite(p->pIndex, iDel);
    for(iCol=0; rc==SQLITE_OK && iCol<pConfig->nCol; iCol++){
      if( pConfig->abUnindexed[iCol] ) continue;
      ctx.szCol = 0;
      rc = sqlite3Fts5Tokenize(pConfig, 
        FTS5_TOKENIZE_DOCUMENT,
        (const char*)sqlite3_value_text(apVal[iCol]),
        sqlite3_value_bytes(apVal[iCol]),
        (void*)&ctx,
        fts5StorageInsertCallback
      );
      p->aTotalSize[iCol] -= (i64)ctx.szCol;
    }
13997
13998
13999
14000
14001
14002
14003

14004
14005
14006
14007
14008
14009
14010
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203







+








    sqlite3Fts5BufferZero(&buf);
    rc = sqlite3Fts5IndexBeginWrite(p->pIndex, iRowid);
    for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
      ctx.szCol = 0;
      if( pConfig->abUnindexed[ctx.iCol]==0 ){
        rc = sqlite3Fts5Tokenize(pConfig, 
            FTS5_TOKENIZE_DOCUMENT,
            (const char*)sqlite3_column_text(pScan, ctx.iCol+1),
            sqlite3_column_bytes(pScan, ctx.iCol+1),
            (void*)&ctx,
            fts5StorageInsertCallback
        );
      }
      sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol);
14114
14115
14116
14117
14118
14119
14120

14121
14122
14123
14124
14125
14126
14127
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321







+







    rc = sqlite3Fts5IndexBeginWrite(p->pIndex, *piRowid);
    ctx.pStorage = p;
  }
  for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
    ctx.szCol = 0;
    if( pConfig->abUnindexed[ctx.iCol]==0 ){
      rc = sqlite3Fts5Tokenize(pConfig, 
          FTS5_TOKENIZE_DOCUMENT,
          (const char*)sqlite3_value_text(apVal[ctx.iCol+2]),
          sqlite3_value_bytes(apVal[ctx.iCol+2]),
          (void*)&ctx,
          fts5StorageInsertCallback
      );
    }
    sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol);
14181
14182
14183
14184
14185
14186
14187

14188
14189
14190
14191
14192
14193

14194


14195
14196

14197
14198
14199
14200
14201
14202
14203
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389

14390
14391
14392

14393
14394
14395
14396
14397
14398
14399
14400







+






+
-
+
+

-
+







};

/*
** Tokenization callback used by integrity check.
*/
static int fts5StorageIntegrityCallback(
  void *pContext,                 /* Pointer to Fts5InsertCtx object */
  int tflags,
  const char *pToken,             /* Buffer containing token */
  int nToken,                     /* Size of token in bytes */
  int iStart,                     /* Start offset of token */
  int iEnd                        /* End offset of token */
){
  Fts5IntegrityCtx *pCtx = (Fts5IntegrityCtx*)pContext;
  if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
  int iPos = pCtx->szCol++;
    pCtx->szCol++;
  }
  pCtx->cksum ^= sqlite3Fts5IndexCksum(
      pCtx->pConfig, pCtx->iRowid, pCtx->iCol, iPos, pToken, nToken
      pCtx->pConfig, pCtx->iRowid, pCtx->iCol, pCtx->szCol-1, pToken, nToken
  );
  return SQLITE_OK;
}

/*
** Check that the contents of the FTS index match that of the %_content
** table. Return SQLITE_OK if they do, or SQLITE_CORRUPT if not. Return
14224
14225
14226
14227
14228
14229
14230

14231


14232
14233
14234
14235
14236
14237


14238
14239
14240
14241
14242

14243


14244
14245
14246
14247
14248
14249
14250
14421
14422
14423
14424
14425
14426
14427
14428

14429
14430
14431
14432
14433
14434


14435
14436
14437
14438
14439
14440
14441
14442

14443
14444
14445
14446
14447
14448
14449
14450
14451







+
-
+
+




-
-
+
+





+
-
+
+







  rc = fts5StorageGetStmt(p, FTS5_STMT_SCAN, &pScan, 0);
  if( rc==SQLITE_OK ){
    int rc2;
    while( SQLITE_ROW==sqlite3_step(pScan) ){
      int i;
      ctx.iRowid = sqlite3_column_int64(pScan, 0);
      ctx.szCol = 0;
      if( pConfig->bColumnsize ){
      rc = sqlite3Fts5StorageDocsize(p, ctx.iRowid, aColSize);
        rc = sqlite3Fts5StorageDocsize(p, ctx.iRowid, aColSize);
      }
      for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
        if( pConfig->abUnindexed[i] ) continue;
        ctx.iCol = i;
        ctx.szCol = 0;
        rc = sqlite3Fts5Tokenize(
            pConfig, 
        rc = sqlite3Fts5Tokenize(pConfig, 
            FTS5_TOKENIZE_DOCUMENT,
            (const char*)sqlite3_column_text(pScan, i+1),
            sqlite3_column_bytes(pScan, i+1),
            (void*)&ctx,
            fts5StorageIntegrityCallback
        );
        if( pConfig->bColumnsize && ctx.szCol!=aColSize[i] ){
        if( ctx.szCol!=aColSize[i] ) rc = FTS5_CORRUPT;
          rc = FTS5_CORRUPT;
        }
        aTotalSize[i] += ctx.szCol;
      }
      if( rc!=SQLITE_OK ) break;
    }
    rc2 = sqlite3_reset(pScan);
    if( rc==SQLITE_OK ) rc = rc2;
  }
14261
14262
14263
14264
14265
14266
14267
14268

14269
14270
14271
14272
14273
14274
14275
14462
14463
14464
14465
14466
14467
14468

14469
14470
14471
14472
14473
14474
14475
14476







-
+







  /* Check that the %_docsize and %_content tables contain the expected
  ** number of rows.  */
  if( rc==SQLITE_OK && pConfig->eContent==FTS5_CONTENT_NORMAL ){
    i64 nRow;
    rc = fts5StorageCount(p, "content", &nRow);
    if( rc==SQLITE_OK && nRow!=p->nTotalRow ) rc = FTS5_CORRUPT;
  }
  if( rc==SQLITE_OK ){
  if( rc==SQLITE_OK && pConfig->bColumnsize ){
    i64 nRow;
    rc = fts5StorageCount(p, "docsize", &nRow);
    if( rc==SQLITE_OK && nRow!=p->nTotalRow ) rc = FTS5_CORRUPT;
  }

  /* Pass the expected checksum down to the FTS index module. It will
  ** verify, amongst other things, that it matches the checksum generated by
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354






14355
14356
14357
14358
14359
14360
14361
14546
14547
14548
14549
14550
14551
14552



14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565







-
-
-
+
+
+
+
+
+







** each table column. This function reads the %_docsize record for the
** specified rowid and populates aCol[] with the results.
**
** An SQLite error code is returned if an error occurs, or SQLITE_OK
** otherwise.
*/
static int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol){
  int nCol = p->pConfig->nCol;
  sqlite3_stmt *pLookup = 0;
  int rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
  int nCol = p->pConfig->nCol;    /* Number of user columns in table */
  sqlite3_stmt *pLookup = 0;      /* Statement to query %_docsize */
  int rc;                         /* Return Code */

  assert( p->pConfig->bColumnsize );
  rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
  if( rc==SQLITE_OK ){
    int bCorrupt = 1;
    sqlite3_bind_int64(pLookup, 1, iRowid);
    if( SQLITE_ROW==sqlite3_step(pLookup) ){
      const u8 *aBlob = sqlite3_column_blob(pLookup, 0);
      int nBlob = sqlite3_column_bytes(pLookup, 0);
      if( 0==fts5StorageDecodeSizeArray(aCol, nCol, aBlob, nBlob) ){
14558
14559
14560
14561
14562
14563
14564

14565
14566

14567
14568
14569
14570
14571
14572
14573
14762
14763
14764
14765
14766
14767
14768
14769
14770

14771
14772
14773
14774
14775
14776
14777
14778







+

-
+








/*
** Tokenize some text using the ascii tokenizer.
*/
static int fts5AsciiTokenize(
  Fts5Tokenizer *pTokenizer,
  void *pCtx,
  int flags,
  const char *pText, int nText,
  int (*xToken)(void*, const char*, int nToken, int iStart, int iEnd)
  int (*xToken)(void*, int, const char*, int nToken, int iStart, int iEnd)
){
  AsciiTokenizer *p = (AsciiTokenizer*)pTokenizer;
  int rc = SQLITE_OK;
  int ie;
  int is = 0;

  char aFold[64];
14600
14601
14602
14603
14604
14605
14606
14607

14608
14609
14610
14611
14612
14613
14614
14805
14806
14807
14808
14809
14810
14811

14812
14813
14814
14815
14816
14817
14818
14819







-
+







        break;
      }
      nFold = nByte*2;
    }
    asciiFold(pFold, &pText[is], nByte);

    /* Invoke the token callback */
    rc = xToken(pCtx, pFold, nByte, is, ie);
    rc = xToken(pCtx, 0, pFold, nByte, is, ie);
    is = ie+1;
  }
  
  if( pFold!=aFold ) sqlite3_free(pFold);
  if( rc==SQLITE_DONE ) rc = SQLITE_OK;
  return rc;
}
14827
14828
14829
14830
14831
14832
14833

14834
14835

14836
14837
14838
14839
14840
14841
14842
15032
15033
15034
15035
15036
15037
15038
15039
15040

15041
15042
15043
15044
15045
15046
15047
15048







+

-
+







  assert( (sqlite3Fts5UnicodeIsalnum(iCode) & 0xFFFFFFFE)==0 );
  return sqlite3Fts5UnicodeIsalnum(iCode) ^ fts5UnicodeIsException(p, iCode);
}

static int fts5UnicodeTokenize(
  Fts5Tokenizer *pTokenizer,
  void *pCtx,
  int flags,
  const char *pText, int nText,
  int (*xToken)(void*, const char*, int nToken, int iStart, int iEnd)
  int (*xToken)(void*, int, const char*, int nToken, int iStart, int iEnd)
){
  Unicode61Tokenizer *p = (Unicode61Tokenizer*)pTokenizer;
  int rc = SQLITE_OK;
  unsigned char *a = p->aTokenChar;

  unsigned char *zTerm = (unsigned char*)&pText[nText];
  unsigned char *zCsr = (unsigned char *)pText;
14917
14918
14919
14920
14921
14922
14923
14924

14925
14926
14927
14928
14929
14930
14931
15123
15124
15125
15126
15127
15128
15129

15130
15131
15132
15133
15134
15135
15136
15137







-
+







        }
        zCsr++;
      }
      ie = zCsr - (unsigned char*)pText;
    }

    /* Invoke the token callback */
    rc = xToken(pCtx, aFold, zOut-aFold, is, ie);
    rc = xToken(pCtx, 0, aFold, zOut-aFold, is, ie); 
  }
  
 tokenize_done:
  if( rc==SQLITE_DONE ) rc = SQLITE_OK;
  return rc;
}

14995
14996
14997
14998
14999
15000
15001
15002

15003
15004
15005
15006
15007
15008
15009
15201
15202
15203
15204
15205
15206
15207

15208
15209
15210
15211
15212
15213
15214
15215







-
+







  *ppOut = (Fts5Tokenizer*)pRet;
  return rc;
}

typedef struct PorterContext PorterContext;
struct PorterContext {
  void *pCtx;
  int (*xToken)(void*, const char*, int, int, int);
  int (*xToken)(void*, int, const char*, int, int, int);
  char *aBuf;
};

typedef struct PorterRule PorterRule;
struct PorterRule {
  const char *zSuffix;
  int nSuffix;
15560
15561
15562
15563
15564
15565
15566

15567
15568
15569
15570
15571
15572
15573
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780







+







      *pnBuf = nBuf-1;
    }
  }
}

static int fts5PorterCb(
  void *pCtx, 
  int tflags,
  const char *pToken, 
  int nToken, 
  int iStart, 
  int iEnd
){
  PorterContext *p = (PorterContext*)pCtx;

15617
15618
15619
15620
15621
15622
15623
15624

15625
15626
15627

15628
15629
15630
15631
15632
15633
15634
15635

15636
15637

15638
15639
15640
15641
15642
15643
15644
15645

15646
15647
15648
15649
15650
15651
15652
15824
15825
15826
15827
15828
15829
15830

15831
15832
15833

15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844

15845
15846
15847
15848
15849
15850
15851
15852

15853
15854
15855
15856
15857
15858
15859
15860







-
+


-
+








+

-
+







-
+







  /* Step 5b. */
  if( nBuf>1 && aBuf[nBuf-1]=='l' 
   && aBuf[nBuf-2]=='l' && fts5Porter_MGt1(aBuf, nBuf-1) 
  ){
    nBuf--;
  }

  return p->xToken(p->pCtx, aBuf, nBuf, iStart, iEnd);
  return p->xToken(p->pCtx, tflags, aBuf, nBuf, iStart, iEnd);

 pass_through:
  return p->xToken(p->pCtx, pToken, nToken, iStart, iEnd);
  return p->xToken(p->pCtx, tflags, pToken, nToken, iStart, iEnd);
}

/*
** Tokenize using the porter tokenizer.
*/
static int fts5PorterTokenize(
  Fts5Tokenizer *pTokenizer,
  void *pCtx,
  int flags,
  const char *pText, int nText,
  int (*xToken)(void*, const char*, int nToken, int iStart, int iEnd)
  int (*xToken)(void*, int, const char*, int nToken, int iStart, int iEnd)
){
  PorterTokenizer *p = (PorterTokenizer*)pTokenizer;
  PorterContext sCtx;
  sCtx.xToken = xToken;
  sCtx.pCtx = pCtx;
  sCtx.aBuf = p->aBuf;
  return p->tokenizer.xTokenize(
      p->pTokenizer, (void*)&sCtx, pText, nText, fts5PorterCb
      p->pTokenizer, (void*)&sCtx, flags, pText, nText, fts5PorterCb
  );
}

/*
** Register all built-in tokenizers with FTS5.
*/
static int sqlite3Fts5TokenizerInit(fts5_api *pApi){
15667
15668
15669
15670
15671
15672
15673
15674

15675
15676
15677
15678
15679
15680
15681
15875
15876
15877
15878
15879
15880
15881

15882
15883
15884
15885
15886
15887
15888
15889







-
+







        aBuiltin[i].zName,
        (void*)pApi,
        &aBuiltin[i].x,
        0
    );
  }

  return SQLITE_OK;
  return rc;
}



#line 2 "fts5_unicode2.c"
/*
** 2012 May 25
16938
16939
16940
16941
16942
16943
16944


16945
16946
16947
16948







16949
16950
16951
16952
16953
16954
16955
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156


17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170







+
+


-
-
+
+
+
+
+
+
+







**                       for base tokens is called "fts5yy0".
**    fts5YYSTACKDEPTH       is the maximum depth of the parser's stack.  If
**                       zero the stack is dynamically sized using realloc()
**    sqlite3Fts5ParserARG_SDECL     A static variable declaration for the %extra_argument
**    sqlite3Fts5ParserARG_PDECL     A parameter declaration for the %extra_argument
**    sqlite3Fts5ParserARG_STORE     Code to store %extra_argument into fts5yypParser
**    sqlite3Fts5ParserARG_FETCH     Code to extract %extra_argument from fts5yypParser
**    fts5YYERRORSYMBOL      is the code number of the error symbol.  If not
**                       defined, then do no error processing.
**    fts5YYNSTATE           the combined number of states.
**    fts5YYNRULE            the number of rules in the grammar
**    fts5YYERRORSYMBOL      is the code number of the error symbol.  If not
**                       defined, then do no error processing.
**    fts5YY_MAX_SHIFT       Maximum value for shift actions
**    fts5YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
**    fts5YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
**    fts5YY_MIN_REDUCE      Maximum value for reduce actions
**    fts5YY_ERROR_ACTION    The fts5yy_action[] code for syntax error
**    fts5YY_ACCEPT_ACTION   The fts5yy_action[] code for accept
**    fts5YY_NO_ACTION       The fts5yy_action[] code for no-op
*/
#define fts5YYCODETYPE unsigned char
#define fts5YYNOCODE 27
#define fts5YYACTIONTYPE unsigned char
#define sqlite3Fts5ParserFTS5TOKENTYPE Fts5Token
typedef union {
  int fts5yyinit;
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974










16975
16976
16977
16978
16979
16980
16981
17178
17179
17180
17181
17182
17183
17184





17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201







-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







#ifndef fts5YYSTACKDEPTH
#define fts5YYSTACKDEPTH 100
#endif
#define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
#define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
#define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
#define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
#define fts5YYNSTATE 40
#define fts5YYNRULE 24
#define fts5YY_NO_ACTION      (fts5YYNSTATE+fts5YYNRULE+2)
#define fts5YY_ACCEPT_ACTION  (fts5YYNSTATE+fts5YYNRULE+1)
#define fts5YY_ERROR_ACTION   (fts5YYNSTATE+fts5YYNRULE)
#define fts5YYNSTATE             26
#define fts5YYNRULE              24
#define fts5YY_MAX_SHIFT         25
#define fts5YY_MIN_SHIFTREDUCE   40
#define fts5YY_MAX_SHIFTREDUCE   63
#define fts5YY_MIN_REDUCE        64
#define fts5YY_MAX_REDUCE        87
#define fts5YY_ERROR_ACTION      88
#define fts5YY_ACCEPT_ACTION     89
#define fts5YY_NO_ACTION         90

/* The fts5yyzerominor constant is used to initialize instances of
** fts5YYMINORTYPE objects to zero. */
static const fts5YYMINORTYPE fts5yyzerominor = { 0 };

/* Define the fts5yytestcase() macro to be a no-op if is not already defined
** otherwise.
16994
16995
16996
16997
16998
16999
17000
17001

17002
17003

17004

17005



17006

17007
17008

17009
17010

17011
17012
17013
17014
17015
17016
17017
17214
17215
17216
17217
17218
17219
17220

17221
17222
17223
17224

17225
17226
17227
17228
17229

17230
17231

17232
17233

17234
17235
17236
17237
17238
17239
17240
17241







-
+


+
-
+

+
+
+
-
+

-
+

-
+







** current state and lookahead token.  These tables are used to implement
** functions that take a state number and lookahead value and return an
** action integer.  
**
** Suppose the action integer is N.  Then the action is determined as
** follows
**
**   0 <= N < fts5YYNSTATE                  Shift N.  That is, push the lookahead
**   0 <= N <= fts5YY_MAX_SHIFT             Shift N.  That is, push the lookahead
**                                      token onto the stack and goto state N.
**
**   N between fts5YY_MIN_SHIFTREDUCE       Shift to an arbitrary state then
**   fts5YYNSTATE <= N < fts5YYNSTATE+fts5YYNRULE   Reduce by rule N-fts5YYNSTATE.
**     and fts5YY_MAX_SHIFTREDUCE           reduce by rule N-fts5YY_MIN_SHIFTREDUCE.
**
**   N between fts5YY_MIN_REDUCE            Reduce by rule N-fts5YY_MIN_REDUCE
**     and fts5YY_MAX_REDUCE

**   N == fts5YYNSTATE+fts5YYNRULE              A syntax error has occurred.
**   N == fts5YY_ERROR_ACTION               A syntax error has occurred.
**
**   N == fts5YYNSTATE+fts5YYNRULE+1            The parser accepts its input.
**   N == fts5YY_ACCEPT_ACTION              The parser accepts its input.
**
**   N == fts5YYNSTATE+fts5YYNRULE+2            No such action.  Denotes unused
**   N == fts5YY_NO_ACTION                  No such action.  Denotes unused
**                                      slots in the fts5yy_action[] table.
**
** The action table is constructed as a single large table named fts5yy_action[].
** Given state S and lookahead X, the action is computed as
**
**      fts5yy_action[ fts5yy_shift_ofst[S] + X ]
**
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049








17050
17051
17052
17053


17054
17055
17056
17057
17058
17059





17060
17061

17062
17063
17064


17065
17066
17067
17068



17069
17070
17071
17072
17073

17074
17075
17076


17077
17078
17079
17080
17081



17082
17083
17084
17085
17086
17087
17088
17089
17259
17260
17261
17262
17263
17264
17265








17266
17267
17268
17269
17270
17271
17272
17273
17274
17275


17276
17277
17278





17279
17280
17281
17282
17283
17284

17285
17286


17287
17288
17289



17290
17291
17292
17293
17294
17295
17296

17297
17298


17299
17300
17301
17302



17303
17304
17305

17306
17307
17308
17309
17310
17311
17312







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+


-
-
+
+

-
-
-
-
-
+
+
+
+
+

-
+

-
-
+
+

-
-
-
+
+
+




-
+

-
-
+
+


-
-
-
+
+
+
-







**                     shifting terminals.
**  fts5yy_reduce_ofst[]   For each state, the offset into fts5yy_action for
**                     shifting non-terminals after a reduce.
**  fts5yy_default[]       Default action for each state.
*/
#define fts5YY_ACTTAB_COUNT (78)
static const fts5YYACTIONTYPE fts5yy_action[] = {
 /*     0 */    65,   15,   26,    5,   36,   24,    4,    2,   23,   25,
 /*    10 */    26,    5,   36,   24,   29,   28,   23,   17,   26,    5,
 /*    20 */    36,   24,    6,   18,   23,   39,   26,    5,   36,   24,
 /*    30 */    51,    7,   23,   14,   26,    5,   36,   24,   33,    2,
 /*    40 */    23,   40,    3,    4,    2,    3,    4,    2,    7,   22,
 /*    50 */    37,   38,   36,   24,   35,   33,   23,    1,   23,   11,
 /*    60 */     8,    9,   20,   21,   12,   19,   11,   13,    9,   32,
 /*    70 */    31,   34,   33,   30,   16,   27,   10,   12,
 /*     0 */    89,   15,   46,    5,   48,   24,   12,   19,   23,   14,
 /*    10 */    46,    5,   48,   24,   20,   21,   23,   43,   46,    5,
 /*    20 */    48,   24,    6,   18,   23,   17,   46,    5,   48,   24,
 /*    30 */    75,    7,   23,   25,   46,    5,   48,   24,   62,   47,
 /*    40 */    23,   48,   24,    7,   11,   23,    9,    3,    4,    2,
 /*    50 */    62,   50,   52,   44,   64,    3,    4,    2,   49,    4,
 /*    60 */     2,    1,   23,   11,   16,    9,   12,    2,   10,   61,
 /*    70 */    53,   59,   62,   60,   22,   13,   55,    8,
};
static const fts5YYCODETYPE fts5yy_lookahead[] = {
 /*     0 */    15,   16,   17,   18,   19,   20,    2,    3,   23,   16,
 /*    10 */    17,   18,   19,   20,    9,   10,   23,   16,   17,   18,
 /*     0 */    15,   16,   17,   18,   19,   20,   10,   11,   23,   16,
 /*    10 */    17,   18,   19,   20,   23,   24,   23,   16,   17,   18,
 /*    20 */    19,   20,   22,   23,   23,   16,   17,   18,   19,   20,
 /*    30 */     5,    6,   23,   16,   17,   18,   19,   20,   13,    3,
 /*    40 */    23,    0,    1,    2,    3,    1,    2,    3,    6,   12,
 /*    50 */    17,    7,   19,   20,   19,   13,   23,    6,   23,    8,
 /*    60 */     5,   10,   23,   24,   10,   11,    8,   10,   10,    7,
 /*    70 */    10,   25,   13,   25,   21,   10,   10,   10,
 /*    30 */     5,    6,   23,   16,   17,   18,   19,   20,   13,   17,
 /*    40 */    23,   19,   20,    6,    8,   23,   10,    1,    2,    3,
 /*    50 */    13,    9,   10,    7,    0,    1,    2,    3,   19,    2,
 /*    60 */     3,    6,   23,    8,   21,   10,   10,    3,   10,   25,
 /*    70 */    10,   10,   13,   25,   12,   10,    7,    5,
};
#define fts5YY_SHIFT_USE_DFLT (-1)
#define fts5YY_SHIFT_USE_DFLT (-5)
#define fts5YY_SHIFT_COUNT (25)
#define fts5YY_SHIFT_MIN   (0)
#define fts5YY_SHIFT_MAX   (67)
#define fts5YY_SHIFT_MIN   (-4)
#define fts5YY_SHIFT_MAX   (72)
static const signed char fts5yy_shift_ofst[] = {
 /*     0 */    51,   51,   51,   51,   51,   58,   54,   67,   66,   25,
 /*    10 */    42,   65,   59,   59,   44,   41,    5,    4,   37,   60,
 /*    20 */    37,   62,   57,   37,   55,   36,
 /*     0 */    55,   55,   55,   55,   55,   36,   -4,   56,   58,   25,
 /*    10 */    37,   60,   59,   59,   46,   54,   42,   57,   62,   61,
 /*    20 */    62,   69,   65,   62,   72,   64,
};
#define fts5YY_REDUCE_USE_DFLT (-16)
#define fts5YY_REDUCE_COUNT (13)
#define fts5YY_REDUCE_MIN   (-15)
#define fts5YY_REDUCE_MAX   (53)
#define fts5YY_REDUCE_MAX   (48)
static const signed char fts5yy_reduce_ofst[] = {
 /*     0 */   -15,   17,    9,    1,   -7,   33,   39,    0,   35,   48,
 /*    10 */    48,   53,   48,   46,
 /*     0 */   -15,   -7,    1,    9,   17,   22,   -9,    0,   39,   44,
 /*    10 */    44,   43,   44,   48,
};
static const fts5YYACTIONTYPE fts5yy_default[] = {
 /*     0 */    64,   64,   64,   64,   64,   45,   58,   64,   64,   63,
 /*    10 */    63,   64,   63,   63,   64,   64,   64,   42,   56,   64,
 /*    20 */    57,   64,   64,   54,   64,   41,   46,   53,   52,   50,
 /*     0 */    88,   88,   88,   88,   88,   69,   82,   88,   88,   87,
 /*    10 */    87,   88,   87,   87,   88,   88,   88,   66,   80,   88,
 /*    20 */    81,   88,   88,   78,   88,   65,
 /*    30 */    61,   59,   55,   62,   60,   49,   48,   47,   44,   43,
};

/* The next table maps tokens into fallback tokens.  If a construct
** like the following:
** 
**      %fallback ID X Y Z.
**
17104
17105
17106
17107
17108
17109
17110




17111
17112
17113

17114
17115
17116
17117
17118
17119
17120
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339

17340
17341
17342
17343
17344
17345
17346
17347







+
+
+
+


-
+







**
**   +  The value of the token stored at this level of the stack.
**      (In other words, the "major" token.)
**
**   +  The semantic value stored at this level of the stack.  This is
**      the information used by the action routines in the grammar.
**      It is sometimes called the "minor" token.
**
** After the "shift" half of a SHIFTREDUCE action, the stateno field
** actually contains the reduce action for the second half of the
** SHIFTREDUCE.
*/
struct fts5yyStackEntry {
  fts5YYACTIONTYPE stateno;  /* The state-number */
  fts5YYACTIONTYPE stateno;  /* The state-number, or reduce action in SHIFTREDUCE */
  fts5YYCODETYPE major;      /* The major token value.  This is the code
                         ** number for the token at this stack level */
  fts5YYMINORTYPE minor;     /* The user-supplied minor token value.  This
                         ** is the value of the token  */
};
typedef struct fts5yyStackEntry fts5yyStackEntry;

17290
17291
17292
17293
17294
17295
17296
17297

17298
17299
17300
17301
17302
17303
17304
17305

17306
17307
17308
17309
17310
17311
17312
17313

17314
17315
17316
17317
17318
17319
17320

17321
17322
17323
17324
17325
17326
17327
17517
17518
17519
17520
17521
17522
17523

17524
17525
17526
17527
17528
17529
17530
17531

17532
17533
17534
17535
17536
17537
17538
17539

17540
17541
17542
17543
17544
17545
17546

17547
17548
17549
17550
17551
17552
17553
17554







-
+







-
+







-
+






-
+







    */
    case 16: /* expr */
    case 17: /* cnearset */
    case 18: /* exprlist */
{
#line 75 "fts5parse.y"
 sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy18)); 
#line 427 "fts5parse.c"
#line 446 "fts5parse.c"
}
      break;
    case 19: /* nearset */
    case 22: /* nearphrases */
{
#line 123 "fts5parse.y"
 sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy26)); 
#line 435 "fts5parse.c"
#line 454 "fts5parse.c"
}
      break;
    case 20: /* colset */
    case 21: /* colsetlist */
{
#line 105 "fts5parse.y"
 sqlite3_free((fts5yypminor->fts5yy38)); 
#line 443 "fts5parse.c"
#line 462 "fts5parse.c"
}
      break;
    case 23: /* phrase */
{
#line 154 "fts5parse.y"
 sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy11)); 
#line 450 "fts5parse.c"
#line 469 "fts5parse.c"
}
      break;
    default:  break;   /* If no destructor action specified: do nothing */
  }
}

/*
17400
17401
17402
17403
17404
17405
17406

17407
17408
17409



17410
17411
17412
17413
17414
17415
17416
17417
17627
17628
17629
17630
17631
17632
17633
17634



17635
17636
17637

17638
17639
17640
17641
17642
17643
17644







+
-
-
-
+
+
+
-







static int fts5yy_find_shift_action(
  fts5yyParser *pParser,        /* The parser */
  fts5YYCODETYPE iLookAhead     /* The look-ahead token */
){
  int i;
  int stateno = pParser->fts5yystack[pParser->fts5yyidx].stateno;
 
  if( stateno>=fts5YY_MIN_REDUCE ) return stateno;
  if( stateno>fts5YY_SHIFT_COUNT
   || (i = fts5yy_shift_ofst[stateno])==fts5YY_SHIFT_USE_DFLT ){
    return fts5yy_default[stateno];
  assert( stateno <= fts5YY_SHIFT_COUNT );
  i = fts5yy_shift_ofst[stateno];
  if( i==fts5YY_SHIFT_USE_DFLT ) return fts5yy_default[stateno];
  }
  assert( iLookAhead!=fts5YYNOCODE );
  i += iLookAhead;
  if( i<0 || i>=fts5YY_ACTTAB_COUNT || fts5yy_lookahead[i]!=iLookAhead ){
    if( iLookAhead>0 ){
#ifdef fts5YYFALLBACK
      fts5YYCODETYPE iFallback;            /* Fallback token */
      if( iLookAhead<sizeof(fts5yyFallback)/sizeof(fts5yyFallback[0])
17502
17503
17504
17505
17506
17507
17508
17509

17510
17511
17512
17513






















17514

17515
17516
17517
17518
17519
17520
17521
17729
17730
17731
17732
17733
17734
17735

17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762

17763
17764
17765
17766
17767
17768
17769
17770







-
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+







#endif
   while( fts5yypParser->fts5yyidx>=0 ) fts5yy_pop_parser_stack(fts5yypParser);
   /* Here code is inserted which will execute if the parser
   ** stack every overflows */
#line 35 "fts5parse.y"

  assert( 0 );
#line 639 "fts5parse.c"
#line 658 "fts5parse.c"
   sqlite3Fts5ParserARG_STORE; /* Suppress warning about unused %extra_argument var */
}

/*
** Print tracing information for a SHIFT action
*/
#ifndef NDEBUG
static void fts5yyTraceShift(fts5yyParser *fts5yypParser, int fts5yyNewState){
  if( fts5yyTraceFILE ){
    int i;
    if( fts5yyNewState<fts5YYNSTATE ){
      fprintf(fts5yyTraceFILE,"%sShift %d\n",fts5yyTracePrompt,fts5yyNewState);
      fprintf(fts5yyTraceFILE,"%sStack:",fts5yyTracePrompt);
      for(i=1; i<=fts5yypParser->fts5yyidx; i++)
        fprintf(fts5yyTraceFILE," %s",fts5yyTokenName[fts5yypParser->fts5yystack[i].major]);
      fprintf(fts5yyTraceFILE,"\n");
    }else{
      fprintf(fts5yyTraceFILE,"%sShift *\n",fts5yyTracePrompt);
    }
  }
}
#else
# define fts5yyTraceShift(X,Y)
#endif

/*
** Perform a shift action.
** Perform a shift action.  Return the number of errors.
*/
static void fts5yy_shift(
  fts5yyParser *fts5yypParser,          /* The parser to be shifted */
  int fts5yyNewState,               /* The new state to shift in */
  int fts5yyMajor,                  /* The major token to shift in */
  fts5YYMINORTYPE *fts5yypMinor         /* Pointer to the minor token to shift in */
){
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554

17555
17556
17557
17558
17559
17560
17561
17562
17563
17789
17790
17791
17792
17793
17794
17795








17796


17797
17798
17799
17800
17801
17802
17803







-
-
-
-
-
-
-
-
+
-
-







    }
  }
#endif
  fts5yytos = &fts5yypParser->fts5yystack[fts5yypParser->fts5yyidx];
  fts5yytos->stateno = (fts5YYACTIONTYPE)fts5yyNewState;
  fts5yytos->major = (fts5YYCODETYPE)fts5yyMajor;
  fts5yytos->minor = *fts5yypMinor;
#ifndef NDEBUG
  if( fts5yyTraceFILE && fts5yypParser->fts5yyidx>0 ){
    int i;
    fprintf(fts5yyTraceFILE,"%sShift %d\n",fts5yyTracePrompt,fts5yyNewState);
    fprintf(fts5yyTraceFILE,"%sStack:",fts5yyTracePrompt);
    for(i=1; i<=fts5yypParser->fts5yyidx; i++)
      fprintf(fts5yyTraceFILE," %s",fts5yyTokenName[fts5yypParser->fts5yystack[i].major]);
    fprintf(fts5yyTraceFILE,"\n");
  fts5yyTraceShift(fts5yypParser, fts5yyNewState);
  }
#endif
}

/* The following table contains information about every rule that
** is used during the reduce.
*/
static const struct {
  fts5YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
17605
17606
17607
17608
17609
17610
17611

17612
17613


17614
17615
17616
17617
17618
17619
17620
17845
17846
17847
17848
17849
17850
17851
17852


17853
17854
17855
17856
17857
17858
17859
17860
17861







+
-
-
+
+







  fts5yyStackEntry *fts5yymsp;            /* The top of the parser's stack */
  int fts5yysize;                     /* Amount to pop the stack */
  sqlite3Fts5ParserARG_FETCH;
  fts5yymsp = &fts5yypParser->fts5yystack[fts5yypParser->fts5yyidx];
#ifndef NDEBUG
  if( fts5yyTraceFILE && fts5yyruleno>=0 
        && fts5yyruleno<(int)(sizeof(fts5yyRuleName)/sizeof(fts5yyRuleName[0])) ){
    fts5yysize = fts5yyRuleInfo[fts5yyruleno].nrhs;
    fprintf(fts5yyTraceFILE, "%sReduce [%s].\n", fts5yyTracePrompt,
      fts5yyRuleName[fts5yyruleno]);
    fprintf(fts5yyTraceFILE, "%sReduce [%s] -> state %d.\n", fts5yyTracePrompt,
      fts5yyRuleName[fts5yyruleno], fts5yymsp[-fts5yysize].stateno);
  }
#endif /* NDEBUG */

  /* Silence complaints from purify about fts5yygotominor being uninitialized
  ** in some cases when it is copied into the stack after the following
  ** switch.  fts5yygotominor is uninitialized when a rule reduces that does
  ** not set the value of its left-hand side nonterminal.  Leaving the
17640
17641
17642
17643
17644
17645
17646
17647

17648
17649
17650
17651
17652
17653
17654

17655
17656
17657
17658
17659
17660
17661

17662
17663
17664
17665
17666
17667
17668

17669
17670
17671
17672
17673

17674
17675
17676
17677
17678
17679

17680
17681
17682
17683
17684
17685
17686

17687
17688
17689
17690
17691
17692
17693

17694
17695
17696
17697
17698
17699
17700
17701

17702
17703
17704
17705
17706

17707
17708
17709
17710
17711
17712
17713

17714
17715
17716
17717
17718
17719

17720
17721
17722
17723
17724
17725
17726

17727
17728
17729
17730
17731

17732
17733
17734
17735
17736
17737
17738
17739
17740

17741
17742
17743
17744
17745
17746
17747

17748
17749
17750
17751
17752
17753
17754

17755
17756
17757
17758
17759

17760
17761
17762
17763
17764

17765
17766
17767
17768
17769
17770
17771

17772
17773
17774
17775
17776
17777
17778

17779
17780
17781
17782
17783

17784
17785
17786
17787
17788

17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800



17801
17802
17803
17804
17805
17806
17807
17808
17809

17810

17811
17812
17813
17814
17815
17816

17817
17818
17819
17820
17821
17822
17823
17881
17882
17883
17884
17885
17886
17887

17888
17889
17890
17891
17892
17893
17894

17895
17896
17897
17898
17899
17900
17901

17902
17903
17904
17905
17906
17907
17908

17909
17910
17911
17912
17913

17914
17915
17916
17917
17918
17919

17920
17921
17922
17923
17924
17925
17926

17927
17928
17929
17930
17931
17932
17933

17934
17935
17936
17937
17938
17939
17940
17941

17942
17943
17944
17945
17946

17947
17948
17949
17950
17951
17952
17953

17954
17955
17956
17957
17958
17959

17960
17961
17962
17963
17964
17965
17966

17967
17968
17969
17970
17971

17972
17973
17974
17975
17976
17977
17978
17979
17980

17981
17982
17983
17984
17985
17986
17987

17988
17989
17990
17991
17992
17993
17994

17995
17996
17997
17998
17999

18000
18001
18002
18003
18004

18005
18006
18007
18008
18009
18010
18011

18012
18013
18014
18015
18016
18017
18018

18019
18020
18021
18022
18023

18024
18025
18026
18027
18028

18029
18030
18031
18032
18033
18034
18035
18036
18037
18038



18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051

18052


18053
18054
18055

18056
18057
18058
18059
18060
18061
18062
18063







-
+






-
+






-
+






-
+




-
+





-
+






-
+






-
+







-
+




-
+






-
+





-
+






-
+




-
+








-
+






-
+






-
+




-
+




-
+






-
+






-
+




-
+




-
+









-
-
-
+
+
+









+
-
+
-
-



-
+







  **     { ... }           // User supplied code
  **  #line <lineno> <thisfile>
  **     break;
  */
      case 0: /* input ::= expr */
#line 69 "fts5parse.y"
{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy18); }
#line 777 "fts5parse.c"
#line 810 "fts5parse.c"
        break;
      case 1: /* expr ::= expr AND expr */
#line 78 "fts5parse.y"
{
  fts5yygotominor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
}
#line 784 "fts5parse.c"
#line 817 "fts5parse.c"
        break;
      case 2: /* expr ::= expr OR expr */
#line 81 "fts5parse.y"
{
  fts5yygotominor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
}
#line 791 "fts5parse.c"
#line 824 "fts5parse.c"
        break;
      case 3: /* expr ::= expr NOT expr */
#line 84 "fts5parse.y"
{
  fts5yygotominor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
}
#line 798 "fts5parse.c"
#line 831 "fts5parse.c"
        break;
      case 4: /* expr ::= LP expr RP */
#line 88 "fts5parse.y"
{fts5yygotominor.fts5yy18 = fts5yymsp[-1].minor.fts5yy18;}
#line 803 "fts5parse.c"
#line 836 "fts5parse.c"
        break;
      case 5: /* expr ::= exprlist */
      case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
#line 89 "fts5parse.y"
{fts5yygotominor.fts5yy18 = fts5yymsp[0].minor.fts5yy18;}
#line 809 "fts5parse.c"
#line 842 "fts5parse.c"
        break;
      case 7: /* exprlist ::= exprlist cnearset */
#line 92 "fts5parse.y"
{
  fts5yygotominor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-1].minor.fts5yy18, fts5yymsp[0].minor.fts5yy18, 0);
}
#line 816 "fts5parse.c"
#line 849 "fts5parse.c"
        break;
      case 8: /* cnearset ::= nearset */
#line 96 "fts5parse.y"
{ 
  fts5yygotominor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy26); 
}
#line 823 "fts5parse.c"
#line 856 "fts5parse.c"
        break;
      case 9: /* cnearset ::= colset COLON nearset */
#line 99 "fts5parse.y"
{ 
  sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy26, fts5yymsp[-2].minor.fts5yy38);
  fts5yygotominor.fts5yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy26); 
}
#line 831 "fts5parse.c"
#line 864 "fts5parse.c"
        break;
      case 10: /* colset ::= LCP colsetlist RCP */
#line 109 "fts5parse.y"
{ fts5yygotominor.fts5yy38 = fts5yymsp[-1].minor.fts5yy38; }
#line 836 "fts5parse.c"
#line 869 "fts5parse.c"
        break;
      case 11: /* colset ::= STRING */
#line 110 "fts5parse.y"
{
  fts5yygotominor.fts5yy38 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
}
#line 843 "fts5parse.c"
#line 876 "fts5parse.c"
        break;
      case 12: /* colsetlist ::= colsetlist STRING */
#line 114 "fts5parse.y"
{ 
  fts5yygotominor.fts5yy38 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy38, &fts5yymsp[0].minor.fts5yy0); }
#line 849 "fts5parse.c"
#line 882 "fts5parse.c"
        break;
      case 13: /* colsetlist ::= STRING */
#line 116 "fts5parse.y"
{ 
  fts5yygotominor.fts5yy38 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0); 
}
#line 856 "fts5parse.c"
#line 889 "fts5parse.c"
        break;
      case 14: /* nearset ::= phrase */
#line 126 "fts5parse.y"
{ fts5yygotominor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11); }
#line 861 "fts5parse.c"
#line 894 "fts5parse.c"
        break;
      case 15: /* nearset ::= STRING LP nearphrases neardist_opt RP */
#line 127 "fts5parse.y"
{
  sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
  sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy26, &fts5yymsp[-1].minor.fts5yy0);
  fts5yygotominor.fts5yy26 = fts5yymsp[-2].minor.fts5yy26;
}
#line 870 "fts5parse.c"
#line 903 "fts5parse.c"
        break;
      case 16: /* nearphrases ::= phrase */
#line 133 "fts5parse.y"
{ 
  fts5yygotominor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy11); 
}
#line 877 "fts5parse.c"
#line 910 "fts5parse.c"
        break;
      case 17: /* nearphrases ::= nearphrases phrase */
#line 136 "fts5parse.y"
{
  fts5yygotominor.fts5yy26 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy26, fts5yymsp[0].minor.fts5yy11);
}
#line 884 "fts5parse.c"
#line 917 "fts5parse.c"
        break;
      case 18: /* neardist_opt ::= */
#line 143 "fts5parse.y"
{ fts5yygotominor.fts5yy0.p = 0; fts5yygotominor.fts5yy0.n = 0; }
#line 889 "fts5parse.c"
#line 922 "fts5parse.c"
        break;
      case 19: /* neardist_opt ::= COMMA STRING */
#line 144 "fts5parse.y"
{ fts5yygotominor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
#line 894 "fts5parse.c"
#line 927 "fts5parse.c"
        break;
      case 20: /* phrase ::= phrase PLUS STRING star_opt */
#line 156 "fts5parse.y"
{ 
  fts5yygotominor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy11, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy20);
}
#line 901 "fts5parse.c"
#line 934 "fts5parse.c"
        break;
      case 21: /* phrase ::= STRING star_opt */
#line 159 "fts5parse.y"
{ 
  fts5yygotominor.fts5yy11 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy20);
}
#line 908 "fts5parse.c"
#line 941 "fts5parse.c"
        break;
      case 22: /* star_opt ::= STAR */
#line 168 "fts5parse.y"
{ fts5yygotominor.fts5yy20 = 1; }
#line 913 "fts5parse.c"
#line 946 "fts5parse.c"
        break;
      case 23: /* star_opt ::= */
#line 169 "fts5parse.y"
{ fts5yygotominor.fts5yy20 = 0; }
#line 918 "fts5parse.c"
#line 951 "fts5parse.c"
        break;
      default:
        break;
  };
  assert( fts5yyruleno>=0 && fts5yyruleno<sizeof(fts5yyRuleInfo)/sizeof(fts5yyRuleInfo[0]) );
  fts5yygoto = fts5yyRuleInfo[fts5yyruleno].lhs;
  fts5yysize = fts5yyRuleInfo[fts5yyruleno].nrhs;
  fts5yypParser->fts5yyidx -= fts5yysize;
  fts5yyact = fts5yy_find_reduce_action(fts5yymsp[-fts5yysize].stateno,(fts5YYCODETYPE)fts5yygoto);
  if( fts5yyact < fts5YYNSTATE ){
#ifdef NDEBUG
    /* If we are not debugging and the reduce action popped at least
  if( fts5yyact <= fts5YY_MAX_SHIFTREDUCE ){
    if( fts5yyact>fts5YY_MAX_SHIFT ) fts5yyact += fts5YY_MIN_REDUCE - fts5YY_MIN_SHIFTREDUCE;
    /* If the reduce action popped at least
    ** one element off the stack, then we can push the new element back
    ** onto the stack here, and skip the stack overflow test in fts5yy_shift().
    ** That gives a significant speed improvement. */
    if( fts5yysize ){
      fts5yypParser->fts5yyidx++;
      fts5yymsp -= fts5yysize-1;
      fts5yymsp->stateno = (fts5YYACTIONTYPE)fts5yyact;
      fts5yymsp->major = (fts5YYCODETYPE)fts5yygoto;
      fts5yymsp->minor = fts5yygotominor;
      fts5yyTraceShift(fts5yypParser, fts5yyact);
    }else
    }else{
#endif
    {
      fts5yy_shift(fts5yypParser,fts5yyact,fts5yygoto,&fts5yygotominor);
    }
  }else{
    assert( fts5yyact == fts5YYNSTATE + fts5YYNRULE + 1 );
    assert( fts5yyact == fts5YY_ACCEPT_ACTION );
    fts5yy_accept(fts5yypParser);
  }
}

/*
** The following code executes when the parse fails
*/
17849
17850
17851
17852
17853
17854
17855
17856

17857
17858
17859
17860
17861
17862
17863
18089
18090
18091
18092
18093
18094
18095

18096
18097
18098
18099
18100
18101
18102
18103







-
+







  sqlite3Fts5ParserARG_FETCH;
#define FTS5TOKEN (fts5yyminor.fts5yy0)
#line 30 "fts5parse.y"

  sqlite3Fts5ParseError(
    pParse, "fts5: syntax error near \"%.*s\"",FTS5TOKEN.n,FTS5TOKEN.p
  );
#line 986 "fts5parse.c"
#line 1018 "fts5parse.c"
  sqlite3Fts5ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
}

/*
** The following is executed when the parser accepts
*/
static void fts5yy_accept(
17936
17937
17938
17939
17940
17941
17942
17943


17944
17945
17946
17947
17948


17949
17950
17951
17952
17953
17954
17955
18176
18177
18178
18179
18180
18181
18182

18183
18184
18185
18186
18187


18188
18189
18190
18191
18192
18193
18194
18195
18196







-
+
+



-
-
+
+







  if( fts5yyTraceFILE ){
    fprintf(fts5yyTraceFILE,"%sInput %s\n",fts5yyTracePrompt,fts5yyTokenName[fts5yymajor]);
  }
#endif

  do{
    fts5yyact = fts5yy_find_shift_action(fts5yypParser,(fts5YYCODETYPE)fts5yymajor);
    if( fts5yyact<fts5YYNSTATE ){
    if( fts5yyact <= fts5YY_MAX_SHIFTREDUCE ){
      if( fts5yyact > fts5YY_MAX_SHIFT ) fts5yyact += fts5YY_MIN_REDUCE - fts5YY_MIN_SHIFTREDUCE;
      fts5yy_shift(fts5yypParser,fts5yyact,fts5yymajor,&fts5yyminorunion);
      fts5yypParser->fts5yyerrcnt--;
      fts5yymajor = fts5YYNOCODE;
    }else if( fts5yyact < fts5YYNSTATE + fts5YYNRULE ){
      fts5yy_reduce(fts5yypParser,fts5yyact-fts5YYNSTATE);
    }else if( fts5yyact <= fts5YY_MAX_REDUCE ){
      fts5yy_reduce(fts5yypParser,fts5yyact-fts5YY_MIN_REDUCE);
    }else{
      assert( fts5yyact == fts5YY_ERROR_ACTION );
#ifdef fts5YYERRORSYMBOL
      int fts5yymx;
#endif
#ifndef NDEBUG
      if( fts5yyTraceFILE ){
17991
17992
17993
17994
17995
17996
17997
17998

17999
18000
18001
18002
18003
18004
18005
18232
18233
18234
18235
18236
18237
18238

18239
18240
18241
18242
18243
18244
18245
18246







-
+







        fts5yymajor = fts5YYNOCODE;
      }else{
         while(
          fts5yypParser->fts5yyidx >= 0 &&
          fts5yymx != fts5YYERRORSYMBOL &&
          (fts5yyact = fts5yy_find_reduce_action(
                        fts5yypParser->fts5yystack[fts5yypParser->fts5yyidx].stateno,
                        fts5YYERRORSYMBOL)) >= fts5YYNSTATE
                        fts5YYERRORSYMBOL)) >= fts5YY_MIN_REDUCE
        ){
          fts5yy_pop_parser_stack(fts5yypParser);
        }
        if( fts5yypParser->fts5yyidx < 0 || fts5yymajor==0 ){
          fts5yy_destructor(fts5yypParser,(fts5YYCODETYPE)fts5yymajor,&fts5yyminorunion);
          fts5yy_parse_failed(fts5yypParser);
          fts5yymajor = fts5YYNOCODE;
18041
18042
18043
18044
18045
18046
18047





18048
18049
18050
18051
18052
18053
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299







+
+
+
+
+






      if( fts5yyendofinput ){
        fts5yy_parse_failed(fts5yypParser);
      }
      fts5yymajor = fts5YYNOCODE;
#endif
    }
  }while( fts5yymajor!=fts5YYNOCODE && fts5yypParser->fts5yyidx>=0 );
#ifndef NDEBUG
  if( fts5yyTraceFILE ){
    fprintf(fts5yyTraceFILE,"%sReturn\n",fts5yyTracePrompt);
  }
#endif
  return;
}


    
#endif /* !defined(SQLITE_TEST) || defined(SQLITE_ENABLE_FTS5) */
Changes to SQLite.Interop/src/win/interop.h.
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16








-
+







/*
 * interop.h -
 *
 * Written by Joe Mistachkin.
 * Released to the public domain, use at your own risk!
 */

#ifndef INTEROP_VERSION
#define INTEROP_VERSION          "1.0.98.0"
#define INTEROP_VERSION          "1.0.99.0"
#endif

#ifndef INTEROP_SOURCE_ID
#define INTEROP_SOURCE_ID        "0000000000000000000000000000000000000000"
#endif

#ifndef INTEROP_SOURCE_TIMESTAMP
Changes to System.Data.SQLite.Linq/AssemblyInfo.cs.
49
50
51
52
53
54
55
56
57


49
50
51
52
53
54
55


56
57







-
-
+
+
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.98.0")]
[assembly: AssemblyFileVersion("1.0.98.0")]
[assembly: AssemblyVersion("1.0.99.0")]
[assembly: AssemblyFileVersion("1.0.99.0")]
Changes to System.Data.SQLite/AssemblyInfo.cs.
68
69
70
71
72
73
74
75

76
77

78
68
69
70
71
72
73
74

75
76

77
78







-
+

-
+

//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.98.0")]
[assembly: AssemblyVersion("1.0.99.0")]
#if !PLATFORM_COMPACTFRAMEWORK
[assembly: AssemblyFileVersion("1.0.98.0")]
[assembly: AssemblyFileVersion("1.0.99.0")]
#endif
Changes to System.Data.SQLite/SQLite3.cs.
54
55
56
57
58
59
60
61

62
63
64
65
66
67
68
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68







-
+







    internal const string PublicKey =
        "002400000480000094000000060200000024000052534131000400000100010005a288de5687c4e1" +
        "b621ddff5d844727418956997f475eb829429e411aff3e93f97b70de698b972640925bdd44280df0" +
        "a25a843266973704137cbb0e7441c1fe7cae4e2440ae91ab8cde3933febcb1ac48dd33b40e13c421" +
        "d8215c18a4349a436dd499e3c385cc683015f886f6c10bd90115eb2bd61b67750839e3a19941dc9c";

#if !PLATFORM_COMPACTFRAMEWORK
    internal const string DesignerVersion = "1.0.98.0";
    internal const string DesignerVersion = "1.0.99.0";
#endif

    /// <summary>
    /// The opaque pointer returned to us by the sqlite provider
    /// </summary>
    protected internal SQLiteConnectionHandle _sql;
    protected string _fileName;
Changes to System.Data.SQLite/UnsafeNativeMethods.cs.
1315
1316
1317
1318
1319
1320
1321
1322

1323
1324
1325
1326
1327
1328
1329
1315
1316
1317
1318
1319
1320
1321

1322
1323
1324
1325
1326
1327
1328
1329







-
+







    //
    // NOTE: On the .NET Compact Framework, the native interop assembly must
    //       be used because it provides several workarounds to .NET Compact
    //       Framework limitations important for proper operation of the core
    //       System.Data.SQLite functionality (e.g. being able to bind
    //       parameters and handle column values of types Int64 and Double).
    //
    internal const string SQLITE_DLL = "SQLite.Interop.098.dll";
    internal const string SQLITE_DLL = "SQLite.Interop.099.dll";
#elif SQLITE_STANDARD
    //
    // NOTE: Otherwise, if the standard SQLite library is enabled, use it.
    //
    internal const string SQLITE_DLL = "sqlite3";
#elif USE_INTEROP_DLL
      //
Changes to Tests/version.eagle.
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41







-
+







# NOTE: For these unit tests to be useful and accurate, the following version
#       numbers must be manually kept synchronized with the version numbers for
#       the source code files, the built binaries, and the release packages.
#       The revision number is reserved for NuGet package versioning.
#
set version(major)             1
set version(minor)             0
set version(build)            98; # NOTE: Incremented with each release.
set version(build)            99; # NOTE: Incremented with each release.
set version(revision)          0

###############################################################################

#
# NOTE: What is the full version of the EntityFramework NuGet package (which
#       is not [necessarily] the same version as the assembly itself) in use
Changes to readme.htm.
1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
1
2
3
4
5
6
7


8
9
10
11
12
13
14
15
16







-
-
+
+







<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
ADO.NET SQLite Data Provider<br />
Version 1.0.98.0 - August 19, 2015<br />
Using <a href="https://www.sqlite.org/releaselog/3_8_11_1.html">SQLite 3.8.11.1</a><br />
Version 1.0.99.0 - October XX, 2015 <font color="red">(release scheduled)</font><br />
Using <a href="https://www.sqlite.org/draft/releaselog/3_8_12.html">SQLite 3.8.12</a><br />
Originally written by Robert Simpson<br />
Released to the public domain, use at your own risk!<br />
Official provider website:&nbsp;<a href="https://system.data.sqlite.org/">https://system.data.sqlite.org/</a><br />
Legacy versions:&nbsp;<a href="http://sqlite.phxsoftware.com/">http://sqlite.phxsoftware.com/</a><br />
<br />
The current development version can be downloaded from <a href="https://system.data.sqlite.org/index.html/timeline?y=ci">
https://system.data.sqlite.org/index.html/timeline?y=ci</a>
204
205
206
207
208
209
210






211
212
213
214
215
216
217
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223







+
+
+
+
+
+







supported <a href="https://www.sqlite.org/compile.html">compile-time options</a>
designed for robustness and maximum backward compatibility with previously
released versions of System.Data.SQLite.
</p>

<h2><b>Version History</b></h2>

<p>
    <b>1.0.99.0 - October XX, 2015 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to <a href="https://www.sqlite.org/draft/releaselog/3_8_12.html">SQLite 3.8.12</a>.</li>
</ul>
<p>
    <b>1.0.98.0 - August 19, 2015</b>
</p>
<ul>
    <li>Updated to <a href="https://www.sqlite.org/releaselog/3_8_11_1.html">SQLite 3.8.11.1</a>.</li>
    <li>Add full support for Visual Studio 2015 and the .NET Framework 4.6.</li>
    <li>Add support for creating custom SQL functions using delegates.</li>
Changes to test/AssemblyInfo.cs.
34
35
36
37
38
39
40
41
42


34
35
36
37
38
39
40


41
42







-
-
+
+
// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
[assembly: AssemblyVersion("1.0.98.0")]
[assembly: AssemblyFileVersion("1.0.98.0")]
[assembly: AssemblyVersion("1.0.99.0")]
[assembly: AssemblyFileVersion("1.0.99.0")]
Changes to test/app.config.
1
2
3
4
5

6
7
8
1
2
3
4

5
6
7
8




-
+



<configuration>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
</configuration>
Changes to testce/AssemblyInfo.cs.
34
35
36
37
38
39
40
41
42


34
35
36
37
38
39
40


41
42







-
-
+
+
// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
[assembly: AssemblyVersion("1.0.98.0")]
// [assembly: AssemblyFileVersion("1.0.98.0")]
[assembly: AssemblyVersion("1.0.99.0")]
// [assembly: AssemblyFileVersion("1.0.99.0")]
Changes to testlinq/2008/LINQ/App.config.
1
2
3
4
5
6

7
8
9
10
11
12
1
2
3
4
5

6
7
8
9
10
11
12





-
+






<?xml version="1.0"?>
<configuration>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.Linq" />
      <add name="SQLite Data Provider (LINQ)" invariant="System.Data.SQLite.Linq" description=".NET Framework Data Provider for SQLite (LINQ)" type="System.Data.SQLite.Linq.SQLiteProviderFactory, System.Data.SQLite.Linq, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <add name="SQLite Data Provider (LINQ)" invariant="System.Data.SQLite.Linq" description=".NET Framework Data Provider for SQLite (LINQ)" type="System.Data.SQLite.Linq.SQLiteProviderFactory, System.Data.SQLite.Linq, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.Linq.2008.csdl|res://*/NorthwindModel.Linq.2008.ssdl|res://*/NorthwindModel.Linq.2008.msl;provider=System.Data.SQLite.Linq;provider connection string=&quot;data source=.\northwindEF.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>
Changes to testlinq/2010/EF6/App.config.
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17

18
19
20
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16

17
18
19
20








-
+







-
+



<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.EF6.2010.csdl|res://*/NorthwindModel.EF6.2010.ssdl|res://*/NorthwindModel.EF6.2010.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=.\northwindEF.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </providers>
  </entityFramework>
</configuration>
Changes to testlinq/2010/LINQ/App.config.
1
2
3
4
5
6

7
8
9
10
11
12
1
2
3
4
5

6
7
8
9
10
11
12





-
+






<?xml version="1.0"?>
<configuration>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.Linq" />
      <add name="SQLite Data Provider (LINQ)" invariant="System.Data.SQLite.Linq" description=".NET Framework Data Provider for SQLite (LINQ)" type="System.Data.SQLite.Linq.SQLiteProviderFactory, System.Data.SQLite.Linq, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <add name="SQLite Data Provider (LINQ)" invariant="System.Data.SQLite.Linq" description=".NET Framework Data Provider for SQLite (LINQ)" type="System.Data.SQLite.Linq.SQLiteProviderFactory, System.Data.SQLite.Linq, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.Linq.2010.csdl|res://*/NorthwindModel.Linq.2010.ssdl|res://*/NorthwindModel.Linq.2010.msl;provider=System.Data.SQLite.Linq;provider connection string=&quot;data source=.\northwindEF.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>
Changes to testlinq/2012/EF6/App.config.
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17

18
19
20
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16

17
18
19
20








-
+







-
+



<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.EF6.2012.csdl|res://*/NorthwindModel.EF6.2012.ssdl|res://*/NorthwindModel.EF6.2012.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=.\northwindEF.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </providers>
  </entityFramework>
</configuration>
Changes to testlinq/2012/LINQ/App.config.
1
2
3
4
5
6

7
8
9
10
11
12
1
2
3
4
5

6
7
8
9
10
11
12





-
+






<?xml version="1.0"?>
<configuration>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.Linq" />
      <add name="SQLite Data Provider (LINQ)" invariant="System.Data.SQLite.Linq" description=".NET Framework Data Provider for SQLite (LINQ)" type="System.Data.SQLite.Linq.SQLiteProviderFactory, System.Data.SQLite.Linq, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <add name="SQLite Data Provider (LINQ)" invariant="System.Data.SQLite.Linq" description=".NET Framework Data Provider for SQLite (LINQ)" type="System.Data.SQLite.Linq.SQLiteProviderFactory, System.Data.SQLite.Linq, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.Linq.2012.csdl|res://*/NorthwindModel.Linq.2012.ssdl|res://*/NorthwindModel.Linq.2012.msl;provider=System.Data.SQLite.Linq;provider connection string=&quot;data source=.\northwindEF.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>
Changes to testlinq/2013/EF6/App.config.
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17

18
19
20
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16

17
18
19
20








-
+







-
+



<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.EF6.2013.csdl|res://*/NorthwindModel.EF6.2013.ssdl|res://*/NorthwindModel.EF6.2013.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=.\northwindEF.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </providers>
  </entityFramework>
</configuration>
Changes to testlinq/2013/LINQ/App.config.
1
2
3
4
5
6

7
8
9
10
11
12
1
2
3
4
5

6
7
8
9
10
11
12





-
+






<?xml version="1.0"?>
<configuration>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.Linq" />
      <add name="SQLite Data Provider (LINQ)" invariant="System.Data.SQLite.Linq" description=".NET Framework Data Provider for SQLite (LINQ)" type="System.Data.SQLite.Linq.SQLiteProviderFactory, System.Data.SQLite.Linq, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <add name="SQLite Data Provider (LINQ)" invariant="System.Data.SQLite.Linq" description=".NET Framework Data Provider for SQLite (LINQ)" type="System.Data.SQLite.Linq.SQLiteProviderFactory, System.Data.SQLite.Linq, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.Linq.2013.csdl|res://*/NorthwindModel.Linq.2013.ssdl|res://*/NorthwindModel.Linq.2013.msl;provider=System.Data.SQLite.Linq;provider connection string=&quot;data source=.\northwindEF.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>
Changes to testlinq/2015/EF6/App.config.
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17

18
19
20
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16

17
18
19
20








-
+







-
+



<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.EF6.2015.csdl|res://*/NorthwindModel.EF6.2015.ssdl|res://*/NorthwindModel.EF6.2015.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=.\northwindEF.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </providers>
  </entityFramework>
</configuration>
Changes to testlinq/2015/LINQ/App.config.
1
2
3
4
5
6

7
8
9
10
11
12
1
2
3
4
5

6
7
8
9
10
11
12





-
+






<?xml version="1.0"?>
<configuration>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.Linq" />
      <add name="SQLite Data Provider (LINQ)" invariant="System.Data.SQLite.Linq" description=".NET Framework Data Provider for SQLite (LINQ)" type="System.Data.SQLite.Linq.SQLiteProviderFactory, System.Data.SQLite.Linq, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <add name="SQLite Data Provider (LINQ)" invariant="System.Data.SQLite.Linq" description=".NET Framework Data Provider for SQLite (LINQ)" type="System.Data.SQLite.Linq.SQLiteProviderFactory, System.Data.SQLite.Linq, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.Linq.2015.csdl|res://*/NorthwindModel.Linq.2015.ssdl|res://*/NorthwindModel.Linq.2015.msl;provider=System.Data.SQLite.Linq;provider connection string=&quot;data source=.\northwindEF.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>
Changes to testlinq/Properties/AssemblyInfo.cs.
42
43
44
45
46
47
48
49
50


42
43
44
45
46
47
48


49
50







-
-
+
+
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.98.0")]
[assembly: AssemblyFileVersion("1.0.98.0")]
[assembly: AssemblyVersion("1.0.99.0")]
[assembly: AssemblyFileVersion("1.0.99.0")]
Changes to tools/install/Properties/AssemblyInfo.cs.
24
25
26
27
28
29
30
31
32


24
25
26
27
28
29
30


31
32







-
-
+
+
// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
[assembly: AssemblyVersion("1.0.98.0")]
[assembly: AssemblyFileVersion("1.0.98.0")]
[assembly: AssemblyVersion("1.0.99.0")]
[assembly: AssemblyFileVersion("1.0.99.0")]
Changes to www/news.wiki.
1
2
3
4






5
6
7
8
9
10
11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17




+
+
+
+
+
+







<title>News</title>

<b>Version History</b>

<p>
    <b>1.0.99.0 - October XX, 2015 <font color="red">(release scheduled)</font></b>
</p>
<ul>
    <li>Updated to [https://www.sqlite.org/draft/releaselog/3_8_12.html|SQLite 3.8.12].</li>
</ul>
<p>
    <b>1.0.98.0 - August 19, 2015</b>
</p>
<ul>
    <li>Updated to [https://www.sqlite.org/releaselog/3_8_11_1.html|SQLite 3.8.11.1].</li>
    <li>Add full support for Visual Studio 2015 and the .NET Framework 4.6.</li>
    <li>Add support for creating custom SQL functions using delegates.</li>