Fossil

Check-in Differences
Login

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

Difference From:

[51cf7508] Improvements to the "Fossil Build Process" documentation, with improved comments in related source files. No changes to real code. (user: drh tags: trunk, date: 2017-11-18 19:58:54)

To:

[a0001dcf] Version 2.4 (user: drh tags: trunk, release, version-2.4, date: 2017-11-03 09:29:29)

Changes to VERSION.

     1         -2.5
            1  +2.4

Changes to auto.def.

     9      9       with-zlib:path|auto|tree
    10     10                            => {Look for zlib in the given path, automatically, or in the source tree}
    11     11       with-exec-rel-paths=0
    12     12                            => {Enable relative paths for external diff/gdiff}
    13     13       with-legacy-mv-rm=0  => {Enable legacy behavior for mv/rm (skip checkout files)}
    14     14       with-th1-docs=0      => {Enable TH1 for embedded documentation pages}
    15     15       with-th1-hooks=0     => {Enable TH1 hooks for commands and web pages}
    16         -    with-tcl:path        => {Enable Tcl integration, with Tcl in the specified path}
           16  +    with-tcl=path        => {Enable Tcl integration, with Tcl in the specified path}
    17     17       with-tcl-stubs=0     => {Enable Tcl integration via stubs library mechanism}
    18     18       with-tcl-private-stubs=0
    19     19                            => {Enable Tcl integration via private stubs mechanism}
    20     20       with-see=0           => {Enable the SQLite Encryption Extension (SEE)}
    21     21       internal-sqlite=1    => {Don't use the internal SQLite, use the system one}
    22     22       static=0             => {Link a static executable}
    23     23       fusefs=1             => {Disable the Fuse Filesystem}

Changes to skins/black_and_white/footer.txt.

     1      1   <div class="footer">
     2      2   Fossil $release_version $manifest_version $manifest_date
     3      3   </div>
            4  +</body></html>

Changes to skins/black_and_white/header.txt.

            1  +<html>
            2  +<head>
            3  +<base href="$baseurl/$current_page" />
            4  +<title>$<project_name>: $<title></title>
            5  +<link rel="alternate" type="application/rss+xml" title="RSS Feed"
            6  +      href="$home/timeline.rss">
            7  +<link rel="stylesheet" href="$stylesheet_url" type="text/css"
            8  +      media="screen">
            9  +</head>
           10  +<body>
     1     11   <div class="header">
     2     12     <div class="logo">
     3     13       <img src="$logo_image_url" alt="logo">
     4     14       <br />$<project_name>
     5     15     </div>
     6     16     <div class="title">$<title></div>
     7     17     <div class="status"><th1>

Changes to skins/blitz/footer.txt.

     1         -  </div> <!-- end div container -->
     2         -</div> <!-- end div middle max-full-width -->
     3         -<div class="footer">
     4         -  <div class="container">
     5         -    <div class="pull-right">
     6         -      <a href="https://www.fossil-scm.org/">Fossil $release_version $manifest_version $manifest_date</a>
            1  +      </div> <!-- end div container -->
            2  +    </div> <!-- end div middle max-full-width -->
            3  +    <div class="footer">
            4  +      <div class="container">
            5  +        <div class="pull-right">
            6  +          <a href="https://www.fossil-scm.org/">Fossil $release_version $manifest_version $manifest_date</a>
            7  +        </div>
            8  +        This page was generated in about <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s
            9  +      </div>
     7     10       </div>
     8         -    This page was generated in about <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s
     9         -  </div>
    10         -</div>
           11  +  </body>
           12  +</html>

Changes to skins/blitz/header.txt.

     1         -<div class="header">
     2         -  <div class="container">
            1  +<html>
            2  +  <head>
            3  +    <base href="$baseurl/$current_page" />
            4  +    <title>$<project_name>: $<title></title>
            5  +      <link rel="alternate" type="application/rss+xml" title="RSS Feed" href="$home/timeline.rss" />
            6  +      <link rel="stylesheet" href="$stylesheet_url" type="text/css" media="screen" />
            7  +  </head>
            8  +
            9  +  <body>
           10  +    <div class="header">
           11  +      <div class="container">
     3     12   
     4         -    <!-- Header -->
     5         -    <div class="login pull-right">
     6         -      <th1>
     7         -        if {[info exists login]} {
     8         -          html "<b>$login</b> — <a class='button' href='$home/login'>Logout</a>\n"
     9         -        } else {
    10         -          html "<a class='button' href='$home/login'>Login</a>\n"
    11         -        }
    12         -      </th1>
    13         -      <div>
    14         -        <h2><small>$title</small></h2>
    15         -      </div>
    16         -    </div>
    17         -    <div class='logo'>
    18         -      <img src='$logo_image_url' />
    19         -      <th1>
    20         -      if {[anycap jor]} {
    21         -        html "<a class='rss' href='$home/timeline.rss'></a>"
    22         -      }
    23         -      </th1>
    24         -    </div>
           13  +        <!-- Header -->
           14  +        <div class="login pull-right">
           15  +          <th1>
           16  +            if {[info exists login]} {
           17  +              html "<b>$login</b> — <a class='button' href='$home/login'>Logout</a>\n"
           18  +            } else {
           19  +              html "<a class='button' href='$home/login'>Login</a>\n"
           20  +            }
           21  +          </th1>
           22  +          <div>
           23  +            <h2><small>$title</small></h2>
           24  +          </div>
           25  +        </div>
           26  +        <div class='logo'>
           27  +          <img src='$logo_image_url' />
           28  +          <th1>
           29  +          if {[anycap jor]} {
           30  +            html "<a class='rss' href='$home/timeline.rss'></a>"
           31  +          }
           32  +          </th1>
           33  +        </div>
    25     34   
    26         -    <!-- Main Menu -->
    27         -    <div class="mainmenu">
    28         -      <ul>
    29         -        <th1>
           35  +        <!-- Main Menu -->
           36  +        <div class="mainmenu">
           37  +          <ul>
           38  +            <th1>
    30     39   proc menulink {url name} {
    31     40     upvar current_page current
    32     41     upvar home home
    33     42     if {[string range $url 0 [string length $current]] eq "/$current"} {
    34     43       html "<li class='active'>"
    35     44     } else {
    36     45       html "<li>"

Changes to skins/blitz_no_logo/footer.txt.

     1         -  </div> <!-- end div container -->
     2         -</div> <!-- end div middle max-full-width -->
     3         -<div class="footer">
     4         -  <div class="container">
     5         -    <div class="pull-right">
     6         -      <a href="https://www.fossil-scm.org/">Fossil $release_version $manifest_version $manifest_date</a>
            1  +      </div> <!-- end div container -->
            2  +    </div> <!-- end div middle max-full-width -->
            3  +    <div class="footer">
            4  +      <div class="container">
            5  +        <div class="pull-right">
            6  +          <a href="https://www.fossil-scm.org/">Fossil $release_version $manifest_version $manifest_date</a>
            7  +        </div>
            8  +        This page was generated in about <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s
            9  +      </div>
     7     10       </div>
     8         -    This page was generated in about <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s
     9         -  </div>
    10         -</div>
           11  +  </body>
           12  +</html>

Changes to skins/blitz_no_logo/header.txt.

     1         -<div class="header">
     2         -  <div class="container">
            1  +<html>
            2  +  <head>
            3  +    <base href="$baseurl/$current_page" />
            4  +    <title>$<project_name>: $<title></title>
            5  +      <link rel="alternate" type="application/rss+xml" title="RSS Feed" href="$home/timeline.rss" />
            6  +      <link rel="stylesheet" href="$stylesheet_url" type="text/css" media="screen" />
            7  +  </head>
            8  +
            9  +  <body>
           10  +    <div class="header">
           11  +      <div class="container">
     3     12   
     4         -    <div class="login pull-right">
     5         -      <th1>
     6         -        if {[info exists login]} {
     7         -          html "<b>$login</b> — <a class='button' href='$home/login'>Logout</a>\n"
     8         -        } else {
     9         -          html "<a class='button' href='$home/login'>Login</a>\n"
    10         -        }
    11         -      </th1>
    12         -    </div>
    13         -    <div class='title'>
    14         -      <h1>$<project_name>
    15         -      <th1>
    16         -      if {[anycap jor]} {
    17         -        html "<a class='rss' href='$home/timeline.rss'></a>"
    18         -      }
    19         -      </th1>
    20         -      <small> &nbsp;$<title></small></h1>
    21         -    </div>
           13  +        <div class="login pull-right">
           14  +          <th1>
           15  +            if {[info exists login]} {
           16  +              html "<b>$login</b> — <a class='button' href='$home/login'>Logout</a>\n"
           17  +            } else {
           18  +              html "<a class='button' href='$home/login'>Login</a>\n"
           19  +            }
           20  +          </th1>
           21  +        </div>
           22  +        <div class='title'>
           23  +          <h1>$<project_name>
           24  +          <th1>
           25  +          if {[anycap jor]} {
           26  +            html "<a class='rss' href='$home/timeline.rss'></a>"
           27  +          }
           28  +          </th1>
           29  +          <small> &nbsp;$<title></small></h1>
           30  +        </div>
    22     31   
    23         -    <!-- Main Menu -->
    24         -    <div class="mainmenu">
    25         -      <ul>
    26         -        <th1>
           32  +        <!-- Main Menu -->
           33  +        <div class="mainmenu">
           34  +          <ul>
           35  +            <th1>
    27     36   proc menulink {url name} {
    28     37     upvar current_page current
    29     38     upvar home home
    30     39     if {[string range $url 0 [string length $current]] eq "/$current"} {
    31     40       html "<li class='active'>"
    32     41     } else {
    33     42       html "<li>"

Changes to skins/bootstrap/footer.txt.

    32     32     var target = document.querySelector(
    33     33       collapse.getAttribute('data-target')
    34     34     );
    35     35     target.classList.toggle('collapse');
    36     36     target.classList.toggle('collapsed');
    37     37   };
    38     38   </script>
           39  +</body></html>

Changes to skins/default/footer.txt.

     1      1   <div class="footer">
     2      2   This page was generated in about
     3      3   <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s by
     4      4   Fossil $release_version $manifest_version $manifest_date
     5      5   </div>
            6  +</body></html>

Changes to skins/default/header.txt.

     1         -<div class="header">
     2         -  <div class="title"><h1>$<project_name></h1>$<title></div>
     3         -    <div class="status"><th1>
     4         - if {[info exists login]} {
     5         -   html "$login — <a href='$home/login'>Logout</a>\n"
     6         - } else {
     7         -   html "<a href='$home/login'>Login</a>\n"
     8         - }
     9         -    </th1></div>
    10         -</div>
    11         -<div class="mainmenu">
            1  +<html>
            2  +  <head>
            3  +    <base href="$baseurl/$current_page" />
            4  +    <title>$<project_name>: $<title></title>
            5  +      <link rel="alternate" type="application/rss+xml" title="RSS Feed"
            6  +            href="$home/timeline.rss" />
            7  +      <link rel="stylesheet" href="$stylesheet_url" type="text/css"
            8  +            media="screen" />
            9  +  </head>
           10  +
           11  +  <body>
           12  +    <div class="header">
           13  +      <div class="title"><h1>$<project_name></h1>$<title></div>
           14  +        <div class="status"><th1>
           15  +     if {[info exists login]} {
           16  +       html "$login — <a href='$home/login'>Logout</a>\n"
           17  +     } else {
           18  +       html "<a href='$home/login'>Login</a>\n"
           19  +     }
           20  +        </th1></div>
           21  +    </div>
           22  +
           23  +    <div class="mainmenu">
    12     24   <th1>
    13     25   proc menulink {url name} {
    14     26     upvar current_page current
    15     27     upvar home home
    16     28     if {[string range $url 0 [string length $current]] eq "/$current"} {
    17     29       html "<a href='$home$url' class='active'>$name</a>\n"
    18     30     } else {

Changes to skins/eagle/footer.txt.

    18     18     This page was generated in about
    19     19     <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s by
    20     20     <a href="$fossilUrl/">Fossil</a>
    21     21     version $release_version $tclVersion
    22     22     <a href="$fossilUrl/index.html/info/$version">$manifest_version</a>
    23     23     <a href="$fossilUrl/index.html/timeline?c=$fossilDate&amp;y=ci">$manifest_date</a>
    24     24   </div>
           25  +</body></html>

Changes to skins/eagle/header.txt.

            1  +<html>
            2  +<head>
            3  +<base href="$baseurl/$current_page" />
            4  +<title>$<project_name>: $<title></title>
            5  +<link rel="alternate" type="application/rss+xml" title="RSS Feed"
            6  +      href="$home/timeline.rss" />
            7  +<link rel="stylesheet" href="$stylesheet_url" type="text/css"
            8  +      media="screen" />
            9  +</head>
           10  +<body>
     1     11   <div class="header">
     2     12     <div class="logo">
     3     13       <th1>
     4     14       ##
     5     15       ## NOTE: The purpose of this procedure is to take the base URL of the
     6     16       ##       Fossil project and return the root of the entire web site using
     7     17       ##       the same URI scheme as the base URL (e.g. http or https).

Changes to skins/enhanced1/footer.txt.

    18     18     This page was generated in about
    19     19     <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s by
    20     20     <a href="$fossilUrl/">Fossil</a>
    21     21     version $release_version $tclVersion
    22     22     <a href="$fossilUrl/index.html/info/$version">$manifest_version</a>
    23     23     <a href="$fossilUrl/index.html/timeline?c=$fossilDate&amp;y=ci">$manifest_date</a>
    24     24   </div>
           25  +</body></html>

Changes to skins/enhanced1/header.txt.

            1  +<html>
            2  +<head>
            3  +<base href="$baseurl/$current_page" />
            4  +<title>$<project_name>: $<title></title>
            5  +<link rel="alternate" type="application/rss+xml" title="RSS Feed"
            6  +      href="$home/timeline.rss" />
            7  +<link rel="stylesheet" href="$stylesheet_url" type="text/css"
            8  +      media="screen" />
            9  +</head>
           10  +<body>
     1     11   <div class="header">
     2     12     <div class="logo">
     3     13       <th1>
     4     14       ##
     5     15       ## NOTE: The purpose of this procedure is to take the base URL of the
     6     16       ##       Fossil project and return the root of the entire web site using
     7     17       ##       the same URI scheme as the base URL (e.g. http or https).

Changes to skins/khaki/footer.txt.

     1      1   <div class="footer">
     2      2   Fossil $release_version $manifest_version $manifest_date
     3      3   </div>
            4  +</body></html>

Changes to skins/khaki/header.txt.

            1  +<html>
            2  +<head>
            3  +<base href="$baseurl/$current_page" />
            4  +<title>$<project_name>: $<title></title>
            5  +<link rel="alternate" type="application/rss+xml" title="RSS Feed"
            6  +      href="$home/timeline.rss">
            7  +<link rel="stylesheet" href="$stylesheet_url" type="text/css"
            8  +      media="screen">
            9  +</head>
           10  +<body>
     1     11   <div class="header">
     2     12     <div class="title">$<title></div>
     3     13     <div class="status">
     4     14       <div class="logo">$<project_name></div><br/>
     5     15       <th1>
     6     16        if {[info exists login]} {
     7     17          puts "Logged in as $login"

Changes to skins/original/footer.txt.

     1      1   <div class="footer">
     2      2   This page was generated in about
     3      3   <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s by
     4      4   Fossil $release_version $manifest_version $manifest_date
     5      5   </div>
            6  +</body></html>

Changes to skins/original/header.txt.

            1  +<html>
            2  +<head>
            3  +<base href="$baseurl/$current_page" />
            4  +<title>$<project_name>: $<title></title>
            5  +<link rel="alternate" type="application/rss+xml" title="RSS Feed"
            6  +      href="$home/timeline.rss" />
            7  +<link rel="stylesheet" href="$stylesheet_url" type="text/css"
            8  +      media="screen" />
            9  +</head>
           10  +<body>
     1     11   <div class="header">
     2     12     <div class="logo">
     3     13       <img src="$logo_image_url" alt="logo" />
     4     14     </div>
     5     15     <div class="title"><small>$<project_name></small><br />$<title></div>
     6     16     <div class="status"><th1>
     7     17        if {[info exists login]} {

Changes to skins/plain_gray/footer.txt.

     1      1   <div class="footer">
     2      2   Fossil $release_version $manifest_version $manifest_date
     3      3   </div>
            4  +</body></html>

Changes to skins/plain_gray/header.txt.

            1  +<html>
            2  +<head>
            3  +<base href="$baseurl/$current_page" />
            4  +<title>$<project_name>: $<title></title>
            5  +<link rel="alternate" type="application/rss+xml" title="RSS Feed"
            6  +      href="$home/timeline.rss">
            7  +<link rel="stylesheet" href="$stylesheet_url" type="text/css"
            8  +      media="screen">
            9  +</head>
           10  +<body>
     1     11   <div class="header">
     2     12     <div class="title"><small>$<project_name></small><br />$<title></div>
     3     13     <div class="status"><th1>
     4     14        if {[info exists login]} {
     5     15          puts "Logged in as $login"
     6     16        } else {
     7     17          puts "Not logged in"

Changes to skins/rounded1/footer.txt.

     1      1   <div class="footer">
     2      2   Fossil $release_version $manifest_version $manifest_date
     3      3   </div>
            4  +</body></html>

Changes to skins/rounded1/header.txt.

            1  +<html>
            2  +<head>
            3  +<base href="$baseurl/$current_page" />
            4  +<title>$<project_name>: $<title></title>
            5  +<link rel="alternate" type="application/rss+xml" title="RSS Feed"
            6  +      href="$home/timeline.rss">
            7  +<link rel="stylesheet" href="$stylesheet_url" type="text/css"
            8  +      media="screen">
            9  +</head>
           10  +<body>
     1     11   <div class="header">
     2     12     <div class="logo">
     3     13       <img src="$logo_image_url" alt="logo">
     4     14       <br />$<project_name>
     5     15     </div>
     6     16     <div class="title">$<title></div>
     7     17     <div class="status"><th1>

Changes to skins/xekri/css.txt.

   820    820   /* color for capabilities, inherited by developer */
   821    821   span.ueditInheritDeveloper {
   822    822     color: #f00;
   823    823   }
   824    824   
   825    825   /* color for capabilities, inherited by reader */
   826    826   span.ueditInheritReader {
   827         -  color: #ee0;
          827  +  color: black;
   828    828   }
   829    829   
   830    830   /* color for capabilities, inherited by anonymous */
   831    831   span.ueditInheritAnonymous {
   832    832     color: #00f;
   833    833   }
   834    834   

Changes to skins/xekri/footer.txt.

     3      3   <div class="page-time">
     4      4   Generated in <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s
     5      5   </div>
     6      6   <div class="fossil-info">
     7      7   Fossil v$release_version $manifest_version
     8      8   </div>
     9      9   </div>
           10  +</body>
           11  +</html>

Changes to skins/xekri/header.txt.

            1  +<html>
            2  +<head>
            3  +<base href="$baseurl/$current_page" />
            4  +<title>$<project_name>: $<title></title>
            5  +<link rel="alternate" type="application/rss+xml" title="RSS Feed"
            6  +      href="$home/timeline.rss" />
            7  +<link rel="stylesheet" href="$stylesheet_url" type="text/css"
            8  +      media="screen" />
            9  +</head>
           10  +<body>
     1     11   <div class="header">
     2     12     <div class="logo">
     3     13       <th1>
     4     14       ##
     5     15       ## NOTE: The purpose of this procedure is to take the base URL of the
     6     16       ##       Fossil project and return the root of the entire web site using
     7     17       ##       the same URI scheme as the base URL (e.g. http or https).

Changes to src/diff.tcl.

   230    230   wm title . $CFG(TITLE)
   231    231   wm iconname . $CFG(TITLE)
   232    232   # Keystroke bindings for on the top-level window for navigation and
   233    233   # control also fire when those same keystrokes are pressed in the
   234    234   # Search entry box.  Disable them, to prevent the diff screen from
   235    235   # disappearing abruptly and unexpectedly when searching for "q".
   236    236   #
   237         -bind . <Control-q> exit
   238         -bind . <Control-p> {catch searchPrev; break}
   239         -bind . <Control-n> {catch searchNext; break}
   240         -bind . <Escape><Escape> exit
          237  +# bind . <q> exit
          238  +# bind . <p> {catch searchPrev; break}
          239  +# bind . <n> {catch searchNext; break}
          240  +# bind . <Escape><Escape> exit
   241    241   bind . <Destroy> {after 0 exit}
   242    242   bind . <Tab> {cycleDiffs; break}
   243    243   bind . <<PrevWindow>> {cycleDiffs 1; break}
   244    244   bind . <Control-f> {searchOnOff; break}
   245    245   bind . <Control-g> {catch searchNext; break}
   246    246   bind . <Return> {
   247         -  event generate .bb.files <1>
          247  +  event generate bb.files <1>
   248    248     event generate .bb.files <ButtonRelease-1>
   249    249     break
   250    250   }
   251    251   foreach {key axis args} {
   252    252     Up    y {scroll -5 units}
   253    253     k     y {scroll -5 units}
   254    254     Down  y {scroll 5 units}
................................................................................
   393    393   }
   394    394   proc searchOnOff {} {
   395    395     if {[info exists ::search]} {
   396    396       unset ::search
   397    397       .txtA tag remove search 1.0 end
   398    398       .txtB tag remove search 1.0 end
   399    399       pack forget .bb.sframe
   400         -    focus .
   401    400     } else {
   402    401       set ::search .txtA
   403    402       if {![winfo exists .bb.sframe]} {
   404    403         frame .bb.sframe
   405    404         ::ttk::entry .bb.sframe.e -width 10
   406    405         pack .bb.sframe.e -side left -fill y -expand 1
   407    406         bind .bb.sframe.e <Return> {searchNext; break}

Changes to src/main.mk.

   191    191     $(SRCDIR)/../skins/rounded1/footer.txt \
   192    192     $(SRCDIR)/../skins/rounded1/header.txt \
   193    193     $(SRCDIR)/../skins/xekri/css.txt \
   194    194     $(SRCDIR)/../skins/xekri/details.txt \
   195    195     $(SRCDIR)/../skins/xekri/footer.txt \
   196    196     $(SRCDIR)/../skins/xekri/header.txt \
   197    197     $(SRCDIR)/diff.tcl \
   198         -  $(SRCDIR)/markdown.md \
   199         -  $(SRCDIR)/wiki.wiki
          198  +  $(SRCDIR)/markdown.md
   200    199   
   201    200   TRANS_SRC = \
   202    201     $(OBJDIR)/add_.c \
   203    202     $(OBJDIR)/allrepo_.c \
   204    203     $(OBJDIR)/attach_.c \
   205    204     $(OBJDIR)/bag_.c \
   206    205     $(OBJDIR)/bisect_.c \

Changes to src/makemake.tcl.

     7      7   #     win/Makefile.mingw    # makefile for mingw on windows
     8      8   #     win/Makefile.*        # makefiles for other windows compilers
     9      9   #
    10     10   # Run this script while in the "src" subdirectory.  Like this:
    11     11   #
    12     12   #      tclsh makemake.tcl
    13     13   #
    14         -# Add new source files by listing the files (without their .c suffix)
    15         -# in the "src" variable.  Add new resource files to the "extra_files"
    16         -# variable.  There are other variables that you can alter, down to
    17         -# the "STOP HERE" comment.  The stuff below "STOP HERE" should rarely need
    18         -# to change.
    19         -#
    20     14   #############################################################################
    21     15   
    22     16   # Basenames of all source files that get preprocessed using
    23     17   # "translate" and "makeheaders".  To add new C-language source files to the
    24     18   # project, simply add the basename to this list and rerun this script.
    25     19   #
    26     20   # Set the separate extra_files variable further down for how to add non-C
................................................................................
   156    150   }
   157    151   
   158    152   # Additional resource files that get built into the executable.
   159    153   #
   160    154   set extra_files {
   161    155     diff.tcl
   162    156     markdown.md
   163         -  wiki.wiki
   164    157     ../skins/*/*.txt
   165    158   }
   166    159   
   167    160   # Options used to compile the included SQLite library.
   168    161   #
   169    162   set SQLITE_OPTIONS {
   170    163     -DNDEBUG=1
................................................................................
   217    210   #
   218    211   set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
   219    212   lappend SHELL_WIN32_OPTIONS -Daccess=file_access
   220    213   lappend SHELL_WIN32_OPTIONS -Dsystem=fossil_system
   221    214   lappend SHELL_WIN32_OPTIONS -Dgetenv=fossil_getenv
   222    215   lappend SHELL_WIN32_OPTIONS -Dfopen=fossil_fopen
   223    216   
   224         -# STOP HERE.
   225         -# Unless the build procedures changes, you should not have to edit anything
   226         -# below this line.
   227         -#############################################################################
   228         -
   229    217   # Name of the final application
   230    218   #
   231    219   set name fossil
   232    220   
   233    221   # The "writeln" command sends output to the target makefile.
   234    222   #
   235    223   proc writeln {args} {
................................................................................
   237    225     if {[lindex $args 0]=="-nonewline"} {
   238    226       puts -nonewline $output_file [lindex $args 1]
   239    227     } else {
   240    228       puts $output_file [lindex $args 0]
   241    229     }
   242    230   }
   243    231   
          232  +# STOP HERE.
          233  +# Unless the build procedures changes, you should not have to edit anything
          234  +# below this line.
          235  +
   244    236   # Expand any wildcards in "extra_files"
   245    237   set new_extra_files {}
   246    238   foreach file $extra_files {
   247    239     foreach x [glob -nocomplain $file] {
   248    240       lappend new_extra_files $x
   249    241     }
   250    242   }
................................................................................
   682    674   endif
   683    675   
   684    676   #### The directories where the OpenSSL include and library files are located.
   685    677   #    The recommended usage here is to use the Sysinternals junction tool
   686    678   #    to create a hard link between an "openssl-1.x" sub-directory of the
   687    679   #    Fossil source code directory and the target OpenSSL source directory.
   688    680   #
   689         -OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2m
          681  +OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2l
   690    682   OPENSSLINCDIR = $(OPENSSLDIR)/include
   691    683   OPENSSLLIBDIR = $(OPENSSLDIR)
   692    684   
   693    685   #### Either the directory where the Tcl library is installed or the Tcl
   694    686   #    source code directory resides (depending on the value of the macro
   695    687   #    FOSSIL_TCL_SOURCE).  If this points to the Tcl install directory,
   696    688   #    this directory must have "include" and "lib" sub-directories.  If
................................................................................
  1513   1505   
  1514   1506   # Enable support for the SQLite Encryption Extension?
  1515   1507   !ifndef USE_SEE
  1516   1508   USE_SEE = 0
  1517   1509   !endif
  1518   1510   
  1519   1511   !if $(FOSSIL_ENABLE_SSL)!=0
  1520         -SSLDIR    = $(B)\compat\openssl-1.0.2m
         1512  +SSLDIR    = $(B)\compat\openssl-1.0.2l
  1521   1513   SSLINCDIR = $(SSLDIR)\inc32
  1522   1514   !if $(FOSSIL_DYNAMIC_BUILD)!=0
  1523   1515   SSLLIBDIR = $(SSLDIR)\out32dll
  1524   1516   !else
  1525   1517   SSLLIBDIR = $(SSLDIR)\out32
  1526   1518   !endif
  1527   1519   SSLLFLAGS = /nologo /opt:ref /debug

Changes to src/mkbuiltin.c.

     1      1   /*
     2      2   ** Copyright (c) 2014 D. Richard Hipp
     3      3   **
     4      4   ** This program is free software; you can redistribute it and/or
     5      5   ** modify it under the terms of the Simplified BSD License (also
     6      6   ** known as the "2-Clause License" or "FreeBSD License".)
     7         -**
            7  +
     8      8   ** This program is distributed in the hope that it will be useful,
     9      9   ** but without any warranty; without even the implied warranty of
    10     10   ** merchantability or fitness for a particular purpose.
    11     11   **
    12     12   ** Author contact information:
    13     13   **   drh@hwaci.com
    14     14   **   http://www.hwaci.com/drh/
................................................................................
    16     16   *******************************************************************************
    17     17   **
    18     18   ** This is a stand-alone utility program that is part of the Fossil build
    19     19   ** process.  This program reads files named on the command line and converts
    20     20   ** them into ANSI-C static char array variables.  Output is written onto
    21     21   ** standard output.
    22     22   **
    23         -** The makefiles use this utility to package various resources (large scripts,
           23  +** The makefiles use this utility package various resources (large scripts,
    24     24   ** GIF images, etc) that are separate files in the source code as byte
    25     25   ** arrays in the resulting executable.
    26     26   */
    27     27   #include <stdio.h>
    28     28   #include <stdlib.h>
    29     29   #include <string.h>
    30     30   

Changes to src/mkindex.c.

     1      1   /*
     2      2   ** Copyright (c) 2002 D. Richard Hipp
     3      3   **
     4      4   ** This program is free software; you can redistribute it and/or
     5      5   ** modify it under the terms of the Simplified BSD License (also
     6      6   ** known as the "2-Clause License" or "FreeBSD License".)
     7         -**
            7  +
     8      8   ** This program is distributed in the hope that it will be useful,
     9      9   ** but without any warranty; without even the implied warranty of
    10     10   ** merchantability or fitness for a particular purpose.
    11     11   **
    12     12   ** Author contact information:
    13     13   **   drh@hwaci.com
    14     14   **   http://www.hwaci.com/drh/
................................................................................
    29     29   ** implements the webpage or command.  The form of this function is:
    30     30   **
    31     31   **       void function_name(void){
    32     32   **
    33     33   ** Command names can divided into three classes:  1st-tier, 2nd-tier,
    34     34   ** and test.  1st-tier commands are the most frequently used and the
    35     35   ** ones that show up with "fossil help".  2nd-tier are seldom-used and/or
    36         -** legacy commands.  Test commands are unsupported commands used for testing
           36  +** legacy command.  Test commands are unsupported commands used for testing
    37     37   ** and analysis only.
    38     38   **
    39     39   ** Commands are 1st-tier by default.  If the command name begins with
    40     40   ** "test-" or if the command name has a "test" argument, then it becomes
    41     41   ** a test command.  If the command name has a "2nd-tier" argument or ends
    42     42   ** with a "*" character, it is second tier.  Examples:
    43     43   **

Changes to src/search.c.

   950    950   ** converted into "&lt;".  This is similar to htmlize() except that
   951    951   ** <mark> and </mark> are preserved.
   952    952   */
   953    953   static char *cleanSnippet(const char *zSnip){
   954    954     int i;
   955    955     int n = 0;
   956    956     char *z;
   957         -  if( zSnip==0 ) zSnip = "";
   958    957     for(i=0; zSnip[i]; i++) if( zSnip[i]=='<' ) n++;
   959    958     z = fossil_malloc( i+n*4+1 );
   960    959     i = 0;
   961    960     while( zSnip[0] ){
   962    961       if( zSnip[0]=='<' ){
   963    962         n = isSnippetMark(zSnip);
   964    963         if( n ){

Changes to src/shell.c.

  2561   2561       }
  2562   2562     }
  2563   2563     if( bSep ){
  2564   2564       utf8_printf(p->out, "%s", p->colSeparator);
  2565   2565     }
  2566   2566   }
  2567   2567   
         2568  +#ifdef SIGINT
  2568   2569   /*
  2569   2570   ** This routine runs when the user presses Ctrl-C
  2570   2571   */
  2571   2572   static void interrupt_handler(int NotUsed){
  2572   2573     UNUSED_PARAMETER(NotUsed);
  2573   2574     seenInterrupt++;
  2574   2575     if( seenInterrupt>2 ) exit(1);
  2575   2576     if( globalDb ) sqlite3_interrupt(globalDb);
  2576   2577   }
  2577         -
  2578         -#if (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
  2579         -/*
  2580         -** This routine runs for console events (e.g. Ctrl-C) on Win32
  2581         -*/
  2582         -static BOOL WINAPI ConsoleCtrlHandler(
  2583         -  DWORD dwCtrlType /* One of the CTRL_*_EVENT constants */
  2584         -){
  2585         -  if( dwCtrlType==CTRL_C_EVENT ){
  2586         -    interrupt_handler(0);
  2587         -    return TRUE;
  2588         -  }
  2589         -  return FALSE;
  2590         -}
  2591   2578   #endif
  2592   2579   
  2593   2580   #ifndef SQLITE_OMIT_AUTHORIZATION
  2594   2581   /*
  2595   2582   ** When the ".auth ON" is set, the following authorizer callback is
  2596   2583   ** invoked.  It always returns SQLITE_OK.
  2597   2584   */
................................................................................
  8058   8045     Argv0 = argv[0];
  8059   8046   
  8060   8047     /* Make sure we have a valid signal handler early, before anything
  8061   8048     ** else is done.
  8062   8049     */
  8063   8050   #ifdef SIGINT
  8064   8051     signal(SIGINT, interrupt_handler);
  8065         -#elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
  8066         -  SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
  8067   8052   #endif
  8068   8053   
  8069   8054   #ifdef SQLITE_SHELL_DBNAME_PROC
  8070   8055     {
  8071   8056       /* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
  8072   8057       ** of a C-function that will provide the name of the database file.  Use
  8073   8058       ** this compile-time option to embed this shell program in larger

Changes to src/sqlite3.c.

     1      1   /******************************************************************************
     2      2   ** This file is an amalgamation of many separate C source files from SQLite
     3         -** version 3.22.0.  By combining all the individual C code files into this
            3  +** version 3.21.0.  By combining all the individual C code files into this
     4      4   ** single large file, the entire code can be compiled as a single translation
     5      5   ** unit.  This allows many compilers to do optimizations that would not be
     6      6   ** possible if the files were compiled separately.  Performance improvements
     7      7   ** of 5% or more are commonly seen when SQLite is compiled as a single
     8      8   ** translation unit.
     9      9   **
    10     10   ** This file is all you need to compile SQLite.  To use SQLite in other
................................................................................
  1143   1143   ** been edited in any way since it was last checked in, then the last
  1144   1144   ** four hexadecimal digits of the hash may be modified.
  1145   1145   **
  1146   1146   ** See also: [sqlite3_libversion()],
  1147   1147   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
  1148   1148   ** [sqlite_version()] and [sqlite_source_id()].
  1149   1149   */
  1150         -#define SQLITE_VERSION        "3.22.0"
  1151         -#define SQLITE_VERSION_NUMBER 3022000
  1152         -#define SQLITE_SOURCE_ID      "2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b8322ba3"
         1150  +#define SQLITE_VERSION        "3.21.0"
         1151  +#define SQLITE_VERSION_NUMBER 3021000
         1152  +#define SQLITE_SOURCE_ID      "2017-10-24 18:55:49 1a584e499906b5c87ec7d43d4abce641fdf017c42125b083109bc77c4de48827"
  1153   1153   
  1154   1154   /*
  1155   1155   ** CAPI3REF: Run-Time Library Version Numbers
  1156   1156   ** KEYWORDS: sqlite3_version sqlite3_sourceid
  1157   1157   **
  1158   1158   ** These interfaces provide the same information as the [SQLITE_VERSION],
  1159   1159   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
  1528   1528   #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
  1529   1529   #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
  1530   1530   #define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
  1531   1531   #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
  1532   1532   #define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
  1533   1533   #define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
  1534   1534   #define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
  1535         -#define SQLITE_CANTOPEN_DIRTYWAL       (SQLITE_CANTOPEN | (5<<8))
  1536   1535   #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
  1537   1536   #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
  1538   1537   #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
  1539   1538   #define SQLITE_READONLY_ROLLBACK       (SQLITE_READONLY | (3<<8))
  1540   1539   #define SQLITE_READONLY_DBMOVED        (SQLITE_READONLY | (4<<8))
  1541         -#define SQLITE_READONLY_CANTINIT       (SQLITE_READONLY | (5<<8))
  1542   1540   #define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
  1543   1541   #define SQLITE_CONSTRAINT_CHECK        (SQLITE_CONSTRAINT | (1<<8))
  1544   1542   #define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))
  1545   1543   #define SQLITE_CONSTRAINT_FOREIGNKEY   (SQLITE_CONSTRAINT | (3<<8))
  1546   1544   #define SQLITE_CONSTRAINT_FUNCTION     (SQLITE_CONSTRAINT | (4<<8))
  1547   1545   #define SQLITE_CONSTRAINT_NOTNULL      (SQLITE_CONSTRAINT | (5<<8))
  1548   1546   #define SQLITE_CONSTRAINT_PRIMARYKEY   (SQLITE_CONSTRAINT | (6<<8))
................................................................................
  2153   2151   ** CAPI3REF: OS Interface Object
  2154   2152   **
  2155   2153   ** An instance of the sqlite3_vfs object defines the interface between
  2156   2154   ** the SQLite core and the underlying operating system.  The "vfs"
  2157   2155   ** in the name of the object stands for "virtual file system".  See
  2158   2156   ** the [VFS | VFS documentation] for further information.
  2159   2157   **
  2160         -** The VFS interface is sometimes extended by adding new methods onto
  2161         -** the end.  Each time such an extension occurs, the iVersion field
  2162         -** is incremented.  The iVersion value started out as 1 in
  2163         -** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
  2164         -** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
  2165         -** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6].  Additional fields
  2166         -** may be appended to the sqlite3_vfs object and the iVersion value
  2167         -** may increase again in future versions of SQLite.
  2168         -** Note that the structure
  2169         -** of the sqlite3_vfs object changes in the transition from
  2170         -** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
  2171         -** and yet the iVersion field was not modified.
         2158  +** The value of the iVersion field is initially 1 but may be larger in
         2159  +** future versions of SQLite.  Additional fields may be appended to this
         2160  +** object when the iVersion value is increased.  Note that the structure
         2161  +** of the sqlite3_vfs object changes in the transaction between
         2162  +** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
         2163  +** modified.
  2172   2164   **
  2173   2165   ** The szOsFile field is the size of the subclassed [sqlite3_file]
  2174   2166   ** structure used by this VFS.  mxPathname is the maximum length of
  2175   2167   ** a pathname in this VFS.
  2176   2168   **
  2177   2169   ** Registered sqlite3_vfs objects are kept on a linked list formed by
  2178   2170   ** the pNext pointer.  The [sqlite3_vfs_register()]
................................................................................
 16183  16175   };
 16184  16176   
 16185  16177   /*
 16186  16178   ** The following are the meanings of bits in the Expr.flags field.
 16187  16179   */
 16188  16180   #define EP_FromJoin  0x000001 /* Originates in ON/USING clause of outer join */
 16189  16181   #define EP_Agg       0x000002 /* Contains one or more aggregate functions */
 16190         -#define EP_HasFunc   0x000004 /* Contains one or more functions of any kind */
        16182  +                  /* 0x000004 // available for use */
 16191  16183                     /* 0x000008 // available for use */
 16192  16184   #define EP_Distinct  0x000010 /* Aggregate function with DISTINCT keyword */
 16193  16185   #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
 16194  16186   #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
 16195  16187   #define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
 16196  16188   #define EP_Collate   0x000100 /* Tree contains a TK_COLLATE operator */
 16197  16189   #define EP_Generic   0x000200 /* Ignore COLLATE or affinity on this tree */
................................................................................
 16207  16199   #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
 16208  16200   #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
 16209  16201   #define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
 16210  16202   #define EP_Alias     0x400000 /* Is an alias for a result set column */
 16211  16203   #define EP_Leaf      0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
 16212  16204   
 16213  16205   /*
 16214         -** The EP_Propagate mask is a set of properties that automatically propagate
 16215         -** upwards into parent nodes.
        16206  +** Combinations of two or more EP_* flags
 16216  16207   */
 16217         -#define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
        16208  +#define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */
 16218  16209   
 16219  16210   /*
 16220  16211   ** These macros can be used to test, set, or clear bits in the
 16221  16212   ** Expr.flags field.
 16222  16213   */
 16223  16214   #define ExprHasProperty(E,P)     (((E)->flags&(P))!=0)
 16224  16215   #define ExprHasAllProperty(E,P)  (((E)->flags&(P))==(P))
................................................................................
 16490  16481   #define NC_PartIdx   0x0002  /* True if resolving a partial index WHERE */
 16491  16482   #define NC_IsCheck   0x0004  /* True if resolving names in a CHECK constraint */
 16492  16483   #define NC_InAggFunc 0x0008  /* True if analyzing arguments to an agg func */
 16493  16484   #define NC_HasAgg    0x0010  /* One or more aggregate functions seen */
 16494  16485   #define NC_IdxExpr   0x0020  /* True if resolving columns of CREATE INDEX */
 16495  16486   #define NC_VarSelect 0x0040  /* A correlated subquery has been seen */
 16496  16487   #define NC_MinMaxAgg 0x1000  /* min/max aggregates seen.  See note above */
 16497         -#define NC_Complex   0x2000  /* True if a function or subquery seen */
 16498  16488   
 16499  16489   /*
 16500  16490   ** An instance of the following structure contains all information
 16501  16491   ** needed to generate code for a single SELECT statement.
 16502  16492   **
 16503  16493   ** nLimit is set to -1 if there is no LIMIT clause.  nOffset is set to 0.
 16504  16494   ** If there is a LIMIT clause, the parser sets nLimit to the value of the
................................................................................
 16561  16551   #define SF_NestedFrom     0x00800  /* Part of a parenthesized FROM clause */
 16562  16552   #define SF_MinMaxAgg      0x01000  /* Aggregate containing min() or max() */
 16563  16553   #define SF_Recursive      0x02000  /* The recursive part of a recursive CTE */
 16564  16554   #define SF_FixedLimit     0x04000  /* nSelectRow set by a constant LIMIT */
 16565  16555   #define SF_MaybeConvert   0x08000  /* Need convertCompoundSelectToSubquery() */
 16566  16556   #define SF_Converted      0x10000  /* By convertCompoundSelectToSubquery() */
 16567  16557   #define SF_IncludeHidden  0x20000  /* Include hidden columns in output */
 16568         -#define SF_ComplexResult  0x40000  /* Result set contains subquery or function */
 16569  16558   
 16570  16559   
 16571  16560   /*
 16572  16561   ** The results of a SELECT can be distributed in several ways, as defined
 16573  16562   ** by one of the following macros.  The "SRT" prefix means "SELECT Result
 16574  16563   ** Type".
 16575  16564   **
................................................................................
 17545  17534   SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*);
 17546  17535   SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*);
 17547  17536   SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int);
 17548  17537   SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
 17549  17538   #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
 17550  17539   SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,Expr*,char*);
 17551  17540   #endif
 17552         -SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*, ExprList*, Expr*, Expr*);
 17553         -SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*,Expr*,int,ExprList*,Expr*,Expr*);
        17541  +SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
        17542  +SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
 17554  17543   SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,ExprList*,u16,int);
 17555  17544   SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
 17556  17545   SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
 17557  17546   SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
 17558  17547   SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
 17559  17548   SQLITE_PRIVATE int sqlite3WhereOrderedInnerLoop(WhereInfo*);
 17560  17549   SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
................................................................................
 17670  17659   SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void);
 17671  17660   SQLITE_PRIVATE void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*);
 17672  17661   SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3*);
 17673  17662   SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*);
 17674  17663   SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int);
 17675  17664   
 17676  17665   #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
 17677         -SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, ExprList*,Expr*,Expr*,int);
        17666  +SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, int);
 17678  17667   #endif
 17679  17668   
 17680  17669   #ifndef SQLITE_OMIT_TRIGGER
 17681  17670   SQLITE_PRIVATE   void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,SrcList*,
 17682  17671                              Expr*,int, int);
 17683  17672   SQLITE_PRIVATE   void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*);
 17684  17673   SQLITE_PRIVATE   void sqlite3DropTrigger(Parse*, SrcList*, int);
................................................................................
 26634  26623     StrAccum acc;
 26635  26624     char zBuf[500];
 26636  26625     sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
 26637  26626     va_start(ap,zFormat);
 26638  26627     sqlite3VXPrintf(&acc, zFormat, ap);
 26639  26628     va_end(ap);
 26640  26629     sqlite3StrAccumFinish(&acc);
 26641         -#ifdef SQLITE_OS_TRACE_PROC
 26642         -  {
 26643         -    extern void SQLITE_OS_TRACE_PROC(const char *zBuf, int nBuf);
 26644         -    SQLITE_OS_TRACE_PROC(zBuf, sizeof(zBuf));
 26645         -  }
 26646         -#else
 26647  26630     fprintf(stdout,"%s", zBuf);
 26648  26631     fflush(stdout);
 26649         -#endif
 26650  26632   }
 26651  26633   #endif
 26652  26634   
 26653  26635   
 26654  26636   /*
 26655  26637   ** variable-argument wrapper around sqlite3VXPrintf().  The bFlags argument
 26656  26638   ** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats.
................................................................................
 28532  28514     }else if( *z=='+' ){
 28533  28515       z+=incr;
 28534  28516     }
 28535  28517   
 28536  28518     /* copy max significant digits to significand */
 28537  28519     while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
 28538  28520       s = s*10 + (*z - '0');
 28539         -    z+=incr; nDigits++;
        28521  +    z+=incr, nDigits++;
 28540  28522     }
 28541  28523   
 28542  28524     /* skip non-significant significand digits
 28543  28525     ** (increase exponent by d to shift decimal left) */
 28544         -  while( z<zEnd && sqlite3Isdigit(*z) ){ z+=incr; nDigits++; d++; }
        28526  +  while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++, d++;
 28545  28527     if( z>=zEnd ) goto do_atof_calc;
 28546  28528   
 28547  28529     /* if decimal point is present */
 28548  28530     if( *z=='.' ){
 28549  28531       z+=incr;
 28550  28532       /* copy digits from after decimal to significand
 28551  28533       ** (decrease exponent by d to shift decimal right) */
 28552  28534       while( z<zEnd && sqlite3Isdigit(*z) ){
 28553  28535         if( s<((LARGEST_INT64-9)/10) ){
 28554  28536           s = s*10 + (*z - '0');
 28555  28537           d--;
 28556  28538         }
 28557         -      z+=incr; nDigits++;
        28539  +      z+=incr, nDigits++;
 28558  28540       }
 28559  28541     }
 28560  28542     if( z>=zEnd ) goto do_atof_calc;
 28561  28543   
 28562  28544     /* if exponent is present */
 28563  28545     if( *z=='e' || *z=='E' ){
 28564  28546       z+=incr;
................................................................................
 30897  30879   #if defined(HAVE_LSTAT)
 30898  30880     { "lstat",         (sqlite3_syscall_ptr)lstat,          0 },
 30899  30881   #else
 30900  30882     { "lstat",         (sqlite3_syscall_ptr)0,              0 },
 30901  30883   #endif
 30902  30884   #define osLstat      ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent)
 30903  30885   
 30904         -#if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
 30905  30886     { "ioctl",         (sqlite3_syscall_ptr)ioctl,          0 },
 30906         -#else
 30907         -  { "ioctl",         (sqlite3_syscall_ptr)0,              0 },
 30908         -#endif
 30909  30887   #define osIoctl ((int(*)(int,int,...))aSyscall[28].pCurrent)
 30910  30888   
 30911  30889   }; /* End of the overrideable system calls */
 30912  30890   
 30913  30891   
 30914  30892   /*
 30915  30893   ** On some systems, calls to fchown() will trigger a message in a security
................................................................................
 34492  34470     unixInodeInfo *pInode;     /* unixInodeInfo that owns this SHM node */
 34493  34471     sqlite3_mutex *mutex;      /* Mutex to access this object */
 34494  34472     char *zFilename;           /* Name of the mmapped file */
 34495  34473     int h;                     /* Open file descriptor */
 34496  34474     int szRegion;              /* Size of shared-memory regions */
 34497  34475     u16 nRegion;               /* Size of array apRegion */
 34498  34476     u8 isReadonly;             /* True if read-only */
 34499         -  u8 isUnlocked;             /* True if no DMS lock held */
 34500  34477     char **apRegion;           /* Array of mapped shared-memory regions */
 34501  34478     int nRef;                  /* Number of unixShm objects pointing to this */
 34502  34479     unixShm *pFirst;           /* All unixShm objects pointing to this */
 34503  34480   #ifdef SQLITE_DEBUG
 34504  34481     u8 exclMask;               /* Mask of exclusive locks held */
 34505  34482     u8 sharedMask;             /* Mask of shared locks held */
 34506  34483     u8 nextShmId;              /* Next available unixShm.id value */
................................................................................
 34655  34632         p->h = -1;
 34656  34633       }
 34657  34634       p->pInode->pShmNode = 0;
 34658  34635       sqlite3_free(p);
 34659  34636     }
 34660  34637   }
 34661  34638   
 34662         -/*
 34663         -** The DMS lock has not yet been taken on shm file pShmNode. Attempt to
 34664         -** take it now. Return SQLITE_OK if successful, or an SQLite error
 34665         -** code otherwise.
 34666         -**
 34667         -** If the DMS cannot be locked because this is a readonly_shm=1 
 34668         -** connection and no other process already holds a lock, return
 34669         -** SQLITE_READONLY_CANTINIT and set pShmNode->isUnlocked=1.
 34670         -*/
 34671         -static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode){
 34672         -  struct flock lock;
 34673         -  int rc = SQLITE_OK;
 34674         -
 34675         -  /* Use F_GETLK to determine the locks other processes are holding
 34676         -  ** on the DMS byte. If it indicates that another process is holding
 34677         -  ** a SHARED lock, then this process may also take a SHARED lock
 34678         -  ** and proceed with opening the *-shm file. 
 34679         -  **
 34680         -  ** Or, if no other process is holding any lock, then this process
 34681         -  ** is the first to open it. In this case take an EXCLUSIVE lock on the
 34682         -  ** DMS byte and truncate the *-shm file to zero bytes in size. Then
 34683         -  ** downgrade to a SHARED lock on the DMS byte.
 34684         -  **
 34685         -  ** If another process is holding an EXCLUSIVE lock on the DMS byte,
 34686         -  ** return SQLITE_BUSY to the caller (it will try again). An earlier
 34687         -  ** version of this code attempted the SHARED lock at this point. But
 34688         -  ** this introduced a subtle race condition: if the process holding
 34689         -  ** EXCLUSIVE failed just before truncating the *-shm file, then this
 34690         -  ** process might open and use the *-shm file without truncating it.
 34691         -  ** And if the *-shm file has been corrupted by a power failure or
 34692         -  ** system crash, the database itself may also become corrupt.  */
 34693         -  lock.l_whence = SEEK_SET;
 34694         -  lock.l_start = UNIX_SHM_DMS;
 34695         -  lock.l_len = 1;
 34696         -  lock.l_type = F_WRLCK;
 34697         -  if( osFcntl(pShmNode->h, F_GETLK, &lock)!=0 ) {
 34698         -    rc = SQLITE_IOERR_LOCK;
 34699         -  }else if( lock.l_type==F_UNLCK ){
 34700         -    if( pShmNode->isReadonly ){
 34701         -      pShmNode->isUnlocked = 1;
 34702         -      rc = SQLITE_READONLY_CANTINIT;
 34703         -    }else{
 34704         -      rc = unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1);
 34705         -      if( rc==SQLITE_OK && robust_ftruncate(pShmNode->h, 0) ){
 34706         -        rc = unixLogError(SQLITE_IOERR_SHMOPEN,"ftruncate",pShmNode->zFilename);
 34707         -      }
 34708         -    }
 34709         -  }else if( lock.l_type==F_WRLCK ){
 34710         -    rc = SQLITE_BUSY;
 34711         -  }
 34712         -
 34713         -  if( rc==SQLITE_OK ){
 34714         -    assert( lock.l_type==F_UNLCK || lock.l_type==F_RDLCK );
 34715         -    rc = unixShmSystemLock(pDbFd, F_RDLCK, UNIX_SHM_DMS, 1);
 34716         -  }
 34717         -  return rc;
 34718         -}
 34719         -
 34720  34639   /*
 34721  34640   ** Open a shared-memory area associated with open database file pDbFd.  
 34722  34641   ** This particular implementation uses mmapped files.
 34723  34642   **
 34724  34643   ** The file used to implement shared-memory is in the same directory
 34725  34644   ** as the open database file and has the same name as the open database
 34726  34645   ** file with the "-shm" suffix added.  For example, if the database file
................................................................................
 34751  34670   ** that no other processes are able to read or write the database.  In
 34752  34671   ** that case, we do not really need shared memory.  No shared memory
 34753  34672   ** file is created.  The shared memory will be simulated with heap memory.
 34754  34673   */
 34755  34674   static int unixOpenSharedMemory(unixFile *pDbFd){
 34756  34675     struct unixShm *p = 0;          /* The connection to be opened */
 34757  34676     struct unixShmNode *pShmNode;   /* The underlying mmapped file */
 34758         -  int rc = SQLITE_OK;             /* Result code */
        34677  +  int rc;                         /* Result code */
 34759  34678     unixInodeInfo *pInode;          /* The inode of fd */
 34760         -  char *zShm;             /* Name of the file used for SHM */
        34679  +  char *zShmFilename;             /* Name of the file used for SHM */
 34761  34680     int nShmFilename;               /* Size of the SHM filename in bytes */
 34762  34681   
 34763  34682     /* Allocate space for the new unixShm object. */
 34764  34683     p = sqlite3_malloc64( sizeof(*p) );
 34765  34684     if( p==0 ) return SQLITE_NOMEM_BKPT;
 34766  34685     memset(p, 0, sizeof(*p));
 34767  34686     assert( pDbFd->pShm==0 );
................................................................................
 34794  34713   #endif
 34795  34714       pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename );
 34796  34715       if( pShmNode==0 ){
 34797  34716         rc = SQLITE_NOMEM_BKPT;
 34798  34717         goto shm_open_err;
 34799  34718       }
 34800  34719       memset(pShmNode, 0, sizeof(*pShmNode)+nShmFilename);
 34801         -    zShm = pShmNode->zFilename = (char*)&pShmNode[1];
        34720  +    zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1];
 34802  34721   #ifdef SQLITE_SHM_DIRECTORY
 34803         -    sqlite3_snprintf(nShmFilename, zShm, 
        34722  +    sqlite3_snprintf(nShmFilename, zShmFilename, 
 34804  34723                        SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
 34805  34724                        (u32)sStat.st_ino, (u32)sStat.st_dev);
 34806  34725   #else
 34807         -    sqlite3_snprintf(nShmFilename, zShm, "%s-shm", zBasePath);
 34808         -    sqlite3FileSuffix3(pDbFd->zPath, zShm);
        34726  +    sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", zBasePath);
        34727  +    sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
 34809  34728   #endif
 34810  34729       pShmNode->h = -1;
 34811  34730       pDbFd->pInode->pShmNode = pShmNode;
 34812  34731       pShmNode->pInode = pDbFd->pInode;
 34813  34732       if( sqlite3GlobalConfig.bCoreMutex ){
 34814  34733         pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
 34815  34734         if( pShmNode->mutex==0 ){
 34816  34735           rc = SQLITE_NOMEM_BKPT;
 34817  34736           goto shm_open_err;
 34818  34737         }
 34819  34738       }
 34820  34739   
 34821  34740       if( pInode->bProcessLock==0 ){
 34822         -      if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
 34823         -        pShmNode->h = robust_open(zShm, O_RDWR|O_CREAT, (sStat.st_mode&0777));
        34741  +      int openFlags = O_RDWR | O_CREAT;
        34742  +      if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
        34743  +        openFlags = O_RDONLY;
        34744  +        pShmNode->isReadonly = 1;
 34824  34745         }
        34746  +      pShmNode->h = robust_open(zShmFilename, openFlags, (sStat.st_mode&0777));
 34825  34747         if( pShmNode->h<0 ){
 34826         -        pShmNode->h = robust_open(zShm, O_RDONLY, (sStat.st_mode&0777));
 34827         -        if( pShmNode->h<0 ){
 34828         -          rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShm);
 34829         -          goto shm_open_err;
 34830         -        }
 34831         -        pShmNode->isReadonly = 1;
        34748  +        rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShmFilename);
        34749  +        goto shm_open_err;
 34832  34750         }
 34833  34751   
 34834  34752         /* If this process is running as root, make sure that the SHM file
 34835  34753         ** is owned by the same user that owns the original database.  Otherwise,
 34836  34754         ** the original owner will not be able to connect.
 34837  34755         */
 34838  34756         robustFchown(pShmNode->h, sStat.st_uid, sStat.st_gid);
 34839         -
 34840         -      rc = unixLockSharedMemory(pDbFd, pShmNode);
 34841         -      if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err;
        34757  +  
        34758  +      /* Check to see if another process is holding the dead-man switch.
        34759  +      ** If not, truncate the file to zero length. 
        34760  +      */
        34761  +      rc = SQLITE_OK;
        34762  +      if( unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
        34763  +        if( robust_ftruncate(pShmNode->h, 0) ){
        34764  +          rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename);
        34765  +        }
        34766  +      }
        34767  +      if( rc==SQLITE_OK ){
        34768  +        rc = unixShmSystemLock(pDbFd, F_RDLCK, UNIX_SHM_DMS, 1);
        34769  +      }
        34770  +      if( rc ) goto shm_open_err;
 34842  34771       }
 34843  34772     }
 34844  34773   
 34845  34774     /* Make the new connection a child of the unixShmNode */
 34846  34775     p->pShmNode = pShmNode;
 34847  34776   #ifdef SQLITE_DEBUG
 34848  34777     p->id = pShmNode->nextShmId++;
................................................................................
 34858  34787     ** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex 
 34859  34788     ** mutex.
 34860  34789     */
 34861  34790     sqlite3_mutex_enter(pShmNode->mutex);
 34862  34791     p->pNext = pShmNode->pFirst;
 34863  34792     pShmNode->pFirst = p;
 34864  34793     sqlite3_mutex_leave(pShmNode->mutex);
 34865         -  return rc;
        34794  +  return SQLITE_OK;
 34866  34795   
 34867  34796     /* Jump here on any error */
 34868  34797   shm_open_err:
 34869  34798     unixShmPurge(pDbFd);       /* This call frees pShmNode if required */
 34870  34799     sqlite3_free(p);
 34871  34800     unixLeaveMutex();
 34872  34801     return rc;
................................................................................
 34910  34839       rc = unixOpenSharedMemory(pDbFd);
 34911  34840       if( rc!=SQLITE_OK ) return rc;
 34912  34841     }
 34913  34842   
 34914  34843     p = pDbFd->pShm;
 34915  34844     pShmNode = p->pShmNode;
 34916  34845     sqlite3_mutex_enter(pShmNode->mutex);
 34917         -  if( pShmNode->isUnlocked ){
 34918         -    rc = unixLockSharedMemory(pDbFd, pShmNode);
 34919         -    if( rc!=SQLITE_OK ) goto shmpage_out;
 34920         -    pShmNode->isUnlocked = 0;
 34921         -  }
 34922  34846     assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
 34923  34847     assert( pShmNode->pInode==pDbFd->pInode );
 34924  34848     assert( pShmNode->h>=0 || pDbFd->pInode->bProcessLock==1 );
 34925  34849     assert( pShmNode->h<0 || pDbFd->pInode->bProcessLock==0 );
 34926  34850   
 34927  34851     /* Minimum number of regions required to be mapped. */
 34928  34852     nReqRegion = ((iRegion+nShmPerMap) / nShmPerMap) * nShmPerMap;
................................................................................
 41989  41913   struct winShmNode {
 41990  41914     sqlite3_mutex *mutex;      /* Mutex to access this object */
 41991  41915     char *zFilename;           /* Name of the file */
 41992  41916     winFile hFile;             /* File handle from winOpen */
 41993  41917   
 41994  41918     int szRegion;              /* Size of shared-memory regions */
 41995  41919     int nRegion;               /* Size of array apRegion */
 41996         -  u8 isReadonly;             /* True if read-only */
 41997         -  u8 isUnlocked;             /* True if no DMS lock held */
 41998         -
 41999  41920     struct ShmRegion {
 42000  41921       HANDLE hMap;             /* File handle from CreateFileMapping */
 42001  41922       void *pMap;
 42002  41923     } *aRegion;
 42003  41924     DWORD lastErrno;           /* The Windows errno from the last I/O error */
 42004  41925   
 42005  41926     int nRef;                  /* Number of winShm objects pointing to this */
................................................................................
 42139  42060         sqlite3_free(p);
 42140  42061       }else{
 42141  42062         pp = &p->pNext;
 42142  42063       }
 42143  42064     }
 42144  42065   }
 42145  42066   
 42146         -/*
 42147         -** The DMS lock has not yet been taken on shm file pShmNode. Attempt to
 42148         -** take it now. Return SQLITE_OK if successful, or an SQLite error
 42149         -** code otherwise.
 42150         -**
 42151         -** If the DMS cannot be locked because this is a readonly_shm=1
 42152         -** connection and no other process already holds a lock, return
 42153         -** SQLITE_READONLY_CANTINIT and set pShmNode->isUnlocked=1.
 42154         -*/
 42155         -static int winLockSharedMemory(winShmNode *pShmNode){
 42156         -  int rc = winShmSystemLock(pShmNode, WINSHM_WRLCK, WIN_SHM_DMS, 1);
 42157         -
 42158         -  if( rc==SQLITE_OK ){
 42159         -    if( pShmNode->isReadonly ){
 42160         -      pShmNode->isUnlocked = 1;
 42161         -      winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
 42162         -      return SQLITE_READONLY_CANTINIT;
 42163         -    }else if( winTruncate((sqlite3_file*)&pShmNode->hFile, 0) ){
 42164         -      winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
 42165         -      return winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(),
 42166         -                         "winLockSharedMemory", pShmNode->zFilename);
 42167         -    }
 42168         -  }
 42169         -
 42170         -  if( rc==SQLITE_OK ){
 42171         -    winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
 42172         -  }
 42173         -
 42174         -  return winShmSystemLock(pShmNode, WINSHM_RDLCK, WIN_SHM_DMS, 1);
 42175         -}
 42176         -
 42177  42067   /*
 42178  42068   ** Open the shared-memory area associated with database file pDbFd.
 42179  42069   **
 42180  42070   ** When opening a new shared-memory file, if no other instances of that
 42181  42071   ** file are currently open, in this process or in other processes, then
 42182  42072   ** the file must be truncated to zero length or have its header cleared.
 42183  42073   */
 42184  42074   static int winOpenSharedMemory(winFile *pDbFd){
 42185  42075     struct winShm *p;                  /* The connection to be opened */
 42186         -  winShmNode *pShmNode = 0;          /* The underlying mmapped file */
 42187         -  int rc = SQLITE_OK;                /* Result code */
 42188         -  int rc2 = SQLITE_ERROR;            /* winOpen result code */
 42189         -  winShmNode *pNew;                  /* Newly allocated winShmNode */
        42076  +  struct winShmNode *pShmNode = 0;   /* The underlying mmapped file */
        42077  +  int rc;                            /* Result code */
        42078  +  struct winShmNode *pNew;           /* Newly allocated winShmNode */
 42190  42079     int nName;                         /* Size of zName in bytes */
 42191  42080   
 42192  42081     assert( pDbFd->pShm==0 );    /* Not previously opened */
 42193  42082   
 42194  42083     /* Allocate space for the new sqlite3_shm object.  Also speculatively
 42195  42084     ** allocate space for a new winShmNode and filename.
 42196  42085     */
................................................................................
 42229  42118         pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
 42230  42119         if( pShmNode->mutex==0 ){
 42231  42120           rc = SQLITE_IOERR_NOMEM_BKPT;
 42232  42121           goto shm_open_err;
 42233  42122         }
 42234  42123       }
 42235  42124   
 42236         -    if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
 42237         -      rc2 = winOpen(pDbFd->pVfs,
 42238         -                    pShmNode->zFilename,
 42239         -                    (sqlite3_file*)&pShmNode->hFile,
 42240         -                    SQLITE_OPEN_WAL|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE,
 42241         -                    0);
 42242         -    }
 42243         -    if( rc2!=SQLITE_OK ){
 42244         -      rc2 = winOpen(pDbFd->pVfs,
 42245         -                    pShmNode->zFilename,
 42246         -                    (sqlite3_file*)&pShmNode->hFile,
 42247         -                    SQLITE_OPEN_WAL|SQLITE_OPEN_READONLY,
 42248         -                    0);
 42249         -      if( rc2!=SQLITE_OK ){
 42250         -        rc = winLogError(rc2, osGetLastError(), "winOpenShm",
 42251         -                         pShmNode->zFilename);
 42252         -        goto shm_open_err;
 42253         -      }
 42254         -      pShmNode->isReadonly = 1;
 42255         -    }
 42256         -
 42257         -    rc = winLockSharedMemory(pShmNode);
 42258         -    if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err;
        42125  +    rc = winOpen(pDbFd->pVfs,
        42126  +                 pShmNode->zFilename,             /* Name of the file (UTF-8) */
        42127  +                 (sqlite3_file*)&pShmNode->hFile,  /* File handle here */
        42128  +                 SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
        42129  +                 0);
        42130  +    if( SQLITE_OK!=rc ){
        42131  +      goto shm_open_err;
        42132  +    }
        42133  +
        42134  +    /* Check to see if another process is holding the dead-man switch.
        42135  +    ** If not, truncate the file to zero length.
        42136  +    */
        42137  +    if( winShmSystemLock(pShmNode, WINSHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){
        42138  +      rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0);
        42139  +      if( rc!=SQLITE_OK ){
        42140  +        rc = winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(),
        42141  +                         "winOpenShm", pDbFd->zPath);
        42142  +      }
        42143  +    }
        42144  +    if( rc==SQLITE_OK ){
        42145  +      winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
        42146  +      rc = winShmSystemLock(pShmNode, WINSHM_RDLCK, WIN_SHM_DMS, 1);
        42147  +    }
        42148  +    if( rc ) goto shm_open_err;
 42259  42149     }
 42260  42150   
 42261  42151     /* Make the new connection a child of the winShmNode */
 42262  42152     p->pShmNode = pShmNode;
 42263  42153   #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
 42264  42154     p->id = pShmNode->nextShmId++;
 42265  42155   #endif
................................................................................
 42274  42164     ** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex
 42275  42165     ** mutex.
 42276  42166     */
 42277  42167     sqlite3_mutex_enter(pShmNode->mutex);
 42278  42168     p->pNext = pShmNode->pFirst;
 42279  42169     pShmNode->pFirst = p;
 42280  42170     sqlite3_mutex_leave(pShmNode->mutex);
 42281         -  return rc;
        42171  +  return SQLITE_OK;
 42282  42172   
 42283  42173     /* Jump here on any error */
 42284  42174   shm_open_err:
 42285  42175     winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
 42286  42176     winShmPurge(pDbFd->pVfs, 0);      /* This call frees pShmNode if required */
 42287  42177     sqlite3_free(p);
 42288  42178     sqlite3_free(pNew);
................................................................................
 42478  42368     int szRegion,                   /* Size of regions */
 42479  42369     int isWrite,                    /* True to extend file if necessary */
 42480  42370     void volatile **pp              /* OUT: Mapped memory */
 42481  42371   ){
 42482  42372     winFile *pDbFd = (winFile*)fd;
 42483  42373     winShm *pShm = pDbFd->pShm;
 42484  42374     winShmNode *pShmNode;
 42485         -  DWORD protect = PAGE_READWRITE;
 42486         -  DWORD flags = FILE_MAP_WRITE | FILE_MAP_READ;
 42487  42375     int rc = SQLITE_OK;
 42488  42376   
 42489  42377     if( !pShm ){
 42490  42378       rc = winOpenSharedMemory(pDbFd);
 42491  42379       if( rc!=SQLITE_OK ) return rc;
 42492  42380       pShm = pDbFd->pShm;
 42493  42381     }
 42494  42382     pShmNode = pShm->pShmNode;
 42495  42383   
 42496  42384     sqlite3_mutex_enter(pShmNode->mutex);
 42497         -  if( pShmNode->isUnlocked ){
 42498         -    rc = winLockSharedMemory(pShmNode);
 42499         -    if( rc!=SQLITE_OK ) goto shmpage_out;
 42500         -    pShmNode->isUnlocked = 0;
 42501         -  }
 42502  42385     assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
 42503  42386   
 42504  42387     if( pShmNode->nRegion<=iRegion ){
 42505  42388       struct ShmRegion *apNew;           /* New aRegion[] array */
 42506  42389       int nByte = (iRegion+1)*szRegion;  /* Minimum required file size */
 42507  42390       sqlite3_int64 sz;                  /* Current size of wal-index file */
 42508  42391   
................................................................................
 42541  42424       );
 42542  42425       if( !apNew ){
 42543  42426         rc = SQLITE_IOERR_NOMEM_BKPT;
 42544  42427         goto shmpage_out;
 42545  42428       }
 42546  42429       pShmNode->aRegion = apNew;
 42547  42430   
 42548         -    if( pShmNode->isReadonly ){
 42549         -      protect = PAGE_READONLY;
 42550         -      flags = FILE_MAP_READ;
 42551         -    }
 42552         -
 42553  42431       while( pShmNode->nRegion<=iRegion ){
 42554  42432         HANDLE hMap = NULL;         /* file-mapping handle */
 42555  42433         void *pMap = 0;             /* Mapped memory region */
 42556  42434   
 42557  42435   #if SQLITE_OS_WINRT
 42558  42436         hMap = osCreateFileMappingFromApp(pShmNode->hFile.h,
 42559         -          NULL, protect, nByte, NULL
        42437  +          NULL, PAGE_READWRITE, nByte, NULL
 42560  42438         );
 42561  42439   #elif defined(SQLITE_WIN32_HAS_WIDE)
 42562  42440         hMap = osCreateFileMappingW(pShmNode->hFile.h,
 42563         -          NULL, protect, 0, nByte, NULL
        42441  +          NULL, PAGE_READWRITE, 0, nByte, NULL
 42564  42442         );
 42565  42443   #elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA
 42566  42444         hMap = osCreateFileMappingA(pShmNode->hFile.h,
 42567         -          NULL, protect, 0, nByte, NULL
        42445  +          NULL, PAGE_READWRITE, 0, nByte, NULL
 42568  42446         );
 42569  42447   #endif
 42570  42448         OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n",
 42571  42449                  osGetCurrentProcessId(), pShmNode->nRegion, nByte,
 42572  42450                  hMap ? "ok" : "failed"));
 42573  42451         if( hMap ){
 42574  42452           int iOffset = pShmNode->nRegion*szRegion;
 42575  42453           int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
 42576  42454   #if SQLITE_OS_WINRT
 42577         -        pMap = osMapViewOfFileFromApp(hMap, flags,
        42455  +        pMap = osMapViewOfFileFromApp(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
 42578  42456               iOffset - iOffsetShift, szRegion + iOffsetShift
 42579  42457           );
 42580  42458   #else
 42581         -        pMap = osMapViewOfFile(hMap, flags,
        42459  +        pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
 42582  42460               0, iOffset - iOffsetShift, szRegion + iOffsetShift
 42583  42461           );
 42584  42462   #endif
 42585  42463           OSTRACE(("SHM-MAP-MAP pid=%lu, region=%d, offset=%d, size=%d, rc=%s\n",
 42586  42464                    osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
 42587  42465                    szRegion, pMap ? "ok" : "failed"));
 42588  42466         }
................................................................................
 42605  42483       int iOffset = iRegion*szRegion;
 42606  42484       int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
 42607  42485       char *p = (char *)pShmNode->aRegion[iRegion].pMap;
 42608  42486       *pp = (void *)&p[iOffsetShift];
 42609  42487     }else{
 42610  42488       *pp = 0;
 42611  42489     }
 42612         -  if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY;
 42613  42490     sqlite3_mutex_leave(pShmNode->mutex);
 42614  42491     return rc;
 42615  42492   }
 42616  42493   
 42617  42494   #else
 42618  42495   # define winShmMap     0
 42619  42496   # define winShmLock    0
................................................................................
 45375  45252   
 45376  45253   /*
 45377  45254   ** Make sure the page is marked as clean. If it isn't clean already,
 45378  45255   ** make it so.
 45379  45256   */
 45380  45257   SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr *p){
 45381  45258     assert( sqlite3PcachePageSanity(p) );
 45382         -  assert( (p->flags & PGHDR_DIRTY)!=0 );
 45383         -  assert( (p->flags & PGHDR_CLEAN)==0 );
 45384         -  pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
 45385         -  p->flags &= ~(PGHDR_DIRTY|PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
 45386         -  p->flags |= PGHDR_CLEAN;
 45387         -  pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
 45388         -  assert( sqlite3PcachePageSanity(p) );
 45389         -  if( p->nRef==0 ){
 45390         -    pcacheUnpin(p);
        45259  +  if( ALWAYS((p->flags & PGHDR_DIRTY)!=0) ){
        45260  +    assert( (p->flags & PGHDR_CLEAN)==0 );
        45261  +    pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
        45262  +    p->flags &= ~(PGHDR_DIRTY|PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
        45263  +    p->flags |= PGHDR_CLEAN;
        45264  +    pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
        45265  +    assert( sqlite3PcachePageSanity(p) );
        45266  +    if( p->nRef==0 ){
        45267  +      pcacheUnpin(p);
        45268  +    }
 45391  45269     }
 45392  45270   }
 45393  45271   
 45394  45272   /*
 45395  45273   ** Make every page in the cache clean.
 45396  45274   */
 45397  45275   SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
................................................................................
 55364  55242   **
 55365  55243   ** Conceptually, the wal-index is shared memory, though VFS implementations
 55366  55244   ** might choose to implement the wal-index using a mmapped file.  Because
 55367  55245   ** the wal-index is shared memory, SQLite does not support journal_mode=WAL 
 55368  55246   ** on a network filesystem.  All users of the database must be able to
 55369  55247   ** share memory.
 55370  55248   **
 55371         -** In the default unix and windows implementation, the wal-index is a mmapped
 55372         -** file whose name is the database name with a "-shm" suffix added.  For that
 55373         -** reason, the wal-index is sometimes called the "shm" file.
 55374         -**
 55375  55249   ** The wal-index is transient.  After a crash, the wal-index can (and should
 55376  55250   ** be) reconstructed from the original WAL file.  In fact, the VFS is required
 55377  55251   ** to either truncate or zero the header of the wal-index when the last
 55378  55252   ** connection to it closes.  Because the wal-index is transient, it can
 55379  55253   ** use an architecture-specific format; it does not have to be cross-platform.
 55380  55254   ** Hence, unlike the database and WAL file formats which store all values
 55381  55255   ** as big endian, the wal-index can store multi-byte values in the native
................................................................................
 55507  55381   ** WALINDEX_MAX_VERSION, then no read-transaction is opened and SQLite
 55508  55382   ** returns SQLITE_CANTOPEN.
 55509  55383   */
 55510  55384   #define WAL_MAX_VERSION      3007000
 55511  55385   #define WALINDEX_MAX_VERSION 3007000
 55512  55386   
 55513  55387   /*
 55514         -** Index numbers for various locking bytes.   WAL_NREADER is the number
        55388  +** Indices of various locking bytes.   WAL_NREADER is the number
 55515  55389   ** of available reader locks and should be at least 3.  The default
 55516  55390   ** is SQLITE_SHM_NLOCK==8 and  WAL_NREADER==5.
 55517         -**
 55518         -** Technically, the various VFSes are free to implement these locks however
 55519         -** they see fit.  However, compatibility is encouraged so that VFSes can
 55520         -** interoperate.  The standard implemention used on both unix and windows
 55521         -** is for the index number to indicate a byte offset into the
 55522         -** WalCkptInfo.aLock[] array in the wal-index header.  In other words, all
 55523         -** locks are on the shm file.  The WALINDEX_LOCK_OFFSET constant (which
 55524         -** should be 120) is the location in the shm file for the first locking
 55525         -** byte.
 55526  55391   */
 55527  55392   #define WAL_WRITE_LOCK         0
 55528  55393   #define WAL_ALL_BUT_WRITE      1
 55529  55394   #define WAL_CKPT_LOCK          1
 55530  55395   #define WAL_RECOVER_LOCK       2
 55531  55396   #define WAL_READ_LOCK(I)       (3+(I))
 55532  55397   #define WAL_NREADER            (SQLITE_SHM_NLOCK-3)
................................................................................
 55642  55507   #define WALINDEX_LOCK_OFFSET (sizeof(WalIndexHdr)*2+offsetof(WalCkptInfo,aLock))
 55643  55508   #define WALINDEX_HDR_SIZE    (sizeof(WalIndexHdr)*2+sizeof(WalCkptInfo))
 55644  55509   
 55645  55510   /* Size of header before each frame in wal */
 55646  55511   #define WAL_FRAME_HDRSIZE 24
 55647  55512   
 55648  55513   /* Size of write ahead log header, including checksum. */
        55514  +/* #define WAL_HDRSIZE 24 */
 55649  55515   #define WAL_HDRSIZE 32
 55650  55516   
 55651  55517   /* WAL magic value. Either this value, or the same value with the least
 55652  55518   ** significant bit also set (WAL_MAGIC | 0x00000001) is stored in 32-bit
 55653  55519   ** big-endian format in the first 4 bytes of a WAL file.
 55654  55520   **
 55655  55521   ** If the LSB is set, then the checksums for each frame within the WAL
................................................................................
 55687  55553     u8 exclusiveMode;          /* Non-zero if connection is in exclusive mode */
 55688  55554     u8 writeLock;              /* True if in a write transaction */
 55689  55555     u8 ckptLock;               /* True if holding a checkpoint lock */
 55690  55556     u8 readOnly;               /* WAL_RDWR, WAL_RDONLY, or WAL_SHM_RDONLY */
 55691  55557     u8 truncateOnCommit;       /* True to truncate WAL file on commit */
 55692  55558     u8 syncHeader;             /* Fsync the WAL header if true */
 55693  55559     u8 padToSectorBoundary;    /* Pad transactions out to the next sector */
 55694         -  u8 bShmUnreliable;         /* SHM content is read-only and unreliable */
 55695  55560     WalIndexHdr hdr;           /* Wal-index header for current transaction */
 55696  55561     u32 minFrame;              /* Ignore wal frames before this one */
 55697  55562     u32 iReCksum;              /* On commit, recalculate checksums from here */
 55698  55563     const char *zWalName;      /* Name of WAL file */
 55699  55564     u32 nCkpt;                 /* Checkpoint sequence counter in the wal-header */
 55700  55565   #ifdef SQLITE_DEBUG
 55701  55566     u8 lockError;              /* True if a locking error has occurred */
................................................................................
 55777  55642   )
 55778  55643   
 55779  55644   /*
 55780  55645   ** Obtain a pointer to the iPage'th page of the wal-index. The wal-index
 55781  55646   ** is broken into pages of WALINDEX_PGSZ bytes. Wal-index pages are
 55782  55647   ** numbered from zero.
 55783  55648   **
 55784         -** If the wal-index is currently smaller the iPage pages then the size
 55785         -** of the wal-index might be increased, but only if it is safe to do
 55786         -** so.  It is safe to enlarge the wal-index if pWal->writeLock is true
 55787         -** or pWal->exclusiveMode==WAL_HEAPMEMORY_MODE.
 55788         -**
 55789  55649   ** If this call is successful, *ppPage is set to point to the wal-index
 55790  55650   ** page and SQLITE_OK is returned. If an error (an OOM or VFS error) occurs,
 55791  55651   ** then an SQLite error code is returned and *ppPage is set to 0.
 55792  55652   */
 55793  55653   static int walIndexPage(Wal *pWal, int iPage, volatile u32 **ppPage){
 55794  55654     int rc = SQLITE_OK;
 55795  55655   
................................................................................
 55813  55673       if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ){
 55814  55674         pWal->apWiData[iPage] = (u32 volatile *)sqlite3MallocZero(WALINDEX_PGSZ);
 55815  55675         if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT;
 55816  55676       }else{
 55817  55677         rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ, 
 55818  55678             pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
 55819  55679         );
 55820         -      assert( pWal->apWiData[iPage]!=0 || rc!=SQLITE_OK || pWal->writeLock==0 );
 55821         -      testcase( pWal->apWiData[iPage]==0 && rc==SQLITE_OK );
 55822         -      if( (rc&0xff)==SQLITE_READONLY ){
        55680  +      if( rc==SQLITE_READONLY ){
 55823  55681           pWal->readOnly |= WAL_SHM_RDONLY;
 55824         -        if( rc==SQLITE_READONLY ){
 55825         -          rc = SQLITE_OK;
 55826         -        }
        55682  +        rc = SQLITE_OK;
 55827  55683         }
 55828  55684       }
 55829  55685     }
 55830  55686   
 55831  55687     *ppPage = pWal->apWiData[iPage];
 55832  55688     assert( iPage==0 || *ppPage || rc!=SQLITE_OK );
 55833  55689     return rc;
................................................................................
 56341  56197   ** the necessary locks, this routine returns SQLITE_BUSY.
 56342  56198   */
 56343  56199   static int walIndexRecover(Wal *pWal){
 56344  56200     int rc;                         /* Return Code */
 56345  56201     i64 nSize;                      /* Size of log file */
 56346  56202     u32 aFrameCksum[2] = {0, 0};
 56347  56203     int iLock;                      /* Lock offset to lock for checkpoint */
        56204  +  int nLock;                      /* Number of locks to hold */
 56348  56205   
 56349  56206     /* Obtain an exclusive lock on all byte in the locking range not already
 56350  56207     ** locked by the caller. The caller is guaranteed to have locked the
 56351  56208     ** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte.
 56352  56209     ** If successful, the same bytes that are locked here are unlocked before
 56353  56210     ** this function returns.
 56354  56211     */
 56355  56212     assert( pWal->ckptLock==1 || pWal->ckptLock==0 );
 56356  56213     assert( WAL_ALL_BUT_WRITE==WAL_WRITE_LOCK+1 );
 56357  56214     assert( WAL_CKPT_LOCK==WAL_ALL_BUT_WRITE );
 56358  56215     assert( pWal->writeLock );
 56359  56216     iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock;
 56360         -  rc = walLockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
 56361         -  if( rc==SQLITE_OK ){
 56362         -    rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
 56363         -    if( rc!=SQLITE_OK ){
 56364         -      walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
 56365         -    }
 56366         -  }
        56217  +  nLock = SQLITE_SHM_NLOCK - iLock;
        56218  +  rc = walLockExclusive(pWal, iLock, nLock);
 56367  56219     if( rc ){
 56368  56220       return rc;
 56369  56221     }
 56370         -
 56371  56222     WALTRACE(("WAL%p: recovery begin...\n", pWal));
 56372  56223   
 56373  56224     memset(&pWal->hdr, 0, sizeof(WalIndexHdr));
 56374  56225   
 56375  56226     rc = sqlite3OsFileSize(pWal->pWalFd, &nSize);
 56376  56227     if( rc!=SQLITE_OK ){
 56377  56228       goto recovery_error;
................................................................................
 56501  56352             pWal->hdr.mxFrame, pWal->zWalName
 56502  56353         );
 56503  56354       }
 56504  56355     }
 56505  56356   
 56506  56357   recovery_error:
 56507  56358     WALTRACE(("WAL%p: recovery %s\n", pWal, rc ? "failed" : "ok"));
 56508         -  walUnlockExclusive(pWal, iLock, WAL_READ_LOCK(0)-iLock);
 56509         -  walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
        56359  +  walUnlockExclusive(pWal, iLock, nLock);
 56510  56360     return rc;
 56511  56361   }
 56512  56362   
 56513  56363   /*
 56514  56364   ** Close an open wal-index.
 56515  56365   */
 56516  56366   static void walIndexClose(Wal *pWal, int isDelete){
 56517         -  if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE || pWal->bShmUnreliable ){
        56367  +  if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ){
 56518  56368       int i;
 56519  56369       for(i=0; i<pWal->nWiData; i++){
 56520  56370         sqlite3_free((void *)pWal->apWiData[i]);
 56521  56371         pWal->apWiData[i] = 0;
 56522  56372       }
 56523         -  }
 56524         -  if( pWal->exclusiveMode!=WAL_HEAPMEMORY_MODE ){
        56373  +  }else{
 56525  56374       sqlite3OsShmUnmap(pWal->pDbFd, isDelete);
 56526  56375     }
 56527  56376   }
 56528  56377   
 56529  56378   /* 
 56530  56379   ** Open a connection to the WAL file zWalName. The database file must 
 56531  56380   ** already be opened on connection pDbFd. The buffer that zWalName points
................................................................................
 57310  57159       testcase( pWal->szPage>=65536 );
 57311  57160     }
 57312  57161   
 57313  57162     /* The header was successfully read. Return zero. */
 57314  57163     return 0;
 57315  57164   }
 57316  57165   
 57317         -/*
 57318         -** This is the value that walTryBeginRead returns when it needs to
 57319         -** be retried.
 57320         -*/
 57321         -#define WAL_RETRY  (-1)
 57322         -
 57323  57166   /*
 57324  57167   ** Read the wal-index header from the wal-index and into pWal->hdr.
 57325  57168   ** If the wal-header appears to be corrupt, try to reconstruct the
 57326  57169   ** wal-index from the WAL before returning.
 57327  57170   **
 57328  57171   ** Set *pChanged to 1 if the wal-index header value in pWal->hdr is
 57329  57172   ** changed by this operation.  If pWal->hdr is unchanged, set *pChanged
................................................................................
 57339  57182   
 57340  57183     /* Ensure that page 0 of the wal-index (the page that contains the 
 57341  57184     ** wal-index header) is mapped. Return early if an error occurs here.
 57342  57185     */
 57343  57186     assert( pChanged );
 57344  57187     rc = walIndexPage(pWal, 0, &page0);
 57345  57188     if( rc!=SQLITE_OK ){
 57346         -    assert( rc!=SQLITE_READONLY ); /* READONLY changed to OK in walIndexPage */
 57347         -    if( rc==SQLITE_READONLY_CANTINIT ){
 57348         -      /* The SQLITE_READONLY_CANTINIT return means that the shared-memory
 57349         -      ** was openable but is not writable, and this thread is unable to
 57350         -      ** confirm that another write-capable connection has the shared-memory
 57351         -      ** open, and hence the content of the shared-memory is unreliable,
 57352         -      ** since the shared-memory might be inconsistent with the WAL file
 57353         -      ** and there is no writer on hand to fix it. */
 57354         -      assert( page0==0 );
 57355         -      assert( pWal->writeLock==0 );
 57356         -      assert( pWal->readOnly & WAL_SHM_RDONLY );
 57357         -      pWal->bShmUnreliable = 1;
 57358         -      pWal->exclusiveMode = WAL_HEAPMEMORY_MODE;
 57359         -      *pChanged = 1;
 57360         -    }else{
 57361         -      return rc; /* Any other non-OK return is just an error */
 57362         -    }
 57363         -  }else{
 57364         -    /* page0 can be NULL if the SHM is zero bytes in size and pWal->writeLock
 57365         -    ** is zero, which prevents the SHM from growing */
 57366         -    testcase( page0!=0 );
 57367         -  }
 57368         -  assert( page0!=0 || pWal->writeLock==0 );
        57189  +    return rc;
        57190  +  };
        57191  +  assert( page0 || pWal->writeLock==0 );
 57369  57192   
 57370  57193     /* If the first page of the wal-index has been mapped, try to read the
 57371  57194     ** wal-index header immediately, without holding any lock. This usually
 57372  57195     ** works, but may fail if the wal-index header is corrupt or currently 
 57373  57196     ** being modified by another thread or process.
 57374  57197     */
 57375  57198     badHdr = (page0 ? walIndexTryHdr(pWal, pChanged) : 1);
 57376  57199   
 57377  57200     /* If the first attempt failed, it might have been due to a race
 57378  57201     ** with a writer.  So get a WRITE lock and try again.
 57379  57202     */
 57380  57203     assert( badHdr==0 || pWal->writeLock==0 );
 57381  57204     if( badHdr ){
 57382         -    if( pWal->bShmUnreliable==0 && (pWal->readOnly & WAL_SHM_RDONLY) ){
        57205  +    if( pWal->readOnly & WAL_SHM_RDONLY ){
 57383  57206         if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){
 57384  57207           walUnlockShared(pWal, WAL_WRITE_LOCK);
 57385  57208           rc = SQLITE_READONLY_RECOVERY;
 57386  57209         }
 57387  57210       }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){
 57388  57211         pWal->writeLock = 1;
 57389  57212         if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
................................................................................
 57405  57228     /* If the header is read successfully, check the version number to make
 57406  57229     ** sure the wal-index was not constructed with some future format that
 57407  57230     ** this version of SQLite cannot understand.
 57408  57231     */
 57409  57232     if( badHdr==0 && pWal->hdr.iVersion!=WALINDEX_MAX_VERSION ){
 57410  57233       rc = SQLITE_CANTOPEN_BKPT;
 57411  57234     }
 57412         -  if( pWal->bShmUnreliable ){
 57413         -    if( rc!=SQLITE_OK ){
 57414         -      walIndexClose(pWal, 0);
 57415         -      pWal->bShmUnreliable = 0;
 57416         -      assert( pWal->nWiData>0 && pWal->apWiData[0]==0 );
 57417         -      /* walIndexRecover() might have returned SHORT_READ if a concurrent
 57418         -      ** writer truncated the WAL out from under it.  If that happens, it
 57419         -      ** indicates that a writer has fixed the SHM file for us, so retry */
 57420         -      if( rc==SQLITE_IOERR_SHORT_READ ) rc = WAL_RETRY;
 57421         -    }
 57422         -    pWal->exclusiveMode = WAL_NORMAL_MODE;
 57423         -  }
 57424         -
 57425         -  return rc;
 57426         -}
 57427         -
 57428         -/*
 57429         -** Open a transaction in a connection where the shared-memory is read-only
 57430         -** and where we cannot verify that there is a separate write-capable connection
 57431         -** on hand to keep the shared-memory up-to-date with the WAL file.
 57432         -**
 57433         -** This can happen, for example, when the shared-memory is implemented by
 57434         -** memory-mapping a *-shm file, where a prior writer has shut down and
 57435         -** left the *-shm file on disk, and now the present connection is trying
 57436         -** to use that database but lacks write permission on the *-shm file.
 57437         -** Other scenarios are also possible, depending on the VFS implementation.
 57438         -**
 57439         -** Precondition:
 57440         -**
 57441         -**    The *-wal file has been read and an appropriate wal-index has been
 57442         -**    constructed in pWal->apWiData[] using heap memory instead of shared
 57443         -**    memory. 
 57444         -**
 57445         -** If this function returns SQLITE_OK, then the read transaction has
 57446         -** been successfully opened. In this case output variable (*pChanged) 
 57447         -** is set to true before returning if the caller should discard the
 57448         -** contents of the page cache before proceeding. Or, if it returns 
 57449         -** WAL_RETRY, then the heap memory wal-index has been discarded and 
 57450         -** the caller should retry opening the read transaction from the 
 57451         -** beginning (including attempting to map the *-shm file). 
 57452         -**
 57453         -** If an error occurs, an SQLite error code is returned.
 57454         -*/
 57455         -static int walBeginShmUnreliable(Wal *pWal, int *pChanged){
 57456         -  i64 szWal;                      /* Size of wal file on disk in bytes */
 57457         -  i64 iOffset;                    /* Current offset when reading wal file */
 57458         -  u8 aBuf[WAL_HDRSIZE];           /* Buffer to load WAL header into */
 57459         -  u8 *aFrame = 0;                 /* Malloc'd buffer to load entire frame */
 57460         -  int szFrame;                    /* Number of bytes in buffer aFrame[] */
 57461         -  u8 *aData;                      /* Pointer to data part of aFrame buffer */
 57462         -  volatile void *pDummy;          /* Dummy argument for xShmMap */
 57463         -  int rc;                         /* Return code */
 57464         -  u32 aSaveCksum[2];              /* Saved copy of pWal->hdr.aFrameCksum */
 57465         -
 57466         -  assert( pWal->bShmUnreliable );
 57467         -  assert( pWal->readOnly & WAL_SHM_RDONLY );
 57468         -  assert( pWal->nWiData>0 && pWal->apWiData[0] );
 57469         -
 57470         -  /* Take WAL_READ_LOCK(0). This has the effect of preventing any
 57471         -  ** writers from running a checkpoint, but does not stop them
 57472         -  ** from running recovery.  */
 57473         -  rc = walLockShared(pWal, WAL_READ_LOCK(0));
 57474         -  if( rc!=SQLITE_OK ){
 57475         -    if( rc==SQLITE_BUSY ) rc = WAL_RETRY;
 57476         -    goto begin_unreliable_shm_out;
 57477         -  }
 57478         -  pWal->readLock = 0;
 57479         -
 57480         -  /* Check to see if a separate writer has attached to the shared-memory area,
 57481         -  ** thus making the shared-memory "reliable" again.  Do this by invoking
 57482         -  ** the xShmMap() routine of the VFS and looking to see if the return
 57483         -  ** is SQLITE_READONLY instead of SQLITE_READONLY_CANTINIT.
 57484         -  **
 57485         -  ** If the shared-memory is now "reliable" return WAL_RETRY, which will
 57486         -  ** cause the heap-memory WAL-index to be discarded and the actual
 57487         -  ** shared memory to be used in its place.
 57488         -  **
 57489         -  ** This step is important because, even though this connection is holding
 57490         -  ** the WAL_READ_LOCK(0) which prevents a checkpoint, a writer might
 57491         -  ** have already checkpointed the WAL file and, while the current
 57492         -  ** is active, wrap the WAL and start overwriting frames that this
 57493         -  ** process wants to use.
 57494         -  **
 57495         -  ** Once sqlite3OsShmMap() has been called for an sqlite3_file and has
 57496         -  ** returned any SQLITE_READONLY value, it must return only SQLITE_READONLY
 57497         -  ** or SQLITE_READONLY_CANTINIT or some error for all subsequent invocations,
 57498         -  ** even if some external agent does a "chmod" to make the shared-memory
 57499         -  ** writable by us, until sqlite3OsShmUnmap() has been called.
 57500         -  ** This is a requirement on the VFS implementation.
 57501         -   */
 57502         -  rc = sqlite3OsShmMap(pWal->pDbFd, 0, WALINDEX_PGSZ, 0, &pDummy);
 57503         -  assert( rc!=SQLITE_OK ); /* SQLITE_OK not possible for read-only connection */
 57504         -  if( rc!=SQLITE_READONLY_CANTINIT ){
 57505         -    rc = (rc==SQLITE_READONLY ? WAL_RETRY : rc);
 57506         -    goto begin_unreliable_shm_out;
 57507         -  }
 57508         -
 57509         -  /* We reach this point only if the real shared-memory is still unreliable.
 57510         -  ** Assume the in-memory WAL-index substitute is correct and load it
 57511         -  ** into pWal->hdr.
 57512         -  */
 57513         -  memcpy(&pWal->hdr, (void*)walIndexHdr(pWal), sizeof(WalIndexHdr));
 57514         -
 57515         -  /* Make sure some writer hasn't come in and changed the WAL file out
 57516         -  ** from under us, then disconnected, while we were not looking.
 57517         -  */
 57518         -  rc = sqlite3OsFileSize(pWal->pWalFd, &szWal);
 57519         -  if( rc!=SQLITE_OK ){
 57520         -    goto begin_unreliable_shm_out;
 57521         -  }
 57522         -  if( szWal<WAL_HDRSIZE ){
 57523         -    /* If the wal file is too small to contain a wal-header and the
 57524         -    ** wal-index header has mxFrame==0, then it must be safe to proceed
 57525         -    ** reading the database file only. However, the page cache cannot
 57526         -    ** be trusted, as a read/write connection may have connected, written
 57527         -    ** the db, run a checkpoint, truncated the wal file and disconnected
 57528         -    ** since this client's last read transaction.  */
 57529         -    *pChanged = 1;
 57530         -    rc = (pWal->hdr.mxFrame==0 ? SQLITE_OK : WAL_RETRY);
 57531         -    goto begin_unreliable_shm_out;
 57532         -  }
 57533         -
 57534         -  /* Check the salt keys at the start of the wal file still match. */
 57535         -  rc = sqlite3OsRead(pWal->pWalFd, aBuf, WAL_HDRSIZE, 0);
 57536         -  if( rc!=SQLITE_OK ){
 57537         -    goto begin_unreliable_shm_out;
 57538         -  }
 57539         -  if( memcmp(&pWal->hdr.aSalt, &aBuf[16], 8) ){
 57540         -    /* Some writer has wrapped the WAL file while we were not looking.
 57541         -    ** Return WAL_RETRY which will cause the in-memory WAL-index to be
 57542         -    ** rebuilt. */
 57543         -    rc = WAL_RETRY;
 57544         -    goto begin_unreliable_shm_out;
 57545         -  }
 57546         -
 57547         -  /* Allocate a buffer to read frames into */
 57548         -  szFrame = pWal->hdr.szPage + WAL_FRAME_HDRSIZE;
 57549         -  aFrame = (u8 *)sqlite3_malloc64(szFrame);
 57550         -  if( aFrame==0 ){
 57551         -    rc = SQLITE_NOMEM_BKPT;
 57552         -    goto begin_unreliable_shm_out;
 57553         -  }
 57554         -  aData = &aFrame[WAL_FRAME_HDRSIZE];
 57555         -
 57556         -  /* Check to see if a complete transaction has been appended to the
 57557         -  ** wal file since the heap-memory wal-index was created. If so, the
 57558         -  ** heap-memory wal-index is discarded and WAL_RETRY returned to
 57559         -  ** the caller.  */
 57560         -  aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
 57561         -  aSaveCksum[1] = pWal->hdr.aFrameCksum[1];
 57562         -  for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->hdr.szPage); 
 57563         -      iOffset+szFrame<=szWal; 
 57564         -      iOffset+=szFrame
 57565         -  ){
 57566         -    u32 pgno;                   /* Database page number for frame */
 57567         -    u32 nTruncate;              /* dbsize field from frame header */
 57568         -
 57569         -    /* Read and decode the next log frame. */
 57570         -    rc = sqlite3OsRead(pWal->pWalFd, aFrame, szFrame, iOffset);
 57571         -    if( rc!=SQLITE_OK ) break;
 57572         -    if( !walDecodeFrame(pWal, &pgno, &nTruncate, aData, aFrame) ) break;
 57573         -
 57574         -    /* If nTruncate is non-zero, then a complete transaction has been
 57575         -    ** appended to this wal file. Set rc to WAL_RETRY and break out of
 57576         -    ** the loop.  */
 57577         -    if( nTruncate ){
 57578         -      rc = WAL_RETRY;
 57579         -      break;
 57580         -    }
 57581         -  }
 57582         -  pWal->hdr.aFrameCksum[0] = aSaveCksum[0];
 57583         -  pWal->hdr.aFrameCksum[1] = aSaveCksum[1];
 57584         -
 57585         - begin_unreliable_shm_out:
 57586         -  sqlite3_free(aFrame);
 57587         -  if( rc!=SQLITE_OK ){
 57588         -    int i;
 57589         -    for(i=0; i<pWal->nWiData; i++){
 57590         -      sqlite3_free((void*)pWal->apWiData[i]);
 57591         -      pWal->apWiData[i] = 0;
 57592         -    }
 57593         -    pWal->bShmUnreliable = 0;
 57594         -    sqlite3WalEndReadTransaction(pWal);
 57595         -    *pChanged = 1;
 57596         -  }
 57597         -  return rc;
 57598         -}
        57235  +
        57236  +  return rc;
        57237  +}
        57238  +
        57239  +/*
        57240  +** This is the value that walTryBeginRead returns when it needs to
        57241  +** be retried.
        57242  +*/
        57243  +#define WAL_RETRY  (-1)
 57599  57244   
 57600  57245   /*
 57601  57246   ** Attempt to start a read transaction.  This might fail due to a race or
 57602  57247   ** other transient condition.  When that happens, it returns WAL_RETRY to
 57603  57248   ** indicate to the caller that it is safe to retry immediately.
 57604  57249   **
 57605  57250   ** On success return SQLITE_OK.  On a permanent failure (such an
................................................................................
 57607  57252   ** recovery) return a positive error code.
 57608  57253   **
 57609  57254   ** The useWal parameter is true to force the use of the WAL and disable
 57610  57255   ** the case where the WAL is bypassed because it has been completely
 57611  57256   ** checkpointed.  If useWal==0 then this routine calls walIndexReadHdr() 
 57612  57257   ** to make a copy of the wal-index header into pWal->hdr.  If the 
 57613  57258   ** wal-index header has changed, *pChanged is set to 1 (as an indication 
 57614         -** to the caller that the local page cache is obsolete and needs to be 
        57259  +** to the caller that the local paget cache is obsolete and needs to be 
 57615  57260   ** flushed.)  When useWal==1, the wal-index header is assumed to already
 57616  57261   ** be loaded and the pChanged parameter is unused.
 57617  57262   **
 57618  57263   ** The caller must set the cnt parameter to the number of prior calls to
 57619  57264   ** this routine during the current read attempt that returned WAL_RETRY.
 57620  57265   ** This routine will start taking more aggressive measures to clear the
 57621  57266   ** race conditions after multiple WAL_RETRY returns, and after an excessive
................................................................................
 57653  57298     int mxI;                        /* Index of largest aReadMark[] value */
 57654  57299     int i;                          /* Loop counter */
 57655  57300     int rc = SQLITE_OK;             /* Return code  */
 57656  57301     u32 mxFrame;                    /* Wal frame to lock to */
 57657  57302   
 57658  57303     assert( pWal->readLock<0 );     /* Not currently locked */
 57659  57304   
 57660         -  /* useWal may only be set for read/write connections */
 57661         -  assert( (pWal->readOnly & WAL_SHM_RDONLY)==0 || useWal==0 );
 57662         -
 57663  57305     /* Take steps to avoid spinning forever if there is a protocol error.
 57664  57306     **
 57665  57307     ** Circumstances that cause a RETRY should only last for the briefest
 57666  57308     ** instances of time.  No I/O or other system calls are done while the
 57667  57309     ** locks are held, so the locks should not be held for very long. But 
 57668  57310     ** if we are unlucky, another process that is holding a lock might get
 57669  57311     ** paged out or take a page-fault that is time-consuming to resolve, 
................................................................................
 57684  57326         return SQLITE_PROTOCOL;
 57685  57327       }
 57686  57328       if( cnt>=10 ) nDelay = (cnt-9)*(cnt-9)*39;
 57687  57329       sqlite3OsSleep(pWal->pVfs, nDelay);
 57688  57330     }
 57689  57331   
 57690  57332     if( !useWal ){
 57691         -    assert( rc==SQLITE_OK );
 57692         -    if( pWal->bShmUnreliable==0 ){
 57693         -      rc = walIndexReadHdr(pWal, pChanged);
 57694         -    }
        57333  +    rc = walIndexReadHdr(pWal, pChanged);
 57695  57334       if( rc==SQLITE_BUSY ){
 57696  57335         /* If there is not a recovery running in another thread or process
 57697  57336         ** then convert BUSY errors to WAL_RETRY.  If recovery is known to
 57698  57337         ** be running, convert BUSY to BUSY_RECOVERY.  There is a race here
 57699  57338         ** which might cause WAL_RETRY to be returned even if BUSY_RECOVERY
 57700  57339         ** would be technically correct.  But the race is benign since with
 57701  57340         ** WAL_RETRY this routine will be called again and will probably be
................................................................................
 57716  57355         }else if( rc==SQLITE_BUSY ){
 57717  57356           rc = SQLITE_BUSY_RECOVERY;
 57718  57357         }
 57719  57358       }
 57720  57359       if( rc!=SQLITE_OK ){
 57721  57360         return rc;
 57722  57361       }
 57723         -    else if( pWal->bShmUnreliable ){
 57724         -      return walBeginShmUnreliable(pWal, pChanged);
 57725         -    }
 57726  57362     }
 57727  57363   
 57728         -  assert( pWal->nWiData>0 );
 57729         -  assert( pWal->apWiData[0]!=0 );
 57730  57364     pInfo = walCkptInfo(pWal);
 57731         -  if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame
        57365  +  if( !useWal && pInfo->nBackfill==pWal->hdr.mxFrame 
 57732  57366   #ifdef SQLITE_ENABLE_SNAPSHOT
 57733  57367      && (pWal->pSnapshot==0 || pWal->hdr.mxFrame==0
 57734  57368        || 0==memcmp(&pWal->hdr, pWal->pSnapshot, sizeof(WalIndexHdr)))
 57735  57369   #endif
 57736  57370     ){
 57737  57371       /* The WAL has been completely backfilled (or it is empty).
 57738  57372       ** and can be safely ignored.
................................................................................
 57798  57432         }else if( rc!=SQLITE_BUSY ){
 57799  57433           return rc;
 57800  57434         }
 57801  57435       }
 57802  57436     }
 57803  57437     if( mxI==0 ){
 57804  57438       assert( rc==SQLITE_BUSY || (pWal->readOnly & WAL_SHM_RDONLY)!=0 );
 57805         -    return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTINIT;
        57439  +    return rc==SQLITE_BUSY ? WAL_RETRY : SQLITE_READONLY_CANTLOCK;
 57806  57440     }
 57807  57441   
 57808  57442     rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
 57809  57443     if( rc ){
 57810  57444       return rc==SQLITE_BUSY ? WAL_RETRY : rc;
 57811  57445     }
 57812  57446     /* Now that the read-lock has been obtained, check that neither the
................................................................................
 58070  57704   
 58071  57705     /* If the "last page" field of the wal-index header snapshot is 0, then
 58072  57706     ** no data will be read from the wal under any circumstances. Return early
 58073  57707     ** in this case as an optimization.  Likewise, if pWal->readLock==0, 
 58074  57708     ** then the WAL is ignored by the reader so return early, as if the 
 58075  57709     ** WAL were empty.
 58076  57710     */
 58077         -  if( iLast==0 || (pWal->readLock==0 && pWal->bShmUnreliable==0) ){
        57711  +  if( iLast==0 || pWal->readLock==0 ){
 58078  57712       *piRead = 0;
 58079  57713       return SQLITE_OK;
 58080  57714     }
 58081  57715   
 58082  57716     /* Search the hash table or tables for an entry matching page number
 58083  57717     ** pgno. Each iteration of the following for() loop searches one
 58084  57718     ** hash table (each hash table indexes up to HASHTABLE_NPAGE frames).
................................................................................
 58133  57767   #ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
 58134  57768     /* If expensive assert() statements are available, do a linear search
 58135  57769     ** of the wal-index file content. Make sure the results agree with the
 58136  57770     ** result obtained using the hash indexes above.  */
 58137  57771     {
 58138  57772       u32 iRead2 = 0;
 58139  57773       u32 iTest;
 58140         -    assert( pWal->bShmUnreliable || pWal->minFrame>0 );
 58141         -    for(iTest=iLast; iTest>=pWal->minFrame && iTest>0; iTest--){
        57774  +    assert( pWal->minFrame>0 );
        57775  +    for(iTest=iLast; iTest>=pWal->minFrame; iTest--){
 58142  57776         if( walFramePgno(pWal, iTest)==pgno ){
 58143  57777           iRead2 = iTest;
 58144  57778           break;
 58145  57779         }
 58146  57780       }
 58147  57781       assert( iRead==iRead2 );
 58148  57782     }
................................................................................
 58910  58544     ** locks are taken in this case). Nor should the pager attempt to
 58911  58545     ** upgrade to exclusive-mode following such an error.
 58912  58546     */
 58913  58547     assert( pWal->readLock>=0 || pWal->lockError );
 58914  58548     assert( pWal->readLock>=0 || (op<=0 && pWal->exclusiveMode==0) );
 58915  58549   
 58916  58550     if( op==0 ){
 58917         -    if( pWal->exclusiveMode!=WAL_NORMAL_MODE ){
 58918         -      pWal->exclusiveMode = WAL_NORMAL_MODE;
        58551  +    if( pWal->exclusiveMode ){
        58552  +      pWal->exclusiveMode = 0;
 58919  58553         if( walLockShared(pWal, WAL_READ_LOCK(pWal->readLock))!=SQLITE_OK ){
 58920         -        pWal->exclusiveMode = WAL_EXCLUSIVE_MODE;
        58554  +        pWal->exclusiveMode = 1;
 58921  58555         }
 58922         -      rc = pWal->exclusiveMode==WAL_NORMAL_MODE;
        58556  +      rc = pWal->exclusiveMode==0;
 58923  58557       }else{
 58924  58558         /* Already in locking_mode=NORMAL */
 58925  58559         rc = 0;
 58926  58560       }
 58927  58561     }else if( op>0 ){
 58928         -    assert( pWal->exclusiveMode==WAL_NORMAL_MODE );
        58562  +    assert( pWal->exclusiveMode==0 );
 58929  58563       assert( pWal->readLock>=0 );
 58930  58564       walUnlockShared(pWal, WAL_READ_LOCK(pWal->readLock));
 58931         -    pWal->exclusiveMode = WAL_EXCLUSIVE_MODE;
        58565  +    pWal->exclusiveMode = 1;
 58932  58566       rc = 1;
 58933  58567     }else{
 58934         -    rc = pWal->exclusiveMode==WAL_NORMAL_MODE;
        58568  +    rc = pWal->exclusiveMode==0;
 58935  58569     }
 58936  58570     return rc;
 58937  58571   }
 58938  58572   
 58939  58573   /* 
 58940  58574   ** Return true if the argument is non-NULL and the WAL module is using
 58941  58575   ** heap-memory for the wal-index. Otherwise, if the argument is NULL or the
................................................................................
 71130  70764   ** This routine calls the finalize method for that function.  The
 71131  70765   ** result of the aggregate is stored back into pMem.
 71132  70766   **
 71133  70767   ** Return SQLITE_ERROR if the finalizer reports an error.  SQLITE_OK
 71134  70768   ** otherwise.
 71135  70769   */
 71136  70770   SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
 71137         -  sqlite3_context ctx;
 71138         -  Mem t;
 71139         -  assert( pFunc!=0 );
 71140         -  assert( pFunc->xFinalize!=0 );
 71141         -  assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef );
 71142         -  assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
 71143         -  memset(&ctx, 0, sizeof(ctx));
 71144         -  memset(&t, 0, sizeof(t));
 71145         -  t.flags = MEM_Null;
 71146         -  t.db = pMem->db;
 71147         -  ctx.pOut = &t;
 71148         -  ctx.pMem = pMem;
 71149         -  ctx.pFunc = pFunc;
 71150         -  pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
 71151         -  assert( (pMem->flags & MEM_Dyn)==0 );
 71152         -  if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
 71153         -  memcpy(pMem, &t, sizeof(t));
 71154         -  return ctx.isError;
        70771  +  int rc = SQLITE_OK;
        70772  +  if( ALWAYS(pFunc && pFunc->xFinalize) ){
        70773  +    sqlite3_context ctx;
        70774  +    Mem t;
        70775  +    assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef );
        70776  +    assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
        70777  +    memset(&ctx, 0, sizeof(ctx));
        70778  +    memset(&t, 0, sizeof(t));
        70779  +    t.flags = MEM_Null;
        70780  +    t.db = pMem->db;
        70781  +    ctx.pOut = &t;
        70782  +    ctx.pMem = pMem;
        70783  +    ctx.pFunc = pFunc;
        70784  +    pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
        70785  +    assert( (pMem->flags & MEM_Dyn)==0 );
        70786  +    if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
        70787  +    memcpy(pMem, &t, sizeof(t));
        70788  +    rc = ctx.isError;
        70789  +  }
        70790  +  return rc;
 71155  70791   }
 71156  70792   
 71157  70793   /*
 71158  70794   ** If the memory cell contains a value that must be freed by
 71159  70795   ** invoking the external callback in Mem.xDel, then this routine
 71160  70796   ** will free that value.  It also sets Mem.flags to MEM_Null.
 71161  70797   **
................................................................................
 75586  75222   
 75587  75223   /*
 75588  75224   ** Delete an entire VDBE.
 75589  75225   */
 75590  75226   SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe *p){
 75591  75227     sqlite3 *db;
 75592  75228   
 75593         -  assert( p!=0 );
        75229  +  if( NEVER(p==0) ) return;
 75594  75230     db = p->db;
 75595  75231     assert( sqlite3_mutex_held(db->mutex) );
 75596  75232     sqlite3VdbeClearObject(db, p);
 75597  75233     if( p->pPrev ){
 75598  75234       p->pPrev->pNext = p->pNext;
 75599  75235     }else{
 75600  75236       assert( db->pVdbe==p );
................................................................................
 90571  90207   */
 90572  90208   SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker *pWalker, Select *p){
 90573  90209     SrcList *pSrc;
 90574  90210     int i;
 90575  90211     struct SrcList_item *pItem;
 90576  90212   
 90577  90213     pSrc = p->pSrc;
 90578         -  assert( pSrc!=0 );
 90579         -  for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
 90580         -    if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){
 90581         -      return WRC_Abort;
 90582         -    }
 90583         -    if( pItem->fg.isTabFunc
 90584         -     && sqlite3WalkExprList(pWalker, pItem->u1.pFuncArg)
 90585         -    ){
 90586         -      return WRC_Abort;
        90214  +  if( ALWAYS(pSrc) ){
        90215  +    for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
        90216  +      if( pItem->pSelect && sqlite3WalkSelect(pWalker, pItem->pSelect) ){
        90217  +        return WRC_Abort;
        90218  +      }
        90219  +      if( pItem->fg.isTabFunc
        90220  +       && sqlite3WalkExprList(pWalker, pItem->u1.pFuncArg)
        90221  +      ){
        90222  +        return WRC_Abort;
        90223  +      }
 90587  90224       }
 90588  90225     }
 90589  90226     return WRC_Continue;
 90590  90227   } 
 90591  90228   
 90592  90229   /*
 90593  90230   ** Call sqlite3WalkExpr() for every expression in Select statement p.
................................................................................
 91222  90859       ** column in the FROM clause.  This is used by the LIMIT and ORDER BY
 91223  90860       ** clause processing on UPDATE and DELETE statements.
 91224  90861       */
 91225  90862       case TK_ROW: {
 91226  90863         SrcList *pSrcList = pNC->pSrcList;
 91227  90864         struct SrcList_item *pItem;
 91228  90865         assert( pSrcList && pSrcList->nSrc==1 );
 91229         -      pItem = pSrcList->a;
 91230         -      assert( HasRowid(pItem->pTab) && pItem->pTab->pSelect==0 );
        90866  +      pItem = pSrcList->a; 
 91231  90867         pExpr->op = TK_COLUMN;
 91232  90868         pExpr->pTab = pItem->pTab;
 91233  90869         pExpr->iTable = pItem->iCursor;
 91234  90870         pExpr->iColumn = -1;
 91235  90871         pExpr->affinity = SQLITE_AFF_INTEGER;
 91236  90872         break;
 91237  90873       }
................................................................................
 93113  92749     assert( pToken );
 93114  92750     pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
 93115  92751     if( pNew==0 ){
 93116  92752       sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
 93117  92753       return 0;
 93118  92754     }
 93119  92755     pNew->x.pList = pList;
 93120         -  ExprSetProperty(pNew, EP_HasFunc);
 93121  92756     assert( !ExprHasProperty(pNew, EP_xIsSelect) );
 93122  92757     sqlite3ExprSetHeightAndFlags(pParse, pNew);
 93123  92758     return pNew;
 93124  92759   }
 93125  92760   
 93126  92761   /*
 93127  92762   ** Assign a variable number to an expression that encodes a wildcard
................................................................................
104911 104546     if( !p && (pOn || pUsing) ){
104912 104547       sqlite3ErrorMsg(pParse, "a JOIN clause is required before %s", 
104913 104548         (pOn ? "ON" : "USING")
104914 104549       );
104915 104550       goto append_from_error;
104916 104551     }
104917 104552     p = sqlite3SrcListAppend(db, p, pTable, pDatabase);
104918         -  if( p==0 ){
       104553  +  if( p==0 || NEVER(p->nSrc==0) ){
104919 104554       goto append_from_error;
104920 104555     }
104921         -  assert( p->nSrc>0 );
104922 104556     pItem = &p->a[p->nSrc-1];
104923 104557     assert( pAlias!=0 );
104924 104558     if( pAlias->n ){
104925 104559       pItem->zAlias = sqlite3NameFromToken(db, pAlias);
104926 104560     }
104927 104561     pItem->pSelect = pSubquery;
104928 104562     pItem->pOn = pOn;
................................................................................
106081 105715   ** pWhere argument is an optional WHERE clause that restricts the
106082 105716   ** set of rows in the view that are to be added to the ephemeral table.
106083 105717   */
106084 105718   SQLITE_PRIVATE void sqlite3MaterializeView(
106085 105719     Parse *pParse,       /* Parsing context */
106086 105720     Table *pView,        /* View definition */
106087 105721     Expr *pWhere,        /* Optional WHERE clause to be added */
106088         -  ExprList *pOrderBy,  /* Optional ORDER BY clause */
106089         -  Expr *pLimit,        /* Optional LIMIT clause */
106090         -  Expr *pOffset,       /* Optional OFFSET clause */
106091 105722     int iCur             /* Cursor number for ephemeral table */
106092 105723   ){
106093 105724     SelectDest dest;
106094 105725     Select *pSel;
106095 105726     SrcList *pFrom;
106096 105727     sqlite3 *db = pParse->db;
106097 105728     int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
................................................................................
106100 105731     if( pFrom ){
106101 105732       assert( pFrom->nSrc==1 );
106102 105733       pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
106103 105734       pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zDbSName);
106104 105735       assert( pFrom->a[0].pOn==0 );
106105 105736       assert( pFrom->a[0].pUsing==0 );
106106 105737     }
106107         -  pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, pOrderBy, 
106108         -                          SF_IncludeHidden, pLimit, pOffset);
       105738  +  pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 
       105739  +                          SF_IncludeHidden, 0, 0);
106109 105740     sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
106110 105741     sqlite3Select(pParse, pSel, &dest);
106111 105742     sqlite3SelectDelete(db, pSel);
106112 105743   }
106113 105744   #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
106114 105745   
106115 105746   #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
................................................................................
106126 105757     SrcList *pSrc,               /* the FROM clause -- which tables to scan */
106127 105758     Expr *pWhere,                /* The WHERE clause.  May be null */
106128 105759     ExprList *pOrderBy,          /* The ORDER BY clause.  May be null */
106129 105760     Expr *pLimit,                /* The LIMIT clause.  May be null */
106130 105761     Expr *pOffset,               /* The OFFSET clause.  May be null */
106131 105762     char *zStmtType              /* Either DELETE or UPDATE.  For err msgs. */
106132 105763   ){
106133         -  sqlite3 *db = pParse->db;
106134         -  Expr *pLhs = NULL;           /* LHS of IN(SELECT...) operator */
       105764  +  Expr *pWhereRowid = NULL;    /* WHERE rowid .. */
106135 105765     Expr *pInClause = NULL;      /* WHERE rowid IN ( select ) */
       105766  +  Expr *pSelectRowid = NULL;   /* SELECT rowid ... */
106136 105767     ExprList *pEList = NULL;     /* Expression list contaning only pSelectRowid */
106137 105768     SrcList *pSelectSrc = NULL;  /* SELECT rowid FROM x ... (dup of pSrc) */
106138 105769     Select *pSelect = NULL;      /* Complete SELECT tree */
106139         -  Table *pTab;
106140 105770   
106141 105771     /* Check that there isn't an ORDER BY without a LIMIT clause.
106142 105772     */
106143         -  if( pOrderBy && pLimit==0 ) {
       105773  +  if( pOrderBy && (pLimit == 0) ) {
106144 105774       sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
106145         -    sqlite3ExprDelete(pParse->db, pWhere);
106146         -    sqlite3ExprListDelete(pParse->db, pOrderBy);
106147         -    sqlite3ExprDelete(pParse->db, pLimit);
106148         -    sqlite3ExprDelete(pParse->db, pOffset);
106149         -    return 0;
       105775  +    goto limit_where_cleanup;
106150 105776     }
106151 105777   
106152 105778     /* We only need to generate a select expression if there
106153 105779     ** is a limit/offset term to enforce.
106154 105780     */
106155 105781     if( pLimit == 0 ) {
106156 105782       /* if pLimit is null, pOffset will always be null as well. */
................................................................................
106163 105789     **   DELETE FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
106164 105790     ** becomes:
106165 105791     **   DELETE FROM table_a WHERE rowid IN ( 
106166 105792     **     SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
106167 105793     **   );
106168 105794     */
106169 105795   
106170         -  pTab = pSrc->a[0].pTab;
106171         -  if( HasRowid(pTab) ){
106172         -    pLhs = sqlite3PExpr(pParse, TK_ROW, 0, 0);
106173         -    pEList = sqlite3ExprListAppend(
106174         -        pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0)
106175         -    );
106176         -  }else{
106177         -    Index *pPk = sqlite3PrimaryKeyIndex(pTab);
106178         -    if( pPk->nKeyCol==1 ){
106179         -      const char *zName = pTab->aCol[pPk->aiColumn[0]].zName;
106180         -      pLhs = sqlite3Expr(db, TK_ID, zName);
106181         -      pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName));
106182         -    }else{
106183         -      int i;
106184         -      for(i=0; i<pPk->nKeyCol; i++){
106185         -        Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zName);
106186         -        pEList = sqlite3ExprListAppend(pParse, pEList, p);
106187         -      }
106188         -      pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
106189         -      if( pLhs ){
106190         -        pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0);
106191         -      }
106192         -    }
106193         -  }
       105796  +  pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0);
       105797  +  if( pSelectRowid == 0 ) goto limit_where_cleanup;
       105798  +  pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid);
       105799  +  if( pEList == 0 ) goto limit_where_cleanup;
106194 105800   
106195 105801     /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
106196 105802     ** and the SELECT subtree. */
106197         -  pSrc->a[0].pTab = 0;
106198 105803     pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
106199         -  pSrc->a[0].pTab = pTab;
106200         -  pSrc->a[0].pIBIndex = 0;
       105804  +  if( pSelectSrc == 0 ) {
       105805  +    sqlite3ExprListDelete(pParse->db, pEList);
       105806  +    goto limit_where_cleanup;
       105807  +  }
106201 105808   
106202 105809     /* generate the SELECT expression tree. */
106203         -  pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0, 
106204         -      pOrderBy,0,pLimit,pOffset
106205         -  );
       105810  +  pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,
       105811  +                             pOrderBy,0,pLimit,pOffset);
       105812  +  if( pSelect == 0 ) return 0;
106206 105813   
106207 105814     /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
106208         -  pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0);
       105815  +  pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0);
       105816  +  pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0) : 0;
106209 105817     sqlite3PExprAddSelect(pParse, pInClause, pSelect);
106210 105818     return pInClause;
       105819  +
       105820  +limit_where_cleanup:
       105821  +  sqlite3ExprDelete(pParse->db, pWhere);
       105822  +  sqlite3ExprListDelete(pParse->db, pOrderBy);
       105823  +  sqlite3ExprDelete(pParse->db, pLimit);
       105824  +  sqlite3ExprDelete(pParse->db, pOffset);
       105825  +  return 0;
106211 105826   }
106212 105827   #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */
106213 105828          /*      && !defined(SQLITE_OMIT_SUBQUERY) */
106214 105829   
106215 105830   /*
106216 105831   ** Generate code for a DELETE FROM statement.
106217 105832   **
................................................................................
106218 105833   **     DELETE FROM table_wxyz WHERE a<5 AND b NOT NULL;
106219 105834   **                 \________/       \________________/
106220 105835   **                  pTabList              pWhere
106221 105836   */
106222 105837   SQLITE_PRIVATE void sqlite3DeleteFrom(
106223 105838     Parse *pParse,         /* The parser context */
106224 105839     SrcList *pTabList,     /* The table from which we should delete things */
106225         -  Expr *pWhere,          /* The WHERE clause.  May be null */
106226         -  ExprList *pOrderBy,    /* ORDER BY clause. May be null */
106227         -  Expr *pLimit,          /* LIMIT clause. May be null */
106228         -  Expr *pOffset          /* OFFSET clause. May be null */
       105840  +  Expr *pWhere           /* The WHERE clause.  May be null */
106229 105841   ){
106230 105842     Vdbe *v;               /* The virtual database engine */
106231 105843     Table *pTab;           /* The table from which records will be deleted */
106232 105844     int i;                 /* Loop counter */
106233 105845     WhereInfo *pWInfo;     /* Information about the WHERE clause */
106234 105846     Index *pIdx;           /* For looping over indices of the table */
106235 105847     int iTabCur;           /* Cursor number for the table */
................................................................................
106266 105878     memset(&sContext, 0, sizeof(sContext));
106267 105879     db = pParse->db;
106268 105880     if( pParse->nErr || db->mallocFailed ){
106269 105881       goto delete_from_cleanup;
106270 105882     }
106271 105883     assert( pTabList->nSrc==1 );
106272 105884   
106273         -
106274 105885     /* Locate the table which we want to delete.  This table has to be
106275 105886     ** put in an SrcList structure because some of the subroutines we
106276 105887     ** will be calling are designed to work with multiple tables and expect
106277 105888     ** an SrcList* parameter instead of just a Table* parameter.
106278 105889     */
106279 105890     pTab = sqlite3SrcListLookup(pParse, pTabList);
106280 105891     if( pTab==0 )  goto delete_from_cleanup;
................................................................................
106289 105900   #else
106290 105901   # define pTrigger 0
106291 105902   # define isView 0
106292 105903   #endif
106293 105904   #ifdef SQLITE_OMIT_VIEW
106294 105905   # undef isView
106295 105906   # define isView 0
106296         -#endif
106297         -
106298         -#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
106299         -  if( !isView ){
106300         -    pWhere = sqlite3LimitWhere(
106301         -        pParse, pTabList, pWhere, pOrderBy, pLimit, pOffset, "DELETE"
106302         -    );
106303         -    pOrderBy = 0;
106304         -    pLimit = pOffset = 0;
106305         -  }
106306 105907   #endif
106307 105908   
106308 105909     /* If pTab is really a view, make sure it has been initialized.
106309 105910     */
106310 105911     if( sqlite3ViewGetColumnNames(pParse, pTab) ){
106311 105912       goto delete_from_cleanup;
106312 105913     }
................................................................................
106348 105949     sqlite3BeginWriteOperation(pParse, 1, iDb);
106349 105950   
106350 105951     /* If we are trying to delete from a view, realize that view into
106351 105952     ** an ephemeral table.
106352 105953     */
106353 105954   #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
106354 105955     if( isView ){
106355         -    sqlite3MaterializeView(pParse, pTab, 
106356         -        pWhere, pOrderBy, pLimit, pOffset, iTabCur
106357         -    );
       105956  +    sqlite3MaterializeView(pParse, pTab, pWhere, iTabCur);
106358 105957       iDataCur = iIdxCur = iTabCur;
106359         -    pOrderBy = 0;
106360         -    pLimit = pOffset = 0;
106361 105958     }
106362 105959   #endif
106363 105960   
106364 105961     /* Resolve the column names in the WHERE clause.
106365 105962     */
106366 105963     memset(&sNC, 0, sizeof(sNC));
106367 105964     sNC.pParse = pParse;
................................................................................
106597 106194       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQLITE_STATIC);
106598 106195     }
106599 106196   
106600 106197   delete_from_cleanup:
106601 106198     sqlite3AuthContextPop(&sContext);
106602 106199     sqlite3SrcListDelete(db, pTabList);
106603 106200     sqlite3ExprDelete(db, pWhere);
106604         -#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) 
106605         -  sqlite3ExprListDelete(db, pOrderBy);
106606         -  sqlite3ExprDelete(db, pLimit);
106607         -  sqlite3ExprDelete(db, pOffset);
106608         -#endif
106609 106201     sqlite3DbFree(db, aToOpen);
106610 106202     return;
106611 106203   }
106612 106204   /* Make sure "isView" and other macros defined above are undefined. Otherwise
106613 106205   ** they may interfere with compilation of other functions in this file
106614 106206   ** (or in another file, if this file becomes part of the amalgamation).  */
106615 106207   #ifdef isView
................................................................................
107643 107235         ** that point.
107644 107236         **
107645 107237         ** For a case-insensitive search, set variable cx to be the same as
107646 107238         ** c but in the other case and search the input string for either
107647 107239         ** c or cx.
107648 107240         */
107649 107241         if( c<=0x80 ){
107650         -        char zStop[3];
       107242  +        u32 cx;
107651 107243           int bMatch;
107652 107244           if( noCase ){
107653         -          zStop[0] = sqlite3Toupper(c);
107654         -          zStop[1] = sqlite3Tolower(c);
107655         -          zStop[2] = 0;
       107245  +          cx = sqlite3Toupper(c);
       107246  +          c = sqlite3Tolower(c);
107656 107247           }else{
107657         -          zStop[0] = c;
107658         -          zStop[1] = 0;
       107248  +          cx = c;
107659 107249           }
107660         -        while(1){
107661         -          zString += strcspn((const char*)zString, zStop);
107662         -          if( zString[0]==0 ) break;
107663         -          zString++;
       107250  +        while( (c2 = *(zString++))!=0 ){
       107251  +          if( c2!=c && c2!=cx ) continue;
107664 107252             bMatch = patternCompare(zPattern,zString,pInfo,matchOther);
107665 107253             if( bMatch!=SQLITE_NOMATCH ) return bMatch;
107666 107254           }
107667 107255         }else{
107668 107256           int bMatch;
107669 107257           while( (c2 = Utf8Read(zString))!=0 ){
107670 107258             if( c2!=c ) continue;
................................................................................
109566 109154         }
109567 109155         if( !p ) return;
109568 109156         iSkip = sqlite3VdbeMakeLabel(v);
109569 109157         sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
109570 109158       }
109571 109159   
109572 109160       pParse->disableTriggers = 1;
109573         -    sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0, 0, 0, 0);
       109161  +    sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
109574 109162       pParse->disableTriggers = 0;
109575 109163   
109576 109164       /* If the DELETE has generated immediate foreign key constraint 
109577 109165       ** violations, halt the VDBE and return an error at this point, before
109578 109166       ** any modifications to the schema are made. This is because statement
109579 109167       ** transactions are not able to rollback schema changes.  
109580 109168       **
................................................................................
111174 110762           sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid);
111175 110763         }else if( pSelect ){
111176 110764           sqlite3VdbeAddOp2(v, OP_Copy, regFromSelect+ipkColumn, regRowid);
111177 110765         }else{
111178 110766           VdbeOp *pOp;
111179 110767           sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
111180 110768           pOp = sqlite3VdbeGetOp(v, -1);
111181         -        assert( pOp!=0 );
111182         -        if( pOp->opcode==OP_Null && !IsVirtual(pTab) ){
       110769  +        if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
111183 110770             appendFlag = 1;
111184 110771             pOp->opcode = OP_NewRowid;
111185 110772             pOp->p1 = iDataCur;
111186 110773             pOp->p2 = regRowid;
111187 110774             pOp->p3 = regAutoinc;
111188 110775           }
111189 110776         }
................................................................................
117670 117257     ** We return -1000000 instead of the more usual -1 simply because using
117671 117258     ** -1000000 as the incorrect index into db->aDb[] is much 
117672 117259     ** more likely to cause a segfault than -1 (of course there are assert()
117673 117260     ** statements too, but it never hurts to play the odds).
117674 117261     */
117675 117262     assert( sqlite3_mutex_held(db->mutex) );
117676 117263     if( pSchema ){
117677         -    for(i=0; 1; i++){
117678         -      assert( i<db->nDb );
       117264  +    for(i=0; ALWAYS(i<db->nDb); i++){
117679 117265         if( db->aDb[i].pSchema==pSchema ){
117680 117266           break;
117681 117267         }
117682 117268       }
117683 117269       assert( i>=0 && i<db->nDb );
117684 117270     }
117685 117271     return i;
................................................................................
121480 121066   **  (18)  If the sub-query is a compound select, then all terms of the
121481 121067   **        ORDER BY clause of the parent must be simple references to 
121482 121068   **        columns of the sub-query.
121483 121069   **
121484 121070   **  (19)  If the subquery uses LIMIT then the outer query may not
121485 121071   **        have a WHERE clause.
121486 121072   **
121487         -**  (20)  If the sub-query is a compound select, then it must not use
121488         -**        an ORDER BY clause.  Ticket #3773.  We could relax this constraint
121489         -**        somewhat by saying that the terms of the ORDER BY clause must
121490         -**        appear as unmodified result columns in the outer query.  But we
121491         -**        have other optimizations in mind to deal with that case.
       121073  +**  (**)  Subsumed into (17d3).  Was: If the sub-query is a compound select,
       121074  +**        then it must not use an ORDER BY clause - Ticket #3773.  Because
       121075  +**        of (17d3), then only way to have a compound subquery is if it is
       121076  +**        the only term in the FROM clause of the outer query.  But if the
       121077  +**        only term in the FROM clause has an ORDER BY, then it will be
       121078  +**        implemented as a co-routine and the flattener will never be called.
121492 121079   **
121493 121080   **  (21)  If the subquery uses LIMIT then the outer query may not be
121494 121081   **        DISTINCT.  (See ticket [752e1646fc]).
121495 121082   **
121496 121083   **  (22)  The subquery may not be a recursive CTE.
121497 121084   **
121498 121085   **  (**)  Subsumed into restriction (17d3).  Was: If the outer query is
................................................................................
121618 121205   
121619 121206     /* Restriction (17): If the sub-query is a compound SELECT, then it must
121620 121207     ** use only the UNION ALL operator. And none of the simple select queries
121621 121208     ** that make up the compound SELECT are allowed to be aggregate or distinct
121622 121209     ** queries.
121623 121210     */
121624 121211     if( pSub->pPrior ){
121625         -    if( pSub->pOrderBy ){
121626         -      return 0;  /* Restriction (20) */
121627         -    }
121628 121212       if( isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){
121629 121213         return 0; /* (17d1), (17d2), or (17d3) */
121630 121214       }
121631 121215       for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){
121632 121216         testcase( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct );
121633 121217         testcase( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))==SF_Aggregate );
121634 121218         assert( pSub->pSrc!=0 );
................................................................................
121655 121239     ** The only way that the recursive part of a CTE can contain a compound
121656 121240     ** subquery is for the subquery to be one term of a join.  But if the
121657 121241     ** subquery is a join, then the flattening has already been stopped by
121658 121242     ** restriction (17d3)
121659 121243     */
121660 121244     assert( (p->selFlags & SF_Recursive)==0 || pSub->pPrior==0 );
121661 121245   
       121246  +  /* Ex-restriction (20):
       121247  +  ** A compound subquery must be the only term in the FROM clause of the
       121248  +  ** outer query by restriction (17d3).  But if that term also has an
       121249  +  ** ORDER BY clause, then the subquery will be implemented by co-routine
       121250  +  ** and so the flattener will never be invoked.  Hence, it is not possible
       121251  +  ** for the subquery to be a compound and have an ORDER BY clause.
       121252  +  */
       121253  +  assert( pSub->pPrior==0 || pSub->pOrderBy==0 );
       121254  +
121662 121255     /***** If we reach this point, flattening is permitted. *****/
121663 121256     SELECTTRACE(1,pParse,p,("flatten %s.%p from term %d\n",
121664 121257                      pSub->zSelName, pSub, iFrom));
121665 121258   
121666 121259     /* Authorize the subquery */
121667 121260     pParse->zAuthContext = pSubitem->zName;
121668 121261     TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
................................................................................
122009 121602       }
122010 121603     }
122011 121604     return nChng;
122012 121605   }
122013 121606   #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
122014 121607   
122015 121608   /*
122016         -** The pFunc is the only aggregate function in the query.  Check to see
122017         -** if the query is a candidate for the min/max optimization. 
122018         -**
122019         -** If the query is a candidate for the min/max optimization, then set
122020         -** *ppMinMax to be an ORDER BY clause to be used for the optimization
122021         -** and return either WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX depending on
122022         -** whether pFunc is a min() or max() function.
122023         -**
122024         -** If the query is not a candidate for the min/max optimization, return
122025         -** WHERE_ORDERBY_NORMAL (which must be zero).
122026         -**
122027         -** This routine must be called after aggregate functions have been
122028         -** located but before their arguments have been subjected to aggregate
122029         -** analysis.
122030         -*/
122031         -static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
122032         -  int eRet = WHERE_ORDERBY_NORMAL;      /* Return value */
122033         -  ExprList *pEList = pFunc->x.pList;    /* Arguments to agg function */
122034         -  const char *zFunc;                    /* Name of aggregate function pFunc */
122035         -  ExprList *pOrderBy;
122036         -  u8 sortOrder;
122037         -
122038         -  assert( *ppMinMax==0 );
122039         -  assert( pFunc->op==TK_AGG_FUNCTION );
122040         -  if( pEList==0 || pEList->nExpr!=1 ) return eRet;
122041         -  zFunc = pFunc->u.zToken;
122042         -  if( sqlite3StrICmp(zFunc, "min")==0 ){
122043         -    eRet = WHERE_ORDERBY_MIN;
122044         -    sortOrder = SQLITE_SO_ASC;
122045         -  }else if( sqlite3StrICmp(zFunc, "max")==0 ){
122046         -    eRet = WHERE_ORDERBY_MAX;
122047         -    sortOrder = SQLITE_SO_DESC;
122048         -  }else{
122049         -    return eRet;
122050         -  }
122051         -  *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
122052         -  assert( pOrderBy!=0 || db->mallocFailed );
122053         -  if( pOrderBy ) pOrderBy->a[0].sortOrder = sortOrder;
       121609  +** Based on the contents of the AggInfo structure indicated by the first
       121610  +** argument, this function checks if the following are true:
       121611  +**
       121612  +**    * the query contains just a single aggregate function,
       121613  +**    * the aggregate function is either min() or max(), and
       121614  +**    * the argument to the aggregate function is a column value.
       121615  +**
       121616  +** If all of the above are true, then WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX
       121617  +** is returned as appropriate. Also, *ppMinMax is set to point to the 
       121618  +** list of arguments passed to the aggregate before returning.
       121619  +**
       121620  +** Or, if the conditions above are not met, *ppMinMax is set to 0 and
       121621  +** WHERE_ORDERBY_NORMAL is returned.
       121622  +*/
       121623  +static u8 minMaxQuery(AggInfo *pAggInfo, ExprList **ppMinMax){
       121624  +  int eRet = WHERE_ORDERBY_NORMAL;          /* Return value */
       121625  +
       121626  +  *ppMinMax = 0;
       121627  +  if( pAggInfo->nFunc==1 ){
       121628  +    Expr *pExpr = pAggInfo->aFunc[0].pExpr; /* Aggregate function */
       121629  +    ExprList *pEList = pExpr->x.pList;      /* Arguments to agg function */
       121630  +
       121631  +    assert( pExpr->op==TK_AGG_FUNCTION );
       121632  +    if( pEList && pEList->nExpr==1 && pEList->a[0].pExpr->op==TK_AGG_COLUMN ){
       121633  +      const char *zFunc = pExpr->u.zToken;
       121634  +      if( sqlite3StrICmp(zFunc, "min")==0 ){
       121635  +        eRet = WHERE_ORDERBY_MIN;
       121636  +        *ppMinMax = pEList;
       121637  +      }else if( sqlite3StrICmp(zFunc, "max")==0 ){
       121638  +        eRet = WHERE_ORDERBY_MAX;
       121639  +        *ppMinMax = pEList;
       121640  +      }
       121641  +    }
       121642  +  }
       121643  +
       121644  +  assert( *ppMinMax==0 || (*ppMinMax)->nExpr==1 );
122054 121645     return eRet;
122055 121646   }
122056 121647   
122057 121648   /*
122058 121649   ** The select statement passed as the first argument is an aggregate query.
122059 121650   ** The second argument is the associated aggregate-info object. This 
122060 121651   ** function tests if the SELECT is of the form:
................................................................................
122433 122024     int i, j, k;
122434 122025     SrcList *pTabList;
122435 122026     ExprList *pEList;
122436 122027     struct SrcList_item *pFrom;
122437 122028     sqlite3 *db = pParse->db;
122438 122029     Expr *pE, *pRight, *pExpr;
122439 122030     u16 selFlags = p->selFlags;
122440         -  u32 elistFlags = 0;
122441 122031   
122442 122032     p->selFlags |= SF_Expanded;
122443 122033     if( db->mallocFailed  ){
122444 122034       return WRC_Abort;
122445 122035     }
122446         -  assert( p->pSrc!=0 );
122447         -  if( (selFlags & SF_Expanded)!=0 ){
       122036  +  if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
122448 122037       return WRC_Prune;
122449 122038     }
122450 122039     pTabList = p->pSrc;
122451 122040     pEList = p->pEList;
122452 122041     if( OK_IF_ALWAYS_TRUE(p->pWith) ){
122453 122042       sqlite3WithPush(pParse, p->pWith, 0);
122454 122043     }
................................................................................
122547 122136     */
122548 122137     for(k=0; k<pEList->nExpr; k++){
122549 122138       pE = pEList->a[k].pExpr;
122550 122139       if( pE->op==TK_ASTERISK ) break;
122551 122140       assert( pE->op!=TK_DOT || pE->pRight!=0 );
122552 122141       assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) );
122553 122142       if( pE->op==TK_DOT && pE->pRight->op==TK_ASTERISK ) break;
122554         -    elistFlags |= pE->flags;
122555 122143     }
122556 122144     if( k<pEList->nExpr ){
122557 122145       /*
122558 122146       ** If we get here it means the result set contains one or more "*"
122559 122147       ** operators that need to be expanded.  Loop through each expression
122560 122148       ** in the result set and expand them one by one.
122561 122149       */
................................................................................
122563 122151       ExprList *pNew = 0;
122564 122152       int flags = pParse->db->flags;
122565 122153       int longNames = (flags & SQLITE_FullColNames)!=0
122566 122154                         && (flags & SQLITE_ShortColNames)==0;
122567 122155   
122568 122156       for(k=0; k<pEList->nExpr; k++){
122569 122157         pE = a[k].pExpr;
122570         -      elistFlags |= pE->flags;
122571 122158         pRight = pE->pRight;
122572 122159         assert( pE->op!=TK_DOT || pRight!=0 );
122573 122160         if( pE->op!=TK_ASTERISK
122574 122161          && (pE->op!=TK_DOT || pRight->op!=TK_ASTERISK)
122575 122162         ){
122576 122163           /* This particular expression does not need to be expanded.
122577 122164           */
................................................................................
122693 122280             }
122694 122281           }
122695 122282         }
122696 122283       }
122697 122284       sqlite3ExprListDelete(db, pEList);
122698 122285       p->pEList = pNew;
122699 122286     }
122700         -  if( p->pEList ){
122701         -    if( p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
122702         -      sqlite3ErrorMsg(pParse, "too many columns in result set");
122703         -      return WRC_Abort;
122704         -    }
122705         -    if( (elistFlags & (EP_HasFunc|EP_Subquery))!=0 ){
122706         -      p->selFlags |= SF_ComplexResult;
122707         -    }
       122287  +  if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
       122288  +    sqlite3ErrorMsg(pParse, "too many columns in result set");
       122289  +    return WRC_Abort;
122708 122290     }
122709 122291     return WRC_Continue;
122710 122292   }
122711 122293   
122712 122294   /*
122713 122295   ** No-op routine for the parse-tree walker.
122714 122296   **
................................................................................
123236 122818     Expr *pHaving;         /* The HAVING clause.  May be NULL */
123237 122819     int rc = 1;            /* Value to return from this function */
123238 122820     DistinctCtx sDistinct; /* Info on how to code the DISTINCT keyword */
123239 122821     SortCtx sSort;         /* Info on how to code the ORDER BY clause */
123240 122822     AggInfo sAggInfo;      /* Information used by aggregate queries */
123241 122823     int iEnd;              /* Address of the end of the query */
123242 122824     sqlite3 *db;           /* The database connection */
123243         -  ExprList *pMinMaxOrderBy = 0;  /* Added ORDER BY for min/max queries */
123244         -  u8 minMaxFlag;                 /* Flag for min/max queries */
123245 122825   
123246 122826   #ifndef SQLITE_OMIT_EXPLAIN
123247 122827     int iRestoreSelectId = pParse->iSelectId;
123248 122828     pParse->iSelectId = pParse->iNextSelectId++;
123249 122829   #endif
123250 122830   
123251 122831     db = pParse->db;
................................................................................
123324 122904       ** is not a join.  But if the outer query is not a join, then the subquery
123325 122905       ** will be implemented as a co-routine and there is no advantage to
123326 122906       ** flattening in that case.
123327 122907       */
123328 122908       if( (pSub->selFlags & SF_Aggregate)!=0 ) continue;
123329 122909       assert( pSub->pGroupBy==0 );
123330 122910   
123331         -    /* If the outer query contains a "complex" result set (that is,
123332         -    ** if the result set of the outer query uses functions or subqueries)
123333         -    ** and if the subquery contains an ORDER BY clause and if
       122911  +    /* If the subquery contains an ORDER BY clause and if
123334 122912       ** it will be implemented as a co-routine, then do not flatten.  This
123335 122913       ** restriction allows SQL constructs like this:
123336 122914       **
123337 122915       **  SELECT expensive_function(x)
123338 122916       **    FROM (SELECT x FROM tab ORDER BY y LIMIT 10);
123339 122917       **
123340 122918       ** The expensive_function() is only computed on the 10 rows that
123341 122919       ** are output, rather than every row of the table.
123342         -    **
123343         -    ** The requirement that the outer query have a complex result set
123344         -    ** means that flattening does occur on simpler SQL constraints without
123345         -    ** the expensive_function() like:
123346         -    **
123347         -    **  SELECT x FROM (SELECT x FROM tab ORDER BY y LIMIT 10);
123348 122920       */
123349 122921       if( pSub->pOrderBy!=0
123350 122922        && i==0
123351         -     && (p->selFlags & SF_ComplexResult)!=0
123352 122923        && (pTabList->nSrc==1
123353 122924            || (pTabList->a[1].fg.jointype&(JT_LEFT|JT_CROSS))!=0)
123354 122925       ){
123355 122926         continue;
123356 122927       }
123357 122928   
123358 122929       if( flattenSubquery(pParse, p, i, isAgg) ){
................................................................................
123763 123334           assert( pWhere==p->pWhere );
123764 123335           havingToWhere(pParse, pGroupBy, pHaving, &p->pWhere);
123765 123336           pWhere = p->pWhere;
123766 123337         }
123767 123338         sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
123768 123339       }
123769 123340       sAggInfo.nAccumulator = sAggInfo.nColumn;
123770         -    if( p->pGroupBy==0 && p->pHaving==0 && sAggInfo.nFunc==1 ){
123771         -      minMaxFlag = minMaxQuery(db, sAggInfo.aFunc[0].pExpr, &pMinMaxOrderBy);
123772         -    }else{
123773         -      minMaxFlag = WHERE_ORDERBY_NORMAL;
123774         -    }
123775 123341       for(i=0; i<sAggInfo.nFunc; i++){
123776 123342         assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
123777 123343         sNC.ncFlags |= NC_InAggFunc;
123778 123344         sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList);
123779 123345         sNC.ncFlags &= ~NC_InAggFunc;
123780 123346       }
123781 123347       sAggInfo.mxReg = pParse->nMem;
123782 123348       if( db->mallocFailed ) goto select_end;
123783         -#if SELECTTRACE_ENABLED
123784         -    if( sqlite3SelectTrace & 0x400 ){
123785         -      int ii;
123786         -      SELECTTRACE(0x400,pParse,p,("After aggregate analysis:\n"));
123787         -      sqlite3TreeViewSelect(0, p, 0);
123788         -      for(ii=0; ii<sAggInfo.nColumn; ii++){
123789         -        sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
123790         -            ii, sAggInfo.aCol[ii].iMem);
123791         -        sqlite3TreeViewExpr(0, sAggInfo.aCol[ii].pExpr, 0);
123792         -      }
123793         -      for(ii=0; ii<sAggInfo.nFunc; ii++){
123794         -        sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
123795         -            ii, sAggInfo.aFunc[ii].iMem);
123796         -        sqlite3TreeViewExpr(0, sAggInfo.aFunc[ii].pExpr, 0);
123797         -      }
123798         -    }
123799         -#endif
123800         -
123801 123349   
123802 123350       /* Processing for aggregates with GROUP BY is very different and
123803 123351       ** much more complex than aggregates without a GROUP BY.
123804 123352       */
123805 123353       if( pGroupBy ){
123806 123354         KeyInfo *pKeyInfo;  /* Keying information for the group by clause */
123807 123355         int addr1;          /* A-vs-B comparision jump */
................................................................................
124023 123571         */
124024 123572         sqlite3VdbeResolveLabel(v, addrReset);
124025 123573         resetAccumulator(pParse, &sAggInfo);
124026 123574         sqlite3VdbeAddOp1(v, OP_Return, regReset);
124027 123575        
124028 123576       } /* endif pGroupBy.  Begin aggregate queries without GROUP BY: */
124029 123577       else {
       123578  +      ExprList *pDel = 0;
124030 123579   #ifndef SQLITE_OMIT_BTREECOUNT
124031 123580         Table *pTab;
124032 123581         if( (pTab = isSimpleCount(p, &sAggInfo))!=0 ){
124033 123582           /* If isSimpleCount() returns a pointer to a Table structure, then
124034 123583           ** the SQL statement is of the form:
124035 123584           **
124036 123585           **   SELECT count(*) FROM <tbl>
................................................................................
124084 123633           }
124085 123634           sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem);
124086 123635           sqlite3VdbeAddOp1(v, OP_Close, iCsr);
124087 123636           explainSimpleCount(pParse, pTab, pBest);
124088 123637         }else
124089 123638   #endif /* SQLITE_OMIT_BTREECOUNT */
124090 123639         {
       123640  +        /* Check if the query is of one of the following forms:
       123641  +        **
       123642  +        **   SELECT min(x) FROM ...
       123643  +        **   SELECT max(x) FROM ...
       123644  +        **
       123645  +        ** If it is, then ask the code in where.c to attempt to sort results
       123646  +        ** as if there was an "ORDER ON x" or "ORDER ON x DESC" clause. 
       123647  +        ** If where.c is able to produce results sorted in this order, then
       123648  +        ** add vdbe code to break out of the processing loop after the 
       123649  +        ** first iteration (since the first iteration of the loop is 
       123650  +        ** guaranteed to operate on the row with the minimum or maximum 
       123651  +        ** value of x, the only row required).
       123652  +        **
       123653  +        ** A special flag must be passed to sqlite3WhereBegin() to slightly
       123654  +        ** modify behavior as follows:
       123655  +        **
       123656  +        **   + If the query is a "SELECT min(x)", then the loop coded by
       123657  +        **     where.c should not iterate over any values with a NULL value
       123658  +        **     for x.
       123659  +        **
       123660  +        **   + The optimizer code in where.c (the thing that decides which
       123661  +        **     index or indices to use) should place a different priority on 
       123662  +        **     satisfying the 'ORDER BY' clause than it does in other cases.
       123663  +        **     Refer to code and comments in where.c for details.
       123664  +        */
       123665  +        ExprList *pMinMax = 0;
       123666  +        u8 flag = WHERE_ORDERBY_NORMAL;
       123667  +        
       123668  +        assert( p->pGroupBy==0 );
       123669  +        assert( flag==0 );
       123670  +        if( p->pHaving==0 ){
       123671  +          flag = minMaxQuery(&sAggInfo, &pMinMax);
       123672  +        }
       123673  +        assert( flag==0 || (pMinMax!=0 && pMinMax->nExpr==1) );
       123674  +
       123675  +        if( flag ){
       123676  +          pMinMax = sqlite3ExprListDup(db, pMinMax, 0);
       123677  +          pDel = pMinMax;
       123678  +          assert( db->mallocFailed || pMinMax!=0 );
       123679  +          if( !db->mallocFailed ){
       123680  +            pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN ?1:0;
       123681  +            pMinMax->a[0].pExpr->op = TK_COLUMN;
       123682  +          }
       123683  +        }
       123684  +  
124091 123685           /* This case runs if the aggregate has no GROUP BY clause.  The
124092 123686           ** processing is much simpler since there is only a single row
124093 123687           ** of output.
124094 123688           */
124095         -        assert( p->pGroupBy==0 );
124096 123689           resetAccumulator(pParse, &sAggInfo);
124097         -
124098         -        /* If this query is a candidate for the min/max optimization, then
124099         -        ** minMaxFlag will have been previously set to either
124100         -        ** WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX and pMinMaxOrderBy will
124101         -        ** be an appropriate ORDER BY expression for the optimization.
124102         -        */
124103         -        assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
124104         -        assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
124105         -
124106         -        pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
124107         -                                   0, minMaxFlag, 0);
       123690  +        pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMax, 0,flag,0);
124108 123691           if( pWInfo==0 ){
       123692  +          sqlite3ExprListDelete(db, pDel);
124109 123693             goto select_end;
124110 123694           }
124111 123695           updateAccumulator(pParse, &sAggInfo);
       123696  +        assert( pMinMax==0 || pMinMax->nExpr==1 );
124112 123697           if( sqlite3WhereIsOrdered(pWInfo)>0 ){
124113 123698             sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo));
124114 123699             VdbeComment((v, "%s() by index",
124115         -                (minMaxFlag==WHERE_ORDERBY_MIN?"min":"max")));
       123700  +                (flag==WHERE_ORDERBY_MIN?"min":"max")));
124116 123701           }
124117 123702           sqlite3WhereEnd(pWInfo);
124118 123703           finalizeAggFunctions(pParse, &sAggInfo);
124119 123704         }
124120 123705   
124121 123706         sSort.pOrderBy = 0;
124122 123707         sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
124123 123708         selectInnerLoop(pParse, p, -1, 0, 0, 
124124 123709                         pDest, addrEnd, addrEnd);
       123710  +      sqlite3ExprListDelete(db, pDel);
124125 123711       }
124126 123712       sqlite3VdbeResolveLabel(v, addrEnd);
124127 123713       
124128 123714     } /* endif aggregate query */
124129 123715   
124130 123716     if( sDistinct.eTnctType==WHERE_DISTINCT_UNORDERED ){
124131 123717       explainTempTable(pParse, "DISTINCT");
................................................................................
124149 123735     rc = (pParse->nErr>0);
124150 123736   
124151 123737     /* Control jumps to here if an error is encountered above, or upon
124152 123738     ** successful coding of the SELECT.
124153 123739     */
124154 123740   select_end:
124155 123741     explainSetInteger(pParse->iSelectId, iRestoreSelectId);
124156         -  sqlite3ExprListDelete(db, pMinMaxOrderBy);
       123742  +
124157 123743     sqlite3DbFree(db, sAggInfo.aCol);
124158 123744     sqlite3DbFree(db, sAggInfo.aFunc);
124159 123745   #if SELECTTRACE_ENABLED
124160 123746     SELECTTRACE(1,pParse,p,("end processing\n"));
124161 123747     pParse->nSelectIndent--;
124162 123748   #endif
124163 123749     return rc;
................................................................................
125075 124661   
125076 124662       switch( pStep->op ){
125077 124663         case TK_UPDATE: {
125078 124664           sqlite3Update(pParse, 
125079 124665             targetSrcList(pParse, pStep),
125080 124666             sqlite3ExprListDup(db, pStep->pExprList, 0), 
125081 124667             sqlite3ExprDup(db, pStep->pWhere, 0), 
125082         -          pParse->eOrconf, 0, 0, 0
       124668  +          pParse->eOrconf
125083 124669           );
125084 124670           break;
125085 124671         }
125086 124672         case TK_INSERT: {
125087 124673           sqlite3Insert(pParse, 
125088 124674             targetSrcList(pParse, pStep),
125089 124675             sqlite3SelectDup(db, pStep->pSelect, 0), 
................................................................................
125091 124677             pParse->eOrconf
125092 124678           );
125093 124679           break;
125094 124680         }
125095 124681         case TK_DELETE: {
125096 124682           sqlite3DeleteFrom(pParse, 
125097 124683             targetSrcList(pParse, pStep),
125098         -          sqlite3ExprDup(db, pStep->pWhere, 0), 0, 0, 0
       124684  +          sqlite3ExprDup(db, pStep->pWhere, 0)
125099 124685           );
125100 124686           break;
125101 124687         }
125102 124688         default: assert( pStep->op==TK_SELECT ); {
125103 124689           SelectDest sDest;
125104 124690           Select *pSelect = sqlite3SelectDup(db, pStep->pSelect, 0);
125105 124691           sqlite3SelectDestInit(&sDest, SRT_Discard, 0);
................................................................................
125558 125144   *            onError   pTabList      pChanges             pWhere
125559 125145   */
125560 125146   SQLITE_PRIVATE void sqlite3Update(
125561 125147     Parse *pParse,         /* The parser context */
125562 125148     SrcList *pTabList,     /* The table in which we should change things */
125563 125149     ExprList *pChanges,    /* Things to be changed */
125564 125150     Expr *pWhere,          /* The WHERE clause.  May be null */
125565         -  int onError,           /* How to handle constraint errors */
125566         -  ExprList *pOrderBy,    /* ORDER BY clause. May be null */
125567         -  Expr *pLimit,          /* LIMIT clause. May be null */
125568         -  Expr *pOffset          /* OFFSET clause. May be null */
       125151  +  int onError            /* How to handle constraint errors */
125569 125152   ){
125570 125153     int i, j;              /* Loop counters */
125571 125154     Table *pTab;           /* The table to be updated */
125572 125155     int addrTop = 0;       /* VDBE instruction address of the start of the loop */
125573 125156     WhereInfo *pWInfo;     /* Information about the WHERE clause */
125574 125157     Vdbe *v;               /* The virtual database engine */
125575 125158     Index *pIdx;           /* For looping over indices */
................................................................................
125644 125227   # define pTrigger 0
125645 125228   # define isView 0
125646 125229   # define tmask 0
125647 125230   #endif
125648 125231   #ifdef SQLITE_OMIT_VIEW
125649 125232   # undef isView
125650 125233   # define isView 0
125651         -#endif
125652         -
125653         -#ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
125654         -  if( !isView ){
125655         -    pWhere = sqlite3LimitWhere(
125656         -        pParse, pTabList, pWhere, pOrderBy, pLimit, pOffset, "UPDATE"
125657         -    );
125658         -    pOrderBy = 0;
125659         -    pLimit = pOffset = 0;
125660         -  }
125661 125234   #endif
125662 125235   
125663 125236     if( sqlite3ViewGetColumnNames(pParse, pTab) ){
125664 125237       goto update_cleanup;
125665 125238     }
125666 125239     if( sqlite3IsReadOnly(pParse, pTab, tmask) ){
125667 125240       goto update_cleanup;
................................................................................
125824 125397     }
125825 125398   
125826 125399     /* If we are trying to update a view, realize that view into
125827 125400     ** an ephemeral table.
125828 125401     */
125829 125402   #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
125830 125403     if( isView ){
125831         -    sqlite3MaterializeView(pParse, pTab, 
125832         -        pWhere, pOrderBy, pLimit, pOffset, iDataCur
125833         -    );
125834         -    pOrderBy = 0;
125835         -    pLimit = pOffset = 0;
       125404  +    sqlite3MaterializeView(pParse, pTab, pWhere, iDataCur);
125836 125405     }
125837 125406   #endif
125838 125407   
125839 125408     /* Resolve the column names in all the expressions in the
125840 125409     ** WHERE clause.
125841 125410     */
125842 125411     if( sqlite3ResolveExprNames(&sNC, pWhere) ){
................................................................................
126212 125781   
126213 125782   update_cleanup:
126214 125783     sqlite3AuthContextPop(&sContext);
126215 125784     sqlite3DbFree(db, aXRef); /* Also frees aRegIdx[] and aToOpen[] */
126216 125785     sqlite3SrcListDelete(db, pTabList);
126217 125786     sqlite3ExprListDelete(db, pChanges);
126218 125787     sqlite3ExprDelete(db, pWhere);
126219         -#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) 
126220         -  sqlite3ExprListDelete(db, pOrderBy);
126221         -  sqlite3ExprDelete(db, pLimit);
126222         -  sqlite3ExprDelete(db, pOffset);
126223         -#endif
126224 125788     return;
126225 125789   }
126226 125790   /* Make sure "isView" and other macros defined above are undefined. Otherwise
126227 125791   ** they may interfere with compilation of other functions in this file
126228 125792   ** (or in another file, if this file becomes part of the amalgamation).  */
126229 125793   #ifdef isView
126230 125794    #undef isView
................................................................................
128847 128411   ** term was originally TERM_LIKE, then the parent gets TERM_LIKECOND instead.
128848 128412   ** The TERM_LIKECOND marking indicates that the term should be coded inside
128849 128413   ** a conditional such that is only evaluated on the second pass of a
128850 128414   ** LIKE-optimization loop, when scanning BLOBs instead of strings.
128851 128415   */
128852 128416   static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
128853 128417     int nLoop = 0;
128854         -  assert( pTerm!=0 );
128855         -  while( (pTerm->wtFlags & TERM_CODED)==0
       128418  +  while( ALWAYS(pTerm!=0)
       128419  +      && (pTerm->wtFlags & TERM_CODED)==0
128856 128420         && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
128857 128421         && (pLevel->notReady & pTerm->prereqAll)==0
128858 128422     ){
128859 128423       if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
128860 128424         pTerm->wtFlags |= TERM_LIKECOND;
128861 128425       }else{
128862 128426         pTerm->wtFlags |= TERM_CODED;
128863 128427       }
128864 128428       if( pTerm->iParent<0 ) break;
128865 128429       pTerm = &pTerm->pWC->a[pTerm->iParent];
128866         -    assert( pTerm!=0 );
128867 128430       pTerm->nChild--;
128868 128431       if( pTerm->nChild!=0 ) break;
128869 128432       nLoop++;
128870 128433     }
128871 128434   }
128872 128435   
128873 128436   /*
................................................................................
131692 131255     Bitmask extraRight = 0;          /* Extra dependencies on LEFT JOIN */
131693 131256     Expr *pStr1 = 0;                 /* RHS of LIKE/GLOB operator */
131694 131257     int isComplete = 0;              /* RHS of LIKE/GLOB ends with wildcard */
131695 131258     int noCase = 0;                  /* uppercase equivalent to lowercase */
131696 131259     int op;                          /* Top-level operator.  pExpr->op */
131697 131260     Parse *pParse = pWInfo->pParse;  /* Parsing context */
131698 131261     sqlite3 *db = pParse->db;        /* Database connection */
131699         -  unsigned char eOp2 = 0;          /* op2 value for LIKE/REGEXP/GLOB */
       131262  +  unsigned char eOp2;              /* op2 value for LIKE/REGEXP/GLOB */
131700 131263     int nLeft;                       /* Number of elements on left side vector */
131701 131264   
131702 131265     if( db->mallocFailed ){
131703 131266       return;
131704 131267     }
131705 131268     pTerm = &pWC->a[idxTerm];
131706 131269     pMaskSet = &pWInfo->sMaskSet;
................................................................................
131936 131499     ** not normally optimized for ordinary tables.  In other words, OP
131937 131500     ** is one of MATCH, LIKE, GLOB, REGEXP, !=, IS, IS NOT, or NOT NULL.
131938 131501     ** This information is used by the xBestIndex methods of
131939 131502     ** virtual tables.  The native query optimizer does not attempt
131940 131503     ** to do anything with MATCH functions.
131941 131504     */
131942 131505     if( pWC->op==TK_AND ){
131943         -    Expr *pRight = 0, *pLeft = 0;
       131506  +    Expr *pRight, *pLeft;
131944 131507       int res = isAuxiliaryVtabOperator(pExpr, &eOp2, &pLeft, &pRight);
131945 131508       while( res-- > 0 ){
131946 131509         int idxNew;
131947 131510         WhereTerm *pNewTerm;
131948 131511         Bitmask prereqColumn, prereqExpr;
131949 131512   
131950 131513         prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight);
................................................................................
134104 133667     sqlite3DbFreeNN(db, p);
134105 133668   }
134106 133669   
134107 133670   /*
134108 133671   ** Free a WhereInfo structure
134109 133672   */
134110 133673   static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
134111         -  int i;
134112         -  assert( pWInfo!=0 );
134113         -  for(i=0; i<pWInfo->nLevel; i++){
134114         -    WhereLevel *pLevel = &pWInfo->a[i];
134115         -    if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
134116         -      sqlite3DbFree(db, pLevel->u.in.aInLoop);
       133674  +  if( ALWAYS(pWInfo) ){
       133675  +    int i;
       133676  +    for(i=0; i<pWInfo->nLevel; i++){
       133677  +      WhereLevel *pLevel = &pWInfo->a[i];
       133678  +      if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
       133679  +        sqlite3DbFree(db, pLevel->u.in.aInLoop);
       133680  +      }
134117 133681       }
       133682  +    sqlite3WhereClauseClear(&pWInfo->sWC);
       133683  +    while( pWInfo->pLoops ){
       133684  +      WhereLoop *p = pWInfo->pLoops;
       133685  +      pWInfo->pLoops = p->pNextLoop;
       133686  +      whereLoopDelete(db, p);
       133687  +    }
       133688  +    sqlite3DbFreeNN(db, pWInfo);
134118 133689     }
134119         -  sqlite3WhereClauseClear(&pWInfo->sWC);
134120         -  while( pWInfo->pLoops ){
134121         -    WhereLoop *p = pWInfo->pLoops;
134122         -    pWInfo->pLoops = p->pNextLoop;
134123         -    whereLoopDelete(db, p);
134124         -  }
134125         -  sqlite3DbFreeNN(db, pWInfo);
134126 133690   }
134127 133691   
134128 133692   /*
134129 133693   ** Return TRUE if all of the following are true:
134130 133694   **
134131 133695   **   (1)  X has the same or lower cost that Y
134132 133696   **   (2)  X uses fewer WHERE clause terms than Y
................................................................................
135110 134674           pNew->prereq = mPrereq | pTerm->prereqRight;
135111 134675           rc = whereLoopInsert(pBuilder, pNew);
135112 134676         }
135113 134677       }
135114 134678     }
135115 134679   #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
135116 134680   
135117         -  /* Loop over all indices. If there was an INDEXED BY clause, then only 
135118         -  ** consider index pProbe.  */
135119         -  for(; rc==SQLITE_OK && pProbe; 
135120         -      pProbe=(pSrc->pIBIndex ? 0 : pProbe->pNext), iSortIdx++
135121         -  ){
       134681  +  /* Loop over all indices
       134682  +  */
       134683  +  for(; rc==SQLITE_OK && pProbe; pProbe=pProbe->pNext, iSortIdx++){
135122 134684       if( pProbe->pPartIdxWhere!=0
135123 134685        && !whereUsablePartialIndex(pSrc->iCursor, pWC, pProbe->pPartIdxWhere) ){
135124 134686         testcase( pNew->iTab!=pSrc->iCursor );  /* See ticket [98d973b8f5] */
135125 134687         continue;  /* Partial index inappropriate for this query */
135126 134688       }
135127 134689       rSize = pProbe->aiRowLogEst[0];
135128 134690       pNew->u.btree.nEq = 0;
................................................................................
135224 134786         pTab->tabFlags |= TF_StatsUsed;
135225 134787       }
135226 134788   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
135227 134789       sqlite3Stat4ProbeFree(pBuilder->pRec);
135228 134790       pBuilder->nRecValid = 0;
135229 134791       pBuilder->pRec = 0;
135230 134792   #endif
       134793  +
       134794  +    /* If there was an INDEXED BY clause, then only that one index is
       134795  +    ** considered. */
       134796  +    if( pSrc->pIBIndex ) break;
135231 134797     }
135232 134798     return rc;
135233 134799   }
135234 134800   
135235 134801   #ifndef SQLITE_OMIT_VIRTUALTABLE
135236 134802   
135237 134803   /*
................................................................................
140158 139724         case 132: /* limit_opt ::= LIMIT expr COMMA expr */
140159 139725   {yymsp[-3].minor.yy354.pOffset = yymsp[-2].minor.yy190.pExpr; yymsp[-3].minor.yy354.pLimit = yymsp[0].minor.yy190.pExpr;}
140160 139726           break;
140161 139727         case 133: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
140162 139728   {
140163 139729     sqlite3WithPush(pParse, yymsp[-5].minor.yy285, 1);
140164 139730     sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy185, &yymsp[-1].minor.yy0);
140165         -  sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy185,yymsp[0].minor.yy72,0,0,0);
       139731  +  sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy185,yymsp[0].minor.yy72);
140166 139732   }
140167 139733           break;
140168 139734         case 136: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
140169 139735   {
140170 139736     sqlite3WithPush(pParse, yymsp[-7].minor.yy285, 1);
140171 139737     sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy185, &yymsp[-3].minor.yy0);
140172 139738     sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy148,"set list"); 
140173         -  sqlite3Update(pParse,yymsp[-4].minor.yy185,yymsp[-1].minor.yy148,yymsp[0].minor.yy72,yymsp[-5].minor.yy194,0,0,0);
       139739  +  sqlite3Update(pParse,yymsp[-4].minor.yy185,yymsp[-1].minor.yy148,yymsp[0].minor.yy72,yymsp[-5].minor.yy194);
140174 139740   }
140175 139741           break;
140176 139742         case 137: /* setlist ::= setlist COMMA nm EQ expr */
140177 139743   {
140178 139744     yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr);
140179 139745     sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy148, &yymsp[-2].minor.yy0, 1);
140180 139746   }
................................................................................
143722 143288         case SQLITE_BUSY_RECOVERY:      zName = "SQLITE_BUSY_RECOVERY";     break;
143723 143289         case SQLITE_BUSY_SNAPSHOT:      zName = "SQLITE_BUSY_SNAPSHOT";     break;
143724 143290         case SQLITE_LOCKED:             zName = "SQLITE_LOCKED";            break;
143725 143291         case SQLITE_LOCKED_SHAREDCACHE: zName = "SQLITE_LOCKED_SHAREDCACHE";break;
143726 143292         case SQLITE_NOMEM:              zName = "SQLITE_NOMEM";             break;
143727 143293         case SQLITE_READONLY:           zName = "SQLITE_READONLY";          break;
143728 143294         case SQLITE_READONLY_RECOVERY:  zName = "SQLITE_READONLY_RECOVERY"; break;
143729         -      case SQLITE_READONLY_CANTINIT:  zName = "SQLITE_READONLY_CANTINIT"; break;
       143295  +      case SQLITE_READONLY_CANTLOCK:  zName = "SQLITE_READONLY_CANTLOCK"; break;
143730 143296         case SQLITE_READONLY_ROLLBACK:  zName = "SQLITE_READONLY_ROLLBACK"; break;
143731 143297         case SQLITE_READONLY_DBMOVED:   zName = "SQLITE_READONLY_DBMOVED";  break;
143732 143298         case SQLITE_INTERRUPT:          zName = "SQLITE_INTERRUPT";         break;
143733 143299         case SQLITE_IOERR:              zName = "SQLITE_IOERR";             break;
143734 143300         case SQLITE_IOERR_READ:         zName = "SQLITE_IOERR_READ";        break;
143735 143301         case SQLITE_IOERR_SHORT_READ:   zName = "SQLITE_IOERR_SHORT_READ";  break;
143736 143302         case SQLITE_IOERR_WRITE:        zName = "SQLITE_IOERR_WRITE";       break;
................................................................................
166271 165837   #define RTREE_REINSERT(p) RTREE_MINCELLS(p)
166272 165838   #define RTREE_MAXCELLS 51
166273 165839   
166274 165840   /*
166275 165841   ** The smallest possible node-size is (512-64)==448 bytes. And the largest
166276 165842   ** supported cell size is 48 bytes (8 byte rowid + ten 4 byte coordinates).
166277 165843   ** Therefore all non-root nodes must contain at least 3 entries. Since 
166278         -** 3^40 is greater than 2^64, an r-tree structure always has a depth of
       165844  +** 2^40 is greater than 2^64, an r-tree structure always has a depth of
166279 165845   ** 40 or less.
166280 165846   */
166281 165847   #define RTREE_MAX_DEPTH 40
166282 165848   
166283 165849   
166284 165850   /*
166285 165851   ** Number of entries in the cursor RtreeNode cache.  The first entry is
................................................................................
169669 169235     ){
169670 169236       sqlite3_result_error(ctx, "Invalid argument to rtreedepth()", -1); 
169671 169237     }else{
169672 169238       u8 *zBlob = (u8 *)sqlite3_value_blob(apArg[0]);
169673 169239       sqlite3_result_int(ctx, readInt16(zBlob));
169674 169240     }
169675 169241   }
169676         -
169677         -/*
169678         -** Context object passed between the various routines that make up the
169679         -** implementation of integrity-check function rtreecheck().
169680         -*/
169681         -typedef struct RtreeCheck RtreeCheck;
169682         -struct RtreeCheck {
169683         -  sqlite3 *db;                    /* Database handle */
169684         -  const char *zDb;                /* Database containing rtree table */
169685         -  const char *zTab;               /* Name of rtree table */
169686         -  int bInt;                       /* True for rtree_i32 table */
169687         -  int nDim;                       /* Number of dimensions for this rtree tbl */
169688         -  sqlite3_stmt *pGetNode;         /* Statement used to retrieve nodes */
169689         -  sqlite3_stmt *aCheckMapping[2]; /* Statements to query %_parent/%_rowid */
169690         -  int nLeaf;                      /* Number of leaf cells in table */
169691         -  int nNonLeaf;                   /* Number of non-leaf cells in table */
169692         -  int rc;                         /* Return code */
169693         -  char *zReport;                  /* Message to report */
169694         -  int nErr;                       /* Number of lines in zReport */
169695         -};
169696         -
169697         -#define RTREE_CHECK_MAX_ERROR 100
169698         -
169699         -/*
169700         -** Reset SQL statement pStmt. If the sqlite3_reset() call returns an error,
169701         -** and RtreeCheck.rc==SQLITE_OK, set RtreeCheck.rc to the error code.
169702         -*/
169703         -static void rtreeCheckReset(RtreeCheck *pCheck, sqlite3_stmt *pStmt){
169704         -  int rc = sqlite3_reset(pStmt);
169705         -  if( pCheck->rc==SQLITE_OK ) pCheck->rc = rc;
169706         -}
169707         -
169708         -/*
169709         -** The second and subsequent arguments to this function are a format string
169710         -** and printf style arguments. This function formats the string and attempts
169711         -** to compile it as an SQL statement.
169712         -**
169713         -** If successful, a pointer to the new SQL statement is returned. Otherwise,
169714         -** NULL is returned and an error code left in RtreeCheck.rc.
169715         -*/
169716         -static sqlite3_stmt *rtreeCheckPrepare(
169717         -  RtreeCheck *pCheck,             /* RtreeCheck object */
169718         -  const char *zFmt, ...           /* Format string and trailing args */
169719         -){
169720         -  va_list ap;
169721         -  char *z;
169722         -  sqlite3_stmt *pRet = 0;
169723         -
169724         -  va_start(ap, zFmt);
169725         -  z = sqlite3_vmprintf(zFmt, ap);
169726         -
169727         -  if( pCheck->rc==SQLITE_OK ){
169728         -    if( z==0 ){
169729         -      pCheck->rc = SQLITE_NOMEM;
169730         -    }else{
169731         -      pCheck->rc = sqlite3_prepare_v2(pCheck->db, z, -1, &pRet, 0);
169732         -    }
169733         -  }
169734         -
169735         -  sqlite3_free(z);
169736         -  va_end(ap);
169737         -  return pRet;
169738         -}
169739         -
169740         -/*
169741         -** The second and subsequent arguments to this function are a printf()
169742         -** style format string and arguments. This function formats the string and
169743         -** appends it to the report being accumuated in pCheck.
169744         -*/
169745         -static void rtreeCheckAppendMsg(RtreeCheck *pCheck, const char *zFmt, ...){
169746         -  va_list ap;
169747         -  va_start(ap, zFmt);
169748         -  if( pCheck->rc==SQLITE_OK && pCheck->nErr<RTREE_CHECK_MAX_ERROR ){
169749         -    char *z = sqlite3_vmprintf(zFmt, ap);
169750         -    if( z==0 ){
169751         -      pCheck->rc = SQLITE_NOMEM;
169752         -    }else{
169753         -      pCheck->zReport = sqlite3_mprintf("%z%s%z", 
169754         -          pCheck->zReport, (pCheck->zReport ? "\n" : ""), z
169755         -      );
169756         -      if( pCheck->zReport==0 ){
169757         -        pCheck->rc = SQLITE_NOMEM;
169758         -      }
169759         -    }
169760         -    pCheck->nErr++;
169761         -  }
169762         -  va_end(ap);
169763         -}
169764         -
169765         -/*
169766         -** This function is a no-op if there is already an error code stored
169767         -** in the RtreeCheck object indicated by the first argument. NULL is
169768         -** returned in this case.
169769         -**
169770         -** Otherwise, the contents of rtree table node iNode are loaded from
169771         -** the database and copied into a buffer obtained from sqlite3_malloc().
169772         -** If no error occurs, a pointer to the buffer is returned and (*pnNode)
169773         -** is set to the size of the buffer in bytes.
169774         -**
169775         -** Or, if an error does occur, NULL is returned and an error code left
169776         -** in the RtreeCheck object. The final value of *pnNode is undefined in
169777         -** this case.
169778         -*/
169779         -static u8 *rtreeCheckGetNode(RtreeCheck *pCheck, i64 iNode, int *pnNode){
169780         -  u8 *pRet = 0;                   /* Return value */
169781         -
169782         -  assert( pCheck->rc==SQLITE_OK );
169783         -  if( pCheck->pGetNode==0 ){
169784         -    pCheck->pGetNode = rtreeCheckPrepare(pCheck,
169785         -        "SELECT data FROM %Q.'%q_node' WHERE nodeno=?", 
169786         -        pCheck->zDb, pCheck->zTab
169787         -    );
169788         -  }
169789         -
169790         -  if( pCheck->rc==SQLITE_OK ){
169791         -    sqlite3_bind_int64(pCheck->pGetNode, 1, iNode);
169792         -    if( sqlite3_step(pCheck->pGetNode)==SQLITE_ROW ){
169793         -      int nNode = sqlite3_column_bytes(pCheck->pGetNode, 0);
169794         -      const u8 *pNode = (const u8*)sqlite3_column_blob(pCheck->pGetNode, 0);
169795         -      pRet = sqlite3_malloc(nNode);
169796         -      if( pRet==0 ){
169797         -        pCheck->rc = SQLITE_NOMEM;
169798         -      }else{
169799         -        memcpy(pRet, pNode, nNode);
169800         -        *pnNode = nNode;
169801         -      }
169802         -    }
169803         -    rtreeCheckReset(pCheck, pCheck->pGetNode);
169804         -    if( pCheck->rc==SQLITE_OK && pRet==0 ){
169805         -      rtreeCheckAppendMsg(pCheck, "Node %lld missing from database", iNode);
169806         -    }
169807         -  }
169808         -
169809         -  return pRet;
169810         -}
169811         -
169812         -/*
169813         -** This function is used to check that the %_parent (if bLeaf==0) or %_rowid
169814         -** (if bLeaf==1) table contains a specified entry. The schemas of the
169815         -** two tables are:
169816         -**
169817         -**   CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER)
169818         -**   CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER)
169819         -**
169820         -** In both cases, this function checks that there exists an entry with
169821         -** IPK value iKey and the second column set to iVal.
169822         -**
169823         -*/
169824         -static void rtreeCheckMapping(
169825         -  RtreeCheck *pCheck,             /* RtreeCheck object */
169826         -  int bLeaf,                      /* True for a leaf cell, false for interior */
169827         -  i64 iKey,                       /* Key for mapping */
169828         -  i64 iVal                        /* Expected value for mapping */
169829         -){
169830         -  int rc;
169831         -  sqlite3_stmt *pStmt;
169832         -  const char *azSql[2] = {
169833         -    "SELECT parentnode FROM %Q.'%q_parent' WHERE nodeno=?",
169834         -    "SELECT nodeno FROM %Q.'%q_rowid' WHERE rowid=?"
169835         -  };
169836         -
169837         -  assert( bLeaf==0 || bLeaf==1 );
169838         -  if( pCheck->aCheckMapping[bLeaf]==0 ){
169839         -    pCheck->aCheckMapping[bLeaf] = rtreeCheckPrepare(pCheck,
169840         -        azSql[bLeaf], pCheck->zDb, pCheck->zTab
169841         -    );
169842         -  }
169843         -  if( pCheck->rc!=SQLITE_OK ) return;
169844         -
169845         -  pStmt = pCheck->aCheckMapping[bLeaf];
169846         -  sqlite3_bind_int64(pStmt, 1, iKey);
169847         -  rc = sqlite3_step(pStmt);
169848         -  if( rc==SQLITE_DONE ){
169849         -    rtreeCheckAppendMsg(pCheck, "Mapping (%lld -> %lld) missing from %s table",
169850         -        iKey, iVal, (bLeaf ? "%_rowid" : "%_parent")
169851         -    );
169852         -  }else if( rc==SQLITE_ROW ){
169853         -    i64 ii = sqlite3_column_int64(pStmt, 0);
169854         -    if( ii!=iVal ){
169855         -      rtreeCheckAppendMsg(pCheck, 
169856         -          "Found (%lld -> %lld) in %s table, expected (%lld -> %lld)",
169857         -          iKey, ii, (bLeaf ? "%_rowid" : "%_parent"), iKey, iVal
169858         -      );
169859         -    }
169860         -  }
169861         -  rtreeCheckReset(pCheck, pStmt);
169862         -}
169863         -
169864         -/*
169865         -** Argument pCell points to an array of coordinates stored on an rtree page.
169866         -** This function checks that the coordinates are internally consistent (no
169867         -** x1>x2 conditions) and adds an error message to the RtreeCheck object
169868         -** if they are not.
169869         -**
169870         -** Additionally, if pParent is not NULL, then it is assumed to point to
169871         -** the array of coordinates on the parent page that bound the page 
169872         -** containing pCell. In this case it is also verified that the two
169873         -** sets of coordinates are mutually consistent and an error message added
169874         -** to the RtreeCheck object if they are not.
169875         -*/
169876         -static void rtreeCheckCellCoord(
169877         -  RtreeCheck *pCheck, 
169878         -  i64 iNode,                      /* Node id to use in error messages */
169879         -  int iCell,                      /* Cell number to use in error messages */
169880         -  u8 *pCell,                      /* Pointer to cell coordinates */
169881         -  u8 *pParent                     /* Pointer to parent coordinates */
169882         -){
169883         -  RtreeCoord c1, c2;
169884         -  RtreeCoord p1, p2;
169885         -  int i;
169886         -
169887         -  for(i=0; i<pCheck->nDim; i++){
169888         -    readCoord(&pCell[4*2*i], &c1);
169889         -    readCoord(&pCell[4*(2*i + 1)], &c2);
169890         -
169891         -    /* printf("%e, %e\n", c1.u.f, c2.u.f); */
169892         -    if( pCheck->bInt ? c1.i>c2.i : c1.f>c2.f ){
169893         -      rtreeCheckAppendMsg(pCheck, 
169894         -          "Dimension %d of cell %d on node %lld is corrupt", i, iCell, iNode
169895         -      );
169896         -    }
169897         -
169898         -    if( pParent ){
169899         -      readCoord(&pParent[4*2*i], &p1);
169900         -      readCoord(&pParent[4*(2*i + 1)], &p2);
169901         -
169902         -      if( (pCheck->bInt ? c1.i<p1.i : c1.f<p1.f) 
169903         -       || (pCheck->bInt ? c2.i>p2.i : c2.f>p2.f)
169904         -      ){
169905         -        rtreeCheckAppendMsg(pCheck, 
169906         -            "Dimension %d of cell %d on node %lld is corrupt relative to parent"
169907         -            , i, iCell, iNode
169908         -        );
169909         -      }
169910         -    }
169911         -  }
169912         -}
169913         -
169914         -/*
169915         -** Run rtreecheck() checks on node iNode, which is at depth iDepth within
169916         -** the r-tree structure. Argument aParent points to the array of coordinates
169917         -** that bound node iNode on the parent node.
169918         -**
169919         -** If any problems are discovered, an error message is appended to the
169920         -** report accumulated in the RtreeCheck object.
169921         -*/
169922         -static void rtreeCheckNode(
169923         -  RtreeCheck *pCheck,
169924         -  int iDepth,                     /* Depth of iNode (0==leaf) */
169925         -  u8 *aParent,                    /* Buffer containing parent coords */
169926         -  i64 iNode                       /* Node to check */
169927         -){
169928         -  u8 *aNode = 0;
169929         -  int nNode = 0;
169930         -
169931         -  assert( iNode==1 || aParent!=0 );
169932         -  assert( pCheck->nDim>0 );
169933         -
169934         -  aNode = rtreeCheckGetNode(pCheck, iNode, &nNode);
169935         -  if( aNode ){
169936         -    if( nNode<4 ){
169937         -      rtreeCheckAppendMsg(pCheck, 
169938         -          "Node %lld is too small (%d bytes)", iNode, nNode
169939         -      );
169940         -    }else{
169941         -      int nCell;                  /* Number of cells on page */
169942         -      int i;                      /* Used to iterate through cells */
169943         -      if( aParent==0 ){
169944         -        iDepth = readInt16(aNode);
169945         -        if( iDepth>RTREE_MAX_DEPTH ){
169946         -          rtreeCheckAppendMsg(pCheck, "Rtree depth out of range (%d)", iDepth);
169947         -          sqlite3_free(aNode);
169948         -          return;
169949         -        }
169950         -      }
169951         -      nCell = readInt16(&aNode[2]);
169952         -      if( (4 + nCell*(8 + pCheck->nDim*2*4))>nNode ){
169953         -        rtreeCheckAppendMsg(pCheck, 
169954         -            "Node %lld is too small for cell count of %d (%d bytes)", 
169955         -            iNode, nCell, nNode
169956         -        );
169957         -      }else{
169958         -        for(i=0; i<nCell; i++){
169959         -          u8 *pCell = &aNode[4 + i*(8 + pCheck->nDim*2*4)];
169960         -          i64 iVal = readInt64(pCell);
169961         -          rtreeCheckCellCoord(pCheck, iNode, i, &pCell[8], aParent);
169962         -
169963         -          if( iDepth>0 ){
169964         -            rtreeCheckMapping(pCheck, 0, iVal, iNode);
169965         -            rtreeCheckNode(pCheck, iDepth-1, &pCell[8], iVal);
169966         -            pCheck->nNonLeaf++;
169967         -          }else{
169968         -            rtreeCheckMapping(pCheck, 1, iVal, iNode);
169969         -            pCheck->nLeaf++;
169970         -          }
169971         -        }
169972         -      }
169973         -    }
169974         -    sqlite3_free(aNode);
169975         -  }
169976         -}
169977         -
169978         -/*
169979         -** The second argument to this function must be either "_rowid" or
169980         -** "_parent". This function checks that the number of entries in the
169981         -** %_rowid or %_parent table is exactly nExpect. If not, it adds
169982         -** an error message to the report in the RtreeCheck object indicated
169983         -** by the first argument.
169984         -*/
169985         -static void rtreeCheckCount(RtreeCheck *pCheck, const char *zTbl, i64 nExpect){
169986         -  if( pCheck->rc==SQLITE_OK ){
169987         -    sqlite3_stmt *pCount;
169988         -    pCount = rtreeCheckPrepare(pCheck, "SELECT count(*) FROM %Q.'%q%s'",
169989         -        pCheck->zDb, pCheck->zTab, zTbl
169990         -    );
169991         -    if( pCount ){
169992         -      if( sqlite3_step(pCount)==SQLITE_ROW ){
169993         -        i64 nActual = sqlite3_column_int64(pCount, 0);
169994         -        if( nActual!=nExpect ){
169995         -          rtreeCheckAppendMsg(pCheck, "Wrong number of entries in %%%s table"
169996         -              " - expected %lld, actual %lld" , zTbl, nExpect, nActual
169997         -          );
169998         -        }
169999         -      }
170000         -      pCheck->rc = sqlite3_finalize(pCount);
170001         -    }
170002         -  }
170003         -}
170004         -
170005         -/*
170006         -** This function does the bulk of the work for the rtree integrity-check.
170007         -** It is called by rtreecheck(), which is the SQL function implementation.
170008         -*/
170009         -static int rtreeCheckTable(
170010         -  sqlite3 *db,                    /* Database handle to access db through */
170011         -  const char *zDb,                /* Name of db ("main", "temp" etc.) */
170012         -  const char *zTab,               /* Name of rtree table to check */
170013         -  char **pzReport                 /* OUT: sqlite3_malloc'd report text */
170014         -){
170015         -  RtreeCheck check;               /* Common context for various routines */
170016         -  sqlite3_stmt *pStmt = 0;        /* Used to find column count of rtree table */
170017         -  int bEnd = 0;                   /* True if transaction should be closed */
170018         -
170019         -  /* Initialize the context object */
170020         -  memset(&check, 0, sizeof(check));
170021         -  check.db = db;
170022         -  check.zDb = zDb;
170023         -  check.zTab = zTab;
170024         -
170025         -  /* If there is not already an open transaction, open one now. This is
170026         -  ** to ensure that the queries run as part of this integrity-check operate
170027         -  ** on a consistent snapshot.  */
170028         -  if( sqlite3_get_autocommit(db) ){
170029         -    check.rc = sqlite3_exec(db, "BEGIN", 0, 0, 0);
170030         -    bEnd = 1;
170031         -  }
170032         -
170033         -  /* Find number of dimensions in the rtree table. */
170034         -  pStmt = rtreeCheckPrepare(&check, "SELECT * FROM %Q.%Q", zDb, zTab);
170035         -  if( pStmt ){
170036         -    int rc;
170037         -    check.nDim = (sqlite3_column_count(pStmt) - 1) / 2;
170038         -    if( check.nDim<1 ){
170039         -      rtreeCheckAppendMsg(&check, "Schema corrupt or not an rtree");
170040         -    }else if( SQLITE_ROW==sqlite3_step(pStmt) ){
170041         -      check.bInt = (sqlite3_column_type(pStmt, 1)==SQLITE_INTEGER);
170042         -    }
170043         -    rc = sqlite3_finalize(pStmt);
170044         -    if( rc!=SQLITE_CORRUPT ) check.rc = rc;
170045         -  }
170046         -
170047         -  /* Do the actual integrity-check */
170048         -  if( check.nDim>=1 ){
170049         -    if( check.rc==SQLITE_OK ){
170050         -      rtreeCheckNode(&check, 0, 0, 1);
170051         -    }
170052         -    rtreeCheckCount(&check, "_rowid", check.nLeaf);
170053         -    rtreeCheckCount(&check, "_parent", check.nNonLeaf);
170054         -  }
170055         -
170056         -  /* Finalize SQL statements used by the integrity-check */
170057         -  sqlite3_finalize(check.pGetNode);
170058         -  sqlite3_finalize(check.aCheckMapping[0]);
170059         -  sqlite3_finalize(check.aCheckMapping[1]);
170060         -
170061         -  /* If one was opened, close the transaction */
170062         -  if( bEnd ){
170063         -    int rc = sqlite3_exec(db, "END", 0, 0, 0);
170064         -    if( check.rc==SQLITE_OK ) check.rc = rc;
170065         -  }
170066         -  *pzReport = check.zReport;
170067         -  return check.rc;
170068         -}
170069         -
170070         -/*
170071         -** Usage:
170072         -**
170073         -**   rtreecheck(<rtree-table>);
170074         -**   rtreecheck(<database>, <rtree-table>);
170075         -**
170076         -** Invoking this SQL function runs an integrity-check on the named rtree
170077         -** table. The integrity-check verifies the following:
170078         -**
170079         -**   1. For each cell in the r-tree structure (%_node table), that:
170080         -**
170081         -**       a) for each dimension, (coord1 <= coord2).
170082         -**
170083         -**       b) unless the cell is on the root node, that the cell is bounded
170084         -**          by the parent cell on the parent node.
170085         -**
170086         -**       c) for leaf nodes, that there is an entry in the %_rowid 
170087         -**          table corresponding to the cell's rowid value that 
170088         -**          points to the correct node.
170089         -**
170090         -**       d) for cells on non-leaf nodes, that there is an entry in the 
170091         -**          %_parent table mapping from the cell's child node to the
170092         -**          node that it resides on.
170093         -**
170094         -**   2. That there are the same number of entries in the %_rowid table
170095         -**      as there are leaf cells in the r-tree structure, and that there
170096         -**      is a leaf cell that corresponds to each entry in the %_rowid table.
170097         -**
170098         -**   3. That there are the same number of entries in the %_parent table
170099         -**      as there are non-leaf cells in the r-tree structure, and that 
170100         -**      there is a non-leaf cell that corresponds to each entry in the 
170101         -**      %_parent table.
170102         -*/
170103         -static void rtreecheck(
170104         -  sqlite3_context *ctx, 
170105         -  int nArg, 
170106         -  sqlite3_value **apArg
170107         -){
170108         -  if( nArg!=1 && nArg!=2 ){
170109         -    sqlite3_result_error(ctx, 
170110         -        "wrong number of arguments to function rtreecheck()", -1
170111         -    );
170112         -  }else{
170113         -    int rc;
170114         -    char *zReport = 0;
170115         -    const char *zDb = (const char*)sqlite3_value_text(apArg[0]);
170116         -    const char *zTab;
170117         -    if( nArg==1 ){
170118         -      zTab = zDb;
170119         -      zDb = "main";
170120         -    }else{
170121         -      zTab = (const char*)sqlite3_value_text(apArg[1]);
170122         -    }
170123         -    rc = rtreeCheckTable(sqlite3_context_db_handle(ctx), zDb, zTab, &zReport);
170124         -    if( rc==SQLITE_OK ){
170125         -      sqlite3_result_text(ctx, zReport ? zReport : "ok", -1, SQLITE_TRANSIENT);
170126         -    }else{
170127         -      sqlite3_result_error_code(ctx, rc);
170128         -    }
170129         -    sqlite3_free(zReport);
170130         -  }
170131         -}
170132         -
170133 169242   
170134 169243   /*
170135 169244   ** Register the r-tree module with database handle db. This creates the
170136 169245   ** virtual table module "rtree" and the debugging/analysis scalar 
170137 169246   ** function "rtreenode".
170138 169247   */
170139 169248   SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db){
................................................................................
170140 169249     const int utf8 = SQLITE_UTF8;
170141 169250     int rc;
170142 169251   
170143 169252     rc = sqlite3_create_function(db, "rtreenode", 2, utf8, 0, rtreenode, 0, 0);
170144 169253     if( rc==SQLITE_OK ){
170145 169254       rc = sqlite3_create_function(db, "rtreedepth", 1, utf8, 0,rtreedepth, 0, 0);
170146 169255     }
170147         -  if( rc==SQLITE_OK ){
170148         -    rc = sqlite3_create_function(db, "rtreecheck", -1, utf8, 0,rtreecheck, 0,0);
170149         -  }
170150 169256     if( rc==SQLITE_OK ){
170151 169257   #ifdef SQLITE_RTREE_INT_ONLY
170152 169258       void *c = (void *)RTREE_COORD_INT32;
170153 169259   #else
170154 169260       void *c = (void *)RTREE_COORD_REAL32;
170155 169261   #endif
170156 169262       rc = sqlite3_create_module_v2(db, "rtree", &rtreeModule, c, 0);
................................................................................
177347 176453   typedef struct DbpageTable DbpageTable;
177348 176454   typedef struct DbpageCursor DbpageCursor;
177349 176455   
177350 176456   struct DbpageCursor {
177351 176457     sqlite3_vtab_cursor base;       /* Base class.  Must be first */
177352 176458     int pgno;                       /* Current page number */
177353 176459     int mxPgno;                     /* Last page to visit on this scan */
177354         -  Pager *pPager;                  /* Pager being read/written */
177355         -  DbPage *pPage1;                 /* Page 1 of the database */
177356         -  int iDb;                        /* Index of database to analyze */
177357         -  int szPage;                     /* Size of each page in bytes */
177358 176460   };
177359 176461   
177360 176462   struct DbpageTable {
177361 176463     sqlite3_vtab base;              /* Base class.  Must be first */
177362 176464     sqlite3 *db;                    /* The database */
       176465  +  Pager *pPager;                  /* Pager being read/written */
       176466  +  int iDb;                        /* Index of database to analyze */
       176467  +  int szPage;                     /* Size of each page in bytes */
       176468  +  int nPage;                      /* Number of pages in the file */
177363 176469   };
177364         -
177365         -/* Columns */
177366         -#define DBPAGE_COLUMN_PGNO    0
177367         -#define DBPAGE_COLUMN_DATA    1
177368         -#define DBPAGE_COLUMN_SCHEMA  2
177369         -
177370         -
177371 176470   
177372 176471   /*
177373 176472   ** Connect to or create a dbpagevfs virtual table.
177374 176473   */
177375 176474   static int dbpageConnect(
177376 176475     sqlite3 *db,
177377 176476     void *pAux,
177378 176477     int argc, const char *const*argv,
177379 176478     sqlite3_vtab **ppVtab,
177380 176479     char **pzErr
177381 176480   ){
177382 176481     DbpageTable *pTab = 0;
177383 176482     int rc = SQLITE_OK;
       176483  +  int iDb;
177384 176484   
       176485  +  if( argc>=4 ){
       176486  +    Token nm;
       176487  +    sqlite3TokenInit(&nm, (char*)argv[3]);
       176488  +    iDb = sqlite3FindDb(db, &nm);
       176489  +    if( iDb<0 ){
       176490  +      *pzErr = sqlite3_mprintf("no such schema: %s", argv[3]);
       176491  +      return SQLITE_ERROR;
       176492  +    }
       176493  +  }else{
       176494  +    iDb = 0;
       176495  +  }
177385 176496     rc = sqlite3_declare_vtab(db, 
177386 176497             "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)");
177387 176498     if( rc==SQLITE_OK ){
177388 176499       pTab = (DbpageTable *)sqlite3_malloc64(sizeof(DbpageTable));
177389 176500       if( pTab==0 ) rc = SQLITE_NOMEM_BKPT;
177390 176501     }
177391 176502   
177392 176503     assert( rc==SQLITE_OK || pTab==0 );
177393 176504     if( rc==SQLITE_OK ){
       176505  +    Btree *pBt = db->aDb[iDb].pBt;
177394 176506       memset(pTab, 0, sizeof(DbpageTable));
177395 176507       pTab->db = db;
       176508  +    pTab->iDb = iDb;
       176509  +    pTab->pPager = pBt ? sqlite3BtreePager(pBt) : 0;
177396 176510     }
177397 176511   
177398 176512     *ppVtab = (sqlite3_vtab*)pTab;
177399 176513     return rc;
177400 176514   }
177401 176515   
177402 176516   /*
................................................................................
177406 176520     sqlite3_free(pVtab);
177407 176521     return SQLITE_OK;
177408 176522   }
177409 176523   
177410 176524   /*
177411 176525   ** idxNum:
177412 176526   **
177413         -**     0     schema=main, full table scan
177414         -**     1     schema=main, pgno=?1
177415         -**     2     schema=?1, full table scan
177416         -**     3     schema=?1, pgno=?2
       176527  +**     0     full table scan
       176528  +**     1     pgno=?1
177417 176529   */
177418 176530   static int dbpageBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
177419 176531     int i;
177420         -  int iPlan = 0;
177421         -
177422         -  /* If there is a schema= constraint, it must be honored.  Report a
177423         -  ** ridiculously large estimated cost if the schema= constraint is
177424         -  ** unavailable
177425         -  */
177426         -  for(i=0; i<pIdxInfo->nConstraint; i++){
177427         -    struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[i];
177428         -    if( p->iColumn!=DBPAGE_COLUMN_SCHEMA ) continue;
177429         -    if( p->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
177430         -    if( !p->usable ){
177431         -      /* No solution.  Use the default SQLITE_BIG_DBL cost */
177432         -      pIdxInfo->estimatedRows = 0x7fffffff;
177433         -      return SQLITE_OK;
177434         -    }
177435         -    iPlan = 2;
177436         -    pIdxInfo->aConstraintUsage[i].argvIndex = 1;
177437         -    pIdxInfo->aConstraintUsage[i].omit = 1;
177438         -    break;
177439         -  }
177440         -
177441         -  /* If we reach this point, it means that either there is no schema=
177442         -  ** constraint (in which case we use the "main" schema) or else the
177443         -  ** schema constraint was accepted.  Lower the estimated cost accordingly
177444         -  */
177445         -  pIdxInfo->estimatedCost = 1.0e6;
177446         -
177447         -  /* Check for constraints against pgno */
       176532  +  pIdxInfo->estimatedCost = 1.0e6;  /* Initial cost estimate */
177448 176533     for(i=0; i<pIdxInfo->nConstraint; i++){
177449 176534       struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[i];
177450 176535       if( p->usable && p->iColumn<=0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
177451 176536         pIdxInfo->estimatedRows = 1;
177452 176537         pIdxInfo->idxFlags = SQLITE_INDEX_SCAN_UNIQUE;
177453 176538         pIdxInfo->estimatedCost = 1.0;
177454         -      pIdxInfo->aConstraintUsage[i].argvIndex = iPlan ? 2 : 1;
       176539  +      pIdxInfo->idxNum = 1;
       176540  +      pIdxInfo->aConstraintUsage[i].argvIndex = 1;
177455 176541         pIdxInfo->aConstraintUsage[i].omit = 1;
177456         -      iPlan |= 1;
177457 176542         break;
177458 176543       }
177459 176544     }
177460         -  pIdxInfo->idxNum = iPlan;
177461         -
177462 176545     if( pIdxInfo->nOrderBy>=1
177463 176546      && pIdxInfo->aOrderBy[0].iColumn<=0
177464 176547      && pIdxInfo->aOrderBy[0].desc==0
177465 176548     ){
177466 176549       pIdxInfo->orderByConsumed = 1;
177467 176550     }
177468 176551     return SQLITE_OK;
................................................................................
177488 176571   }
177489 176572   
177490 176573   /*
177491 176574   ** Close a dbpagevfs cursor.
177492 176575   */
177493 176576   static int dbpageClose(sqlite3_vtab_cursor *pCursor){
177494 176577     DbpageCursor *pCsr = (DbpageCursor *)pCursor;
177495         -  if( pCsr->pPage1 ) sqlite3PagerUnrefPageOne(pCsr->pPage1);
177496 176578     sqlite3_free(pCsr);
177497 176579     return SQLITE_OK;
177498 176580   }
177499 176581   
177500 176582   /*
177501 176583   ** Move a dbpagevfs cursor to the next entry in the file.
177502 176584   */
................................................................................
177508 176590   }
177509 176591   
177510 176592   static int dbpageEof(sqlite3_vtab_cursor *pCursor){
177511 176593     DbpageCursor *pCsr = (DbpageCursor *)pCursor;
177512 176594     return pCsr->pgno > pCsr->mxPgno;
177513 176595   }
177514 176596   
177515         -/*
177516         -** idxNum:
177517         -**
177518         -**     0     schema=main, full table scan
177519         -**     1     schema=main, pgno=?1
177520         -**     2     schema=?1, full table scan
177521         -**     3     schema=?1, pgno=?2
177522         -**
177523         -** idxStr is not used
177524         -*/
177525 176597   static int dbpageFilter(
177526 176598     sqlite3_vtab_cursor *pCursor, 
177527 176599     int idxNum, const char *idxStr,
177528 176600     int argc, sqlite3_value **argv
177529 176601   ){
177530 176602     DbpageCursor *pCsr = (DbpageCursor *)pCursor;
177531 176603     DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
177532         -  int rc;
177533         -  sqlite3 *db = pTab->db;
177534         -  Btree *pBt;
       176604  +  int rc = SQLITE_OK;
       176605  +  Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
177535 176606   
177536         -  /* Default setting is no rows of result */
177537         -  pCsr->pgno = 1; 
177538         -  pCsr->mxPgno = 0;
177539         -
177540         -  if( idxNum & 2 ){
177541         -    const char *zSchema;
177542         -    assert( argc>=1 );
177543         -    zSchema = (const char*)sqlite3_value_text(argv[0]);
177544         -    pCsr->iDb = sqlite3FindDbName(db, zSchema);
177545         -    if( pCsr->iDb<0 ) return SQLITE_OK;
177546         -  }else{
177547         -    pCsr->iDb = 0;
177548         -  }
177549         -  pBt = db->aDb[pCsr->iDb].pBt;
177550         -  if( pBt==0 ) return SQLITE_OK;
177551         -  pCsr->pPager = sqlite3BtreePager(pBt);
177552         -  pCsr->szPage = sqlite3BtreeGetPageSize(pBt);
177553         -  pCsr->mxPgno = sqlite3BtreeLastPage(pBt);
177554         -  if( idxNum & 1 ){
177555         -    assert( argc>(idxNum>>1) );
177556         -    pCsr->pgno = sqlite3_value_int(argv[idxNum>>1]);
177557         -    if( pCsr->pgno<1 || pCsr->pgno>pCsr->mxPgno ){
       176607  +  pTab->szPage = sqlite3BtreeGetPageSize(pBt);
       176608  +  pTab->nPage = sqlite3BtreeLastPage(pBt);
       176609  +  if( idxNum==1 ){
       176610  +    pCsr->pgno = sqlite3_value_int(argv[0]);
       176611  +    if( pCsr->pgno<1 || pCsr->pgno>pTab->nPage ){
177558 176612         pCsr->pgno = 1;
177559 176613         pCsr->mxPgno = 0;
177560 176614       }else{
177561 176615         pCsr->mxPgno = pCsr->pgno;
177562 176616       }
177563 176617     }else{
177564         -    assert( pCsr->pgno==1 );
       176618  +    pCsr->pgno = 1;
       176619  +    pCsr->mxPgno = pTab->nPage;
177565 176620     }
177566         -  if( pCsr->pPage1 ) sqlite3PagerUnrefPageOne(pCsr->pPage1);
177567         -  rc = sqlite3PagerGet(pCsr->pPager, 1, &pCsr->pPage1, 0);
177568 176621     return rc;
177569 176622   }
177570 176623   
177571 176624   static int dbpageColumn(
177572 176625     sqlite3_vtab_cursor *pCursor, 
177573 176626     sqlite3_context *ctx, 
177574 176627     int i
177575 176628   ){
177576 176629     DbpageCursor *pCsr = (DbpageCursor *)pCursor;
       176630  +  DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
177577 176631     int rc = SQLITE_OK;
177578 176632     switch( i ){
177579 176633       case 0: {           /* pgno */
177580 176634         sqlite3_result_int(ctx, pCsr->pgno);
177581 176635         break;
177582 176636       }
177583 176637       case 1: {           /* data */
177584 176638         DbPage *pDbPage = 0;
177585         -      rc = sqlite3PagerGet(pCsr->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0);
       176639  +      rc = sqlite3PagerGet(pTab->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0);
177586 176640         if( rc==SQLITE_OK ){
177587         -        sqlite3_result_blob(ctx, sqlite3PagerGetData(pDbPage), pCsr->szPage,
       176641  +        sqlite3_result_blob(ctx, sqlite3PagerGetData(pDbPage), pTab->szPage,
177588 176642                               SQLITE_TRANSIENT);
177589 176643         }
177590 176644         sqlite3PagerUnref(pDbPage);
177591 176645         break;
177592 176646       }
177593 176647       default: {          /* schema */
177594 176648         sqlite3 *db = sqlite3_context_db_handle(ctx);
177595         -      sqlite3_result_text(ctx, db->aDb[pCsr->iDb].zDbSName, -1, SQLITE_STATIC);
       176649  +      sqlite3_result_text(ctx, db->aDb[pTab->iDb].zDbSName, -1, SQLITE_STATIC);
177596 176650         break;
177597 176651       }
177598 176652     }
177599 176653     return SQLITE_OK;
177600 176654   }
177601 176655   
177602 176656   static int dbpageRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
................................................................................
177608 176662   static int dbpageUpdate(
177609 176663     sqlite3_vtab *pVtab,
177610 176664     int argc,
177611 176665     sqlite3_value **argv,
177612 176666     sqlite_int64 *pRowid
177613 176667   ){
177614 176668     DbpageTable *pTab = (DbpageTable *)pVtab;
177615         -  Pgno pgno;
       176669  +  int pgno;
177616 176670     DbPage *pDbPage = 0;
177617 176671     int rc = SQLITE_OK;
177618 176672     char *zErr = 0;
177619         -  const char *zSchema;
177620         -  int iDb;
177621         -  Btree *pBt;
177622         -  Pager *pPager;
177623         -  int szPage;
177624 176673   
177625 176674     if( argc==1 ){
177626 176675       zErr = "cannot delete";
177627 176676       goto update_fail;
177628 176677     }
177629 176678     pgno = sqlite3_value_int(argv[0]);
177630         -  if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){
       176679  +  if( pgno<1 || pgno>pTab->nPage ){
       176680  +    zErr = "bad page number";
       176681  +    goto update_fail;
       176682  +  }
       176683  +  if( sqlite3_value_int(argv[1])!=pgno ){
177631 176684       zErr = "cannot insert";
177632 176685       goto update_fail;
177633 176686     }
177634         -  zSchema = (const char*)sqlite3_value_text(argv[4]);
177635         -  iDb = zSchema ? sqlite3FindDbName(pTab->db, zSchema) : -1;
177636         -  if( iDb<0 ){
177637         -    zErr = "no such schema";
177638         -    goto update_fail;
177639         -  }
177640         -  pBt = pTab->db->aDb[iDb].pBt;
177641         -  if( pgno<1 || pBt==0 || pgno>(int)sqlite3BtreeLastPage(pBt) ){
177642         -    zErr = "bad page number";
177643         -    goto update_fail;
177644         -  }
177645         -  szPage = sqlite3BtreeGetPageSize(pBt);
177646 176687     if( sqlite3_value_type(argv[3])!=SQLITE_BLOB 
177647         -   || sqlite3_value_bytes(argv[3])!=szPage
       176688  +   || sqlite3_value_bytes(argv[3])!=pTab->szPage 
177648 176689     ){
177649 176690       zErr = "bad page value";
177650 176691       goto update_fail;
177651 176692     }
177652         -  pPager = sqlite3BtreePager(pBt);
177653         -  rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pDbPage, 0);
       176693  +  rc = sqlite3PagerGet(pTab->pPager, pgno, (DbPage**)&pDbPage, 0);
177654 176694     if( rc==SQLITE_OK ){
177655 176695       rc = sqlite3PagerWrite(pDbPage);
177656 176696       if( rc==SQLITE_OK ){
177657 176697         memcpy(sqlite3PagerGetData(pDbPage),
177658 176698                sqlite3_value_blob(argv[3]),
177659         -             szPage);
       176699  +             pTab->szPage);
177660 176700       }
177661 176701     }
177662 176702     sqlite3PagerUnref(pDbPage);
177663 176703     return rc;
177664 176704   
177665 176705   update_fail:
177666 176706     sqlite3_free(pVtab->zErrMsg);
177667 176707     pVtab->zErrMsg = sqlite3_mprintf("%s", zErr);
177668 176708     return SQLITE_ERROR;
177669 176709   }
177670         -
177671         -/* Since we do not know in advance which database files will be
177672         -** written by the sqlite_dbpage virtual table, start a write transaction
177673         -** on them all.
177674         -*/
177675         -static int dbpageBegin(sqlite3_vtab *pVtab){
177676         -  DbpageTable *pTab = (DbpageTable *)pVtab;
177677         -  sqlite3 *db = pTab->db;
177678         -  int i;
177679         -  for(i=0; i<db->nDb; i++){
177680         -    Btree *pBt = db->aDb[i].pBt;
177681         -    if( pBt ) sqlite3BtreeBeginTrans(pBt, 1);
177682         -  }
177683         -  return SQLITE_OK;
177684         -}
177685         -
177686 176710   
177687 176711   /*
177688 176712   ** Invoke this routine to register the "dbpage" virtual table module
177689 176713   */
177690 176714   SQLITE_PRIVATE int sqlite3DbpageRegister(sqlite3 *db){
177691 176715     static sqlite3_module dbpage_module = {
177692 176716       0,                            /* iVersion */
................................................................................
177699 176723       dbpageClose,                  /* xClose - close a cursor */
177700 176724       dbpageFilter,                 /* xFilter - configure scan constraints */
177701 176725       dbpageNext,                   /* xNext - advance a cursor */
177702 176726       dbpageEof,                    /* xEof - check for end of scan */
177703 176727       dbpageColumn,                 /* xColumn - read data */
177704 176728       dbpageRowid,                  /* xRowid - read data */
177705 176729       dbpageUpdate,                 /* xUpdate */
177706         -    dbpageBegin,                  /* xBegin */
       176730  +    0,                            /* xBegin */
177707 176731       0,                            /* xSync */
177708 176732       0,                            /* xCommit */
177709 176733       0,                            /* xRollback */
177710 176734       0,                            /* xFindMethod */
177711 176735       0,                            /* xRename */
177712 176736       0,                            /* xSavepoint */
177713 176737       0,                            /* xRelease */
................................................................................
202047 201071   static void fts5SourceIdFunc(
202048 201072     sqlite3_context *pCtx,          /* Function call context */
202049 201073     int nArg,                       /* Number of args */
202050 201074     sqlite3_value **apUnused        /* Function arguments */
202051 201075   ){
202052 201076     assert( nArg==0 );
202053 201077     UNUSED_PARAM2(nArg, apUnused);
202054         -  sqlite3_result_text(pCtx, "fts5: 2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b8322ba3", -1, SQLITE_TRANSIENT);
       201078  +  sqlite3_result_text(pCtx, "fts5: 2017-10-24 18:55:49 1a584e499906b5c87ec7d43d4abce641fdf017c42125b083109bc77c4de48827", -1, SQLITE_TRANSIENT);
202055 201079   }
202056 201080   
202057 201081   static int fts5Init(sqlite3 *db){
202058 201082     static const sqlite3_module fts5Mod = {
202059 201083       /* iVersion      */ 2,
202060 201084       /* xCreate       */ fts5CreateMethod,
202061 201085       /* xConnect      */ fts5ConnectMethod,
................................................................................
206315 205339   #endif
206316 205340     return rc;
206317 205341   }
206318 205342   #endif /* SQLITE_CORE */
206319 205343   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
206320 205344   
206321 205345   /************** End of stmt.c ************************************************/
206322         -#if __LINE__!=206322
       205346  +#if __LINE__!=205346
206323 205347   #undef SQLITE_SOURCE_ID
206324         -#define SQLITE_SOURCE_ID      "2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b832alt2"
       205348  +#define SQLITE_SOURCE_ID      "2017-10-24 18:55:49 1a584e499906b5c87ec7d43d4abce641fdf017c42125b083109bc77c4de4alt2"
206325 205349   #endif
206326 205350   /* Return the source-id for this library */
206327 205351   SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
206328 205352   /************************** End of sqlite3.c ******************************/

Changes to src/sqlite3.h.

   119    119   ** been edited in any way since it was last checked in, then the last
   120    120   ** four hexadecimal digits of the hash may be modified.
   121    121   **
   122    122   ** See also: [sqlite3_libversion()],
   123    123   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   124    124   ** [sqlite_version()] and [sqlite_source_id()].
   125    125   */
   126         -#define SQLITE_VERSION        "3.22.0"
   127         -#define SQLITE_VERSION_NUMBER 3022000
   128         -#define SQLITE_SOURCE_ID      "2017-11-14 19:34:22 00ec95fcd02bb415dabd7f25fee24856d45d6916c18b2728e97e9bb9b8322ba3"
          126  +#define SQLITE_VERSION        "3.21.0"
          127  +#define SQLITE_VERSION_NUMBER 3021000
          128  +#define SQLITE_SOURCE_ID      "2017-10-24 18:55:49 1a584e499906b5c87ec7d43d4abce641fdf017c42125b083109bc77c4de48827"
   129    129   
   130    130   /*
   131    131   ** CAPI3REF: Run-Time Library Version Numbers
   132    132   ** KEYWORDS: sqlite3_version sqlite3_sourceid
   133    133   **
   134    134   ** These interfaces provide the same information as the [SQLITE_VERSION],
   135    135   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
   504    504   #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
   505    505   #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
   506    506   #define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
   507    507   #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
   508    508   #define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
   509    509   #define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
   510    510   #define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
   511         -#define SQLITE_CANTOPEN_DIRTYWAL       (SQLITE_CANTOPEN | (5<<8))
   512    511   #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
   513    512   #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
   514    513   #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
   515    514   #define SQLITE_READONLY_ROLLBACK       (SQLITE_READONLY | (3<<8))
   516    515   #define SQLITE_READONLY_DBMOVED        (SQLITE_READONLY | (4<<8))
   517         -#define SQLITE_READONLY_CANTINIT       (SQLITE_READONLY | (5<<8))
   518    516   #define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
   519    517   #define SQLITE_CONSTRAINT_CHECK        (SQLITE_CONSTRAINT | (1<<8))
   520    518   #define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))
   521    519   #define SQLITE_CONSTRAINT_FOREIGNKEY   (SQLITE_CONSTRAINT | (3<<8))
   522    520   #define SQLITE_CONSTRAINT_FUNCTION     (SQLITE_CONSTRAINT | (4<<8))
   523    521   #define SQLITE_CONSTRAINT_NOTNULL      (SQLITE_CONSTRAINT | (5<<8))
   524    522   #define SQLITE_CONSTRAINT_PRIMARYKEY   (SQLITE_CONSTRAINT | (6<<8))
................................................................................
  1129   1127   ** CAPI3REF: OS Interface Object
  1130   1128   **
  1131   1129   ** An instance of the sqlite3_vfs object defines the interface between
  1132   1130   ** the SQLite core and the underlying operating system.  The "vfs"
  1133   1131   ** in the name of the object stands for "virtual file system".  See
  1134   1132   ** the [VFS | VFS documentation] for further information.
  1135   1133   **
  1136         -** The VFS interface is sometimes extended by adding new methods onto
  1137         -** the end.  Each time such an extension occurs, the iVersion field
  1138         -** is incremented.  The iVersion value started out as 1 in
  1139         -** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
  1140         -** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
  1141         -** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6].  Additional fields
  1142         -** may be appended to the sqlite3_vfs object and the iVersion value
  1143         -** may increase again in future versions of SQLite.
  1144         -** Note that the structure
  1145         -** of the sqlite3_vfs object changes in the transition from
  1146         -** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
  1147         -** and yet the iVersion field was not modified.
         1134  +** The value of the iVersion field is initially 1 but may be larger in
         1135  +** future versions of SQLite.  Additional fields may be appended to this
         1136  +** object when the iVersion value is increased.  Note that the structure
         1137  +** of the sqlite3_vfs object changes in the transaction between
         1138  +** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
         1139  +** modified.
  1148   1140   **
  1149   1141   ** The szOsFile field is the size of the subclassed [sqlite3_file]
  1150   1142   ** structure used by this VFS.  mxPathname is the maximum length of
  1151   1143   ** a pathname in this VFS.
  1152   1144   **
  1153   1145   ** Registered sqlite3_vfs objects are kept on a linked list formed by
  1154   1146   ** the pNext pointer.  The [sqlite3_vfs_register()]

Changes to src/style.c.

   392    392     char *zVarPrefix = mprintf("%s_image", zImageName);
   393    393     char *zConfigName = mprintf("%s-image", zImageName);
   394    394     url_var(zVarPrefix, zConfigName, zImageName);
   395    395     free(zVarPrefix);
   396    396     free(zConfigName);
   397    397   }
   398    398   
   399         -/*
   400         -** Default HTML page header text through <body>.  If the repository-specific
   401         -** header template lacks a <body> tag, then all of the following is
   402         -** prepended.
   403         -*/
   404         -static char zDfltHeader[] = 
   405         -@ <html>
   406         -@ <head>
   407         -@ <base href="$baseurl/$current_page" />
   408         -@ <title>$<project_name>: $<title></title>
   409         -@ <link rel="alternate" type="application/rss+xml" title="RSS Feed"
   410         -@       href="$home/timeline.rss" />
   411         -@ <link rel="stylesheet" href="$stylesheet_url" type="text/css"
   412         -@       media="screen" />
   413         -@ </head>
   414         -@ <body>
   415         -;
   416         -
   417    399   /*
   418    400   ** Draw the header.
   419    401   */
   420    402   void style_header(const char *zTitleFormat, ...){
   421    403     va_list ap;
   422    404     char *zTitle;
   423    405     const char *zHeader = skin_get("header");
................................................................................
   450    432     Th_Store("compiler_name", COMPILER_NAME);
   451    433     url_var("stylesheet", "css", "style.css");
   452    434     image_url_var("logo");
   453    435     image_url_var("background");
   454    436     if( !login_is_nobody() ){
   455    437       Th_Store("login", g.zLogin);
   456    438     }
   457         -  if( sqlite3_strlike("%<body>%", zHeader, 0)!=0 ){
   458         -    Th_Render(zDfltHeader);
   459         -  }
   460    439     if( g.thTrace ) Th_Trace("BEGIN_HEADER_SCRIPT<br />\n", -1);
   461    440     Th_Render(zHeader);
   462    441     if( g.thTrace ) Th_Trace("END_HEADER<br />\n", -1);
   463    442     Th_Unstore("title");   /* Avoid collisions with ticket field names */
   464    443     cgi_destination(CGI_BODY);
   465    444     g.cgiOutput = 1;
   466    445     headerHasBeenGenerated = 1;
................................................................................
   679    658   
   680    659     /* Render trace log if TH1 tracing is enabled. */
   681    660     if( g.thTrace ){
   682    661       cgi_append_content("<span class=\"thTrace\"><hr />\n", -1);
   683    662       cgi_append_content(blob_str(&g.thLog), blob_size(&g.thLog));
   684    663       cgi_append_content("</span>\n", -1);
   685    664     }
   686         -
   687         -  /* Add document end mark if it was not in the footer */
   688         -  if( sqlite3_strlike("%</body>%", zFooter, 0)!=0 ){
   689         -    @ </body></html>
   690         -  }
   691    665   }
   692    666   
   693    667   /*
   694    668   ** Begin a side-box on the right-hand side of a page.  The title and
   695    669   ** the width of the box are given as arguments.  The width is usually
   696    670   ** a percentage of total screen width.
   697    671   */

Changes to src/translate.c.

     1      1   /*
     2      2   ** Copyright (c) 2002 D. Richard Hipp
     3      3   **
     4      4   ** This program is free software; you can redistribute it and/or
     5      5   ** modify it under the terms of the Simplified BSD License (also
     6      6   ** known as the "2-Clause License" or "FreeBSD License".)
     7         -**
            7  +
     8      8   ** This program is distributed in the hope that it will be useful,
     9      9   ** but without any warranty; without even the implied warranty of
    10     10   ** merchantability or fitness for a particular purpose.
    11     11   **
    12     12   ** Author contact information:
    13     13   **   drh@hwaci.com
    14     14   **   http://www.hwaci.com/drh/

Changes to src/wiki.c.

   191    191     }
   192    192     blob_init(&x, builtin_text("markdown.md"), -1);
   193    193     wiki_render_by_mimetype(&x, fTxt ? "text/plain" : "text/x-markdown");
   194    194     blob_reset(&x);
   195    195     style_footer();
   196    196   }
   197    197   
   198         -/*
   199         -** WEBPAGE: wiki_rules
   200         -**
   201         -** Show a summary of the wiki formatting rules.
   202         -*/
   203         -void wiki_rules_page(void){
   204         -  Blob x;
   205         -  int fTxt = P("txt")!=0;
   206         -  style_header("Wiki Formatting Rules");
   207         -  if( fTxt ){
   208         -    style_submenu_element("Formatted", "%R/wiki_rules");
   209         -  }else{
   210         -    style_submenu_element("Plain-Text", "%R/wiki_rules?txt=1");
   211         -  }
   212         -  blob_init(&x, builtin_text("wiki.wiki"), -1);
   213         -  wiki_render_by_mimetype(&x, fTxt ? "text/plain" : "text/x-fossil-wiki");
   214         -  blob_reset(&x);
   215         -  style_footer();
   216         -}
   217         -
   218    198   /*
   219    199   ** Returns non-zero if moderation is required for wiki changes and wiki
   220    200   ** attachments.
   221    201   */
   222    202   int wiki_need_moderation(
   223    203     int localUser /* Are we being called for a local interactive user? */
   224    204   ){
................................................................................
  1010    990       const char *zName = db_column_text(&q, 0);
  1011    991       @ <li>%z(href("%R/wiki?name=%T",zName))%h(zName)</a></li>
  1012    992     }
  1013    993     db_finalize(&q);
  1014    994     @ </ul>
  1015    995     style_footer();
  1016    996   }
          997  +
          998  +/*
          999  +** WEBPAGE: wiki_rules
         1000  +**
         1001  +** Show the formatting rules for Fossil wiki.
         1002  +*/
         1003  +void wikirules_page(void){
         1004  +  style_header("Wiki Formatting Rules");
         1005  +  @ <h2>Formatting Rule Summary</h2>
         1006  +  @ <ol>
         1007  +  @ <li>Blank lines are paragraph breaks</li>
         1008  +  @ <li>Bullets are "*" surrounded by two spaces at the beginning of the
         1009  +  @ line.</li>
         1010  +  @ <li>Enumeration items are "#" surrounded by two spaces at the beginning of
         1011  +  @ a line.</li>
         1012  +  @ <li>Indented paragraphs begin with a tab or two spaces.</li>
         1013  +  @ <li>Hyperlinks are contained with square brackets:  "[target]" or
         1014  +  @ "[target|name]".</li>
         1015  +  @ <li>Most ordinary HTML works.</li>
         1016  +  @ <li>&lt;verbatim&gt; and &lt;nowiki&gt;.</li>
         1017  +  @ </ol>
         1018  +  @ <p>We call the first five rules above "wiki" formatting rules.  The
         1019  +  @ last two rules are the HTML formatting rule.</p>
         1020  +  @ <h2>Formatting Rule Details</h2>
         1021  +  @ <ol>
         1022  +  @ <li> <p><span class="wikiruleHead">Paragraphs</span>.
         1023  +  @ Any sequence of one or more blank lines forms
         1024  +  @ a paragraph break.  Centered or right-justified paragraphs are not
         1025  +  @ supported by wiki markup, but you can do these things if you need them
         1026  +  @ using HTML.</p></li>
         1027  +  @ <li> <p><span class="wikiruleHead">Bullet Lists</span>.
         1028  +  @ A bullet list item is a line that begins with a single "*" character
         1029  +  @ surrounded on
         1030  +  @ both sides by two or more spaces or by a tab.  Only a single level
         1031  +  @ of bullet list is supported by wiki.  For nested lists, use HTML.</p></li>
         1032  +  @ <li> <p><span class="wikiruleHead">Enumeration Lists</span>.
         1033  +  @ An enumeration list item is a line that begins with a single "#" character
         1034  +  @ surrounded on both sides by two or more spaces or by a tab.  Only a single
         1035  +  @ level of enumeration list is supported by wiki.  For nested lists or for
         1036  +  @ enumerations that count using letters or roman numerials, use HTML.</p></li>
         1037  +  @ <li> <p><span class="wikiruleHead">Indented Paragraphs</span>.
         1038  +  @ Any paragraph that begins with two or more spaces or a tab and
         1039  +  @ which is not a bullet or enumeration list item is rendered
         1040  +  @ indented.  Only a single level of indentation is supported by wiki; use
         1041  +  @ HTML for deeper indentation.</p></li>
         1042  +  @ <li> <p><span class="wikiruleHead">Hyperlinks</span>.
         1043  +  @ Text within square brackets ("[...]") becomes a hyperlink.  The
         1044  +  @ target can be a wiki page name, the artifact ID of a check-in or ticket,
         1045  +  @ the name of an image, or a URL.  By default, the target is displayed
         1046  +  @ as the text of the hyperlink.  But you can specify alternative text
         1047  +  @ after the target name separated by a "|" character.</p>
         1048  +  @ <p>You can also link to internal anchor names using [#anchor-name],
         1049  +  @ providing
         1050  +  @ you have added the necessary "&lt;a name='anchor-name'&gt;&lt;/a&gt;"
         1051  +  @ tag to your wiki page.</p></li>
         1052  +  @ <li> <p><span class="wikiruleHead">HTML</span>.
         1053  +  @ The following standard HTML elements may be used:
         1054  +  show_allowed_wiki_markup();
         1055  +  @ . There are two non-standard elements available:
         1056  +  @ &lt;verbatim&gt; and &lt;nowiki&gt;.
         1057  +  @ No other elements are allowed.  All attributes are checked and
         1058  +  @ only a few benign attributes are allowed on each element.
         1059  +  @ In particular, any attributes that specify javascript or CSS
         1060  +  @ are elided.</p></li>
         1061  +  @ <li><p><span class="wikiruleHead">Special Markup.</span>
         1062  +  @ The &lt;nowiki&gt; tag disables all wiki formatting rules
         1063  +  @ through the matching &lt;/nowiki&gt; element.
         1064  +  @ The &lt;verbatim&gt; tag works like &lt;pre&gt; with the addition
         1065  +  @ that it also disables all wiki and HTML markup
         1066  +  @ through the matching &lt;/verbatim&gt;.</p></li>
         1067  +  @ </ol>
         1068  +  style_footer();
         1069  +}
  1017   1070   
  1018   1071   /*
  1019   1072   ** Add a new wiki page to the repository.  The page name is
  1020   1073   ** given by the zPageName parameter.  rid must be zero to create
  1021   1074   ** a new page otherwise the page identified by rid is updated.
  1022   1075   **
  1023   1076   ** The content of the new page is given by the blob pContent.

Deleted src/wiki.wiki.

     1         -<h2>Wiki Formatting Rule Summary</h2>
     2         -
     3         -  #  Blank lines are paragraph breaks
     4         -  #  Bullets are "*" surrounded by two spaces at the beginning of a line
     5         -  #  Enumeration items are "#" or a digit and a "." surrounded by two
     6         -     spaces at the beginning of a line
     7         -  #  Indented paragraphs begin with a tab or two spaces
     8         -  #  Hyperlinks are contained within square brackets:
     9         -     <nowiki>"[target]" or "[target|label]"</nowiki>
    10         -  #  Most ordinary HTML works
    11         -  #  &lt;verbatim&gt; and &lt;nowiki&gt;
    12         -
    13         -We call the first five rules above the "wiki" formatting rules.
    14         -The last two rules are the HTML formatting rules.
    15         -
    16         -<h2>Formatting Rule Details</h2>
    17         -
    18         -  1.  <b>Paragraphs.</b>
    19         -      Any sequence of one or more blank lines forms a paragraph break.
    20         -      Centered or right-justified paragraphs are not supported by wiki markup,
    21         -      but you can do these things if you need them using HTML.
    22         -
    23         -  2.  <b>Bullet Lists.</b>
    24         -      A bullet list item is a line that begins with a single "*" character
    25         -      surrounded on both sides by two or more spaces or by a tab.
    26         -      Only a single level of bullet list is supported by wiki.
    27         -      For nested lists, use HTML.
    28         -
    29         -  3.  <b>Enumeration Lists.</b>
    30         -      An enumeration list item is a line that begins with a single "#"
    31         -      character surrounded on both sides by two or more spaces or by a tab.
    32         -      Or it can be a number and a "." (ex:  "5.") surrounded on both sides
    33         -      by two spaces or a tab.
    34         -      Only a single level of enumeration list is supported by wiki.
    35         -      For nested lists or for enumerations that count using letters or
    36         -      roman numerials, use HTML.
    37         -
    38         -  4.  <b>Indented Paragraphs.</b>
    39         -      Any paragraph that begins with two or more spaces or a tab and which
    40         -      is not a bullet or enumeration list item is rendered indented.
    41         -      Only a single level of indentation is supported by wiki.
    42         -      Use HTML for deeper indentation.
    43         -
    44         -  5.  <b>Hyperlinks.</b>
    45         -      Text within square brackets <nowiki>("[...]")</nowiki> becomes a
    46         -      hyperlink. The target can be a wiki page name, the artifact ID of
    47         -      a check-in or ticket, the name of an image, or a URL.
    48         -      By default, the target is displayed as the text of the hyperlink.
    49         -      But you can specify alternative text after the target name
    50         -      separated by a "|" character.
    51         -      You can also link to internal anchor names using 
    52         -      <nowiki>[#anchor-name],</nowiki> providing you have added the necessary 
    53         -      "&lt;a name='anchor-name'&gt;&lt;/a&gt;" tag to your wiki page.
    54         -
    55         -  6.  <b>HTML.</b>
    56         -      The following standard HTML elements may be used:
    57         -      &lt;a&gt; &lt;address&gt; &lt;article&gt; &lt;aside&gt; &lt;b&gt;
    58         -      &lt;big&gt; &lt;blockquote&gt; &lt;br&gt; &lt;center&gt; &lt;cite&gt;
    59         -      &lt;code&gt; &lt;col&gt; &lt;colgroup&gt; &lt;dd&gt; &lt;dfn&gt;
    60         -      &lt;div&gt; &lt;dl&gt; &lt;dt&gt; &lt;em&gt; &lt;font&gt; &lt;footer&gt;
    61         -      &lt;h1&gt; &lt;h2&gt; &lt;h3&gt; &lt;h4&gt; &lt;h5&gt; &lt;h6&gt;
    62         -      &lt;header&gt; &lt;hr&gt; &lt;i&gt; &lt;img&gt; &lt;kbd&gt; &lt;li&gt;
    63         -      &lt;nav&gt; &lt;nobr&gt; &lt;nowiki&gt; &lt;ol&gt; &lt;p&gt; &lt;pre&gt;
    64         -      &lt;s&gt; &lt;samp&gt; &lt;section&gt; &lt;small&gt; &lt;span&gt;
    65         -      &lt;strike&gt; &lt;strong&gt; &lt;sub&gt; &lt;sup&gt; &lt;table&gt;
    66         -      &lt;tbody&gt; &lt;td&gt; &lt;tfoot&gt; &lt;th&gt; &lt;thead&gt;
    67         -      &lt;title&gt; &lt;tr&gt; &lt;tt&gt; &lt;u&gt; &lt;ul&gt; &lt;var&gt;
    68         -      &lt;verbatim&gt;. There are two non-standard elements available:
    69         -      &lt;verbatim&gt; and &lt;nowiki&gt;. No other elements are allowed.
    70         -      All attributes are checked and only a few benign attributes are
    71         -      allowed on each element. In particular, any attributes that specify
    72         -      javascript or CSS are elided.
    73         -
    74         -  7.  <b>Special Markup.</b>
    75         -      The &lt;nowiki&gt; tag disables all wiki formatting rules through
    76         -      the matching &lt;/nowiki&gt; element. The &lt;verbatim&gt; tag works
    77         -      like &lt;pre&gt; with the addition that it also disables all wiki
    78         -      and HTML markup through the matching &lt;/verbatim&gt;.

Changes to win/Makefile.mingw.

   168    168   endif
   169    169   
   170    170   #### The directories where the OpenSSL include and library files are located.
   171    171   #    The recommended usage here is to use the Sysinternals junction tool
   172    172   #    to create a hard link between an "openssl-1.x" sub-directory of the
   173    173   #    Fossil source code directory and the target OpenSSL source directory.
   174    174   #
   175         -OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2m
          175  +OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2l
   176    176   OPENSSLINCDIR = $(OPENSSLDIR)/include
   177    177   OPENSSLLIBDIR = $(OPENSSLDIR)
   178    178   
   179    179   #### Either the directory where the Tcl library is installed or the Tcl
   180    180   #    source code directory resides (depending on the value of the macro
   181    181   #    FOSSIL_TCL_SOURCE).  If this points to the Tcl install directory,
   182    182   #    this directory must have "include" and "lib" sub-directories.  If
................................................................................
   600    600     $(SRCDIR)/../skins/rounded1/footer.txt \
   601    601     $(SRCDIR)/../skins/rounded1/header.txt \
   602    602     $(SRCDIR)/../skins/xekri/css.txt \
   603    603     $(SRCDIR)/../skins/xekri/details.txt \
   604    604     $(SRCDIR)/../skins/xekri/footer.txt \
   605    605     $(SRCDIR)/../skins/xekri/header.txt \
   606    606     $(SRCDIR)/diff.tcl \
   607         -  $(SRCDIR)/markdown.md \
   608         -  $(SRCDIR)/wiki.wiki
          607  +  $(SRCDIR)/markdown.md
   609    608   
   610    609   TRANS_SRC = \
   611    610     $(OBJDIR)/add_.c \
   612    611     $(OBJDIR)/allrepo_.c \
   613    612     $(OBJDIR)/attach_.c \
   614    613     $(OBJDIR)/bag_.c \
   615    614     $(OBJDIR)/bisect_.c \

Changes to win/Makefile.mingw.mistachkin.

   168    168   endif
   169    169   
   170    170   #### The directories where the OpenSSL include and library files are located.
   171    171   #    The recommended usage here is to use the Sysinternals junction tool
   172    172   #    to create a hard link between an "openssl-1.x" sub-directory of the
   173    173   #    Fossil source code directory and the target OpenSSL source directory.
   174    174   #
   175         -OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2m
          175  +OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2l
   176    176   OPENSSLINCDIR = $(OPENSSLDIR)/include
   177    177   OPENSSLLIBDIR = $(OPENSSLDIR)
   178    178   
   179    179   #### Either the directory where the Tcl library is installed or the Tcl
   180    180   #    source code directory resides (depending on the value of the macro
   181    181   #    FOSSIL_TCL_SOURCE).  If this points to the Tcl install directory,
   182    182   #    this directory must have "include" and "lib" sub-directories.  If
................................................................................
   508    508     $(SRCDIR)/purge.c \
   509    509     $(SRCDIR)/rebuild.c \
   510    510     $(SRCDIR)/regexp.c \
   511    511     $(SRCDIR)/report.c \
   512    512     $(SRCDIR)/rss.c \
   513    513     $(SRCDIR)/schema.c \
   514    514     $(SRCDIR)/search.c \
   515         -  $(SRCDIR)/security_audit.c \
   516    515     $(SRCDIR)/setup.c \
   517    516     $(SRCDIR)/sha1.c \
   518    517     $(SRCDIR)/sha1hard.c \
   519    518     $(SRCDIR)/sha3.c \
   520    519     $(SRCDIR)/shun.c \
   521    520     $(SRCDIR)/sitemap.c \
   522    521     $(SRCDIR)/skins.c \
................................................................................
   563    562     $(SRCDIR)/../skins/blitz/header.txt \
   564    563     $(SRCDIR)/../skins/blitz/ticket.txt \
   565    564     $(SRCDIR)/../skins/blitz_no_logo/css.txt \
   566    565     $(SRCDIR)/../skins/blitz_no_logo/details.txt \
   567    566     $(SRCDIR)/../skins/blitz_no_logo/footer.txt \
   568    567     $(SRCDIR)/../skins/blitz_no_logo/header.txt \
   569    568     $(SRCDIR)/../skins/blitz_no_logo/ticket.txt \
   570         -  $(SRCDIR)/../skins/bootstrap/css.txt \
   571         -  $(SRCDIR)/../skins/bootstrap/details.txt \
   572         -  $(SRCDIR)/../skins/bootstrap/footer.txt \
   573         -  $(SRCDIR)/../skins/bootstrap/header.txt \
   574    569     $(SRCDIR)/../skins/default/css.txt \
   575    570     $(SRCDIR)/../skins/default/details.txt \
   576    571     $(SRCDIR)/../skins/default/footer.txt \
   577    572     $(SRCDIR)/../skins/default/header.txt \
   578    573     $(SRCDIR)/../skins/eagle/css.txt \
   579    574     $(SRCDIR)/../skins/eagle/details.txt \
   580    575     $(SRCDIR)/../skins/eagle/footer.txt \
................................................................................
   600    595     $(SRCDIR)/../skins/rounded1/footer.txt \
   601    596     $(SRCDIR)/../skins/rounded1/header.txt \
   602    597     $(SRCDIR)/../skins/xekri/css.txt \
   603    598     $(SRCDIR)/../skins/xekri/details.txt \
   604    599     $(SRCDIR)/../skins/xekri/footer.txt \
   605    600     $(SRCDIR)/../skins/xekri/header.txt \
   606    601     $(SRCDIR)/diff.tcl \
   607         -  $(SRCDIR)/markdown.md \
   608         -  $(SRCDIR)/wiki.wiki
          602  +  $(SRCDIR)/markdown.md
   609    603   
   610    604   TRANS_SRC = \
   611    605     $(OBJDIR)/add_.c \
   612    606     $(OBJDIR)/allrepo_.c \
   613    607     $(OBJDIR)/attach_.c \
   614    608     $(OBJDIR)/bag_.c \
   615    609     $(OBJDIR)/bisect_.c \
................................................................................
   692    686     $(OBJDIR)/purge_.c \
   693    687     $(OBJDIR)/rebuild_.c \
   694    688     $(OBJDIR)/regexp_.c \
   695    689     $(OBJDIR)/report_.c \
   696    690     $(OBJDIR)/rss_.c \
   697    691     $(OBJDIR)/schema_.c \
   698    692     $(OBJDIR)/search_.c \
   699         -  $(OBJDIR)/security_audit_.c \
   700    693     $(OBJDIR)/setup_.c \
   701    694     $(OBJDIR)/sha1_.c \
   702    695     $(OBJDIR)/sha1hard_.c \
   703    696     $(OBJDIR)/sha3_.c \
   704    697     $(OBJDIR)/shun_.c \
   705    698     $(OBJDIR)/sitemap_.c \
   706    699     $(OBJDIR)/skins_.c \
................................................................................
   820    813    $(OBJDIR)/purge.o \
   821    814    $(OBJDIR)/rebuild.o \
   822    815    $(OBJDIR)/regexp.o \
   823    816    $(OBJDIR)/report.o \
   824    817    $(OBJDIR)/rss.o \
   825    818    $(OBJDIR)/schema.o \
   826    819    $(OBJDIR)/search.o \
   827         - $(OBJDIR)/security_audit.o \
   828    820    $(OBJDIR)/setup.o \
   829    821    $(OBJDIR)/sha1.o \
   830    822    $(OBJDIR)/sha1hard.o \
   831    823    $(OBJDIR)/sha3.o \
   832    824    $(OBJDIR)/shun.o \
   833    825    $(OBJDIR)/sitemap.o \
   834    826    $(OBJDIR)/skins.o \
................................................................................
  1159   1151   		$(OBJDIR)/purge_.c:$(OBJDIR)/purge.h \
  1160   1152   		$(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
  1161   1153   		$(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
  1162   1154   		$(OBJDIR)/report_.c:$(OBJDIR)/report.h \
  1163   1155   		$(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
  1164   1156   		$(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
  1165   1157   		$(OBJDIR)/search_.c:$(OBJDIR)/search.h \
  1166         -		$(OBJDIR)/security_audit_.c:$(OBJDIR)/security_audit.h \
  1167   1158   		$(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
  1168   1159   		$(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
  1169   1160   		$(OBJDIR)/sha1hard_.c:$(OBJDIR)/sha1hard.h \
  1170   1161   		$(OBJDIR)/sha3_.c:$(OBJDIR)/sha3.h \
  1171   1162   		$(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
  1172   1163   		$(OBJDIR)/sitemap_.c:$(OBJDIR)/sitemap.h \
  1173   1164   		$(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
................................................................................
  1910   1901   	$(TRANSLATE) $(SRCDIR)/search.c >$@
  1911   1902   
  1912   1903   $(OBJDIR)/search.o:	$(OBJDIR)/search_.c $(OBJDIR)/search.h $(SRCDIR)/config.h
  1913   1904   	$(XTCC) -o $(OBJDIR)/search.o -c $(OBJDIR)/search_.c
  1914   1905   
  1915   1906   $(OBJDIR)/search.h:	$(OBJDIR)/headers
  1916   1907   
  1917         -$(OBJDIR)/security_audit_.c:	$(SRCDIR)/security_audit.c $(TRANSLATE)
  1918         -	$(TRANSLATE) $(SRCDIR)/security_audit.c >$@
  1919         -
  1920         -$(OBJDIR)/security_audit.o:	$(OBJDIR)/security_audit_.c $(OBJDIR)/security_audit.h $(SRCDIR)/config.h
  1921         -	$(XTCC) -o $(OBJDIR)/security_audit.o -c $(OBJDIR)/security_audit_.c
  1922         -
  1923         -$(OBJDIR)/security_audit.h:	$(OBJDIR)/headers
  1924         -
  1925   1908   $(OBJDIR)/setup_.c:	$(SRCDIR)/setup.c $(TRANSLATE)
  1926   1909   	$(TRANSLATE) $(SRCDIR)/setup.c >$@
  1927   1910   
  1928   1911   $(OBJDIR)/setup.o:	$(OBJDIR)/setup_.c $(OBJDIR)/setup.h $(SRCDIR)/config.h
  1929   1912   	$(XTCC) -o $(OBJDIR)/setup.o -c $(OBJDIR)/setup_.c
  1930   1913   
  1931   1914   $(OBJDIR)/setup.h:	$(OBJDIR)/headers
................................................................................
  2237   2220                    -DSQLITE_DEFAULT_FILE_FORMAT=4 \
  2238   2221                    -DSQLITE_ENABLE_EXPLAIN_COMMENTS \
  2239   2222                    -DSQLITE_ENABLE_FTS4 \
  2240   2223                    -DSQLITE_ENABLE_FTS3_PARENTHESIS \
  2241   2224                    -DSQLITE_ENABLE_DBSTAT_VTAB \
  2242   2225                    -DSQLITE_ENABLE_JSON1 \
  2243   2226                    -DSQLITE_ENABLE_FTS5 \
  2244         -                 -DSQLITE_ENABLE_STMTVTAB \
  2245   2227                    -DSQLITE_WIN32_NO_ANSI \
  2246   2228                    $(MINGW_OPTIONS) \
  2247   2229                    -DSQLITE_USE_MALLOC_H \
  2248   2230                    -DSQLITE_USE_MSIZE
  2249   2231   
  2250   2232   SHELL_OPTIONS = -Dmain=sqlite3_shell \
  2251   2233                   -DSQLITE_SHELL_IS_UTF8=1 \

Changes to win/Makefile.msc.

    96     96   
    97     97   # Enable support for the SQLite Encryption Extension?
    98     98   !ifndef USE_SEE
    99     99   USE_SEE = 0
   100    100   !endif
   101    101   
   102    102   !if $(FOSSIL_ENABLE_SSL)!=0
   103         -SSLDIR    = $(B)\compat\openssl-1.0.2m
          103  +SSLDIR    = $(B)\compat\openssl-1.0.2l
   104    104   SSLINCDIR = $(SSLDIR)\inc32
   105    105   !if $(FOSSIL_DYNAMIC_BUILD)!=0
   106    106   SSLLIBDIR = $(SSLDIR)\out32dll
   107    107   !else
   108    108   SSLLIBDIR = $(SSLDIR)\out32
   109    109   !endif
   110    110   SSLLFLAGS = /nologo /opt:ref /debug
................................................................................
   526    526           $(SRCDIR)\../skins/rounded1/footer.txt \
   527    527           $(SRCDIR)\../skins/rounded1/header.txt \
   528    528           $(SRCDIR)\../skins/xekri/css.txt \
   529    529           $(SRCDIR)\../skins/xekri/details.txt \
   530    530           $(SRCDIR)\../skins/xekri/footer.txt \
   531    531           $(SRCDIR)\../skins/xekri/header.txt \
   532    532           $(SRCDIR)\diff.tcl \
   533         -        $(SRCDIR)\markdown.md \
   534         -        $(SRCDIR)\wiki.wiki
          533  +        $(SRCDIR)\markdown.md
   535    534   
   536    535   OBJ   = $(OX)\add$O \
   537    536           $(OX)\allrepo$O \
   538    537           $(OX)\attach$O \
   539    538           $(OX)\bag$O \
   540    539           $(OX)\bisect$O \
   541    540           $(OX)\blob$O \

Changes to www/build.wiki.

   134    134   file "<b>win\buildmsvc.bat</b>" may be used and it will attempt to
   135    135   detect and use the latest installed version of MSVC.<br><br>To enable
   136    136   the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
   137    137   first <a href="https://www.openssl.org/source/">download the official
   138    138   source code for OpenSSL</a> and extract it to an appropriately named
   139    139   "<b>openssl-X.Y.ZA</b>" subdirectory within the local
   140    140   [/tree?ci=trunk&name=compat | compat] directory (e.g.
   141         -"<b>compat/openssl-1.0.2m</b>"), then make sure that some recent
          141  +"<b>compat/openssl-1.0.2l</b>"), then make sure that some recent
   142    142   <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
   143    143   and finally run one of the following commands:
   144    144   <blockquote><pre>
   145    145   nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
   146    146   </pre></blockquote>
   147    147   <blockquote><pre>
   148    148   buildmsvc.bat FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin

Changes to www/changes.wiki.

     1      1   <title>Change Log</title>
     2      2   
     3         -<a name='v2_5'></a>
     4         -<h2>Changes for Version 2.5 (pending)</h2>
     5         -
     6         -  *  Fossil now automatically generates the
     7         -     &lt;html&gt;&lt;head&gt;...&lt;/head&gt;&lt;body&gt;
     8         -     at the beginning of each web page if the configurable header
     9         -     lacks a &lt;body&gt; tag.
    10         -  *  Upgrade to the latest versions of SQLite and OpenSSL.
    11         -
    12      3   <a name='v2_4'></a>
    13      4   <h2>Changes for Version 2.4 (2017-11-03)</h2>
    14      5   
    15      6     *  New feature: URL Aliases.  URL Aliases allow an administrator
    16      7        to define their own URLs on the web interface that are rewritten to
    17      8        built-in URLs with specific parameters.  Create and configure URL Aliases
    18      9        using the /Setup/URL_Aliases menu option in the web interface.

Changes to www/makefile.wiki.

    22     22   source tree.  The src/ subdirectory contains all code, including
    23     23   the code for the separate preprocessor programs.
    24     24   
    25     25   Each preprocessor program is a separate C program implemented in
    26     26   a single file of C source code.  The three preprocessor programs
    27     27   are:
    28     28   
    29         -  1.  [/file/src/mkindex.c | mkindex.c]
    30         -  2.  [/file/src/translate.c | translate.c]
    31         -  3.  [/file/src/makeheaders.c | makeheaders.c]
           29  +  1.  mkindex.c
           30  +  2.  translate.c
           31  +  3.  makeheaders.c
    32     32   
    33         -Fossil uses [http://www.sqlite.org/ | SQLite] for on-disk
           33  +Fossil makes use of [http://www.sqlite.org/ | SQLite] for on-disk
    34     34   storage.  The SQLite implementation is contained in three source
    35     35   code files that do not participate in the preprocessing steps.
    36     36   These three files that implement SQLite are:
    37     37   
    38     38     4.  sqlite3.c
    39     39     5.  sqlite3.h
    40     40     6.  shell.c
    41     41   
    42         -All three SQLite source files are byte-for-byte copies of files by
    43         -the same name in the
           42  +The sqlite3.c and sqlite3.h source files are byte-for-byte copies of a
    44     43   standard [http://www.sqlite.org/amalgamation.html | amalgamation].
    45         -The sqlite3.c file implements the database engine.  The shell.c file
    46         -implements the command-line shell, which is accessed in fossil using
    47         -the [/help?cmd=sqlite3 | fossil sql] command.
           44  +The shell.c source file is code for the SQLite
           45  +[http://www.sqlite.org/sqlite.html | command-line shell] that is used
           46  +to help implement the [/help/sqlite3 | fossil sql] command.  The
           47  +shell.c source file is also a byte-for-byte copy of the
           48  +shell.c file from the SQLite release.
    48     49   
    49         -The shell.c command-line shell uses the [https://github.com/antirez/linenoise |
           50  +The SQLite shell.c file uses the [https://github.com/antirez/linenoise |
    50     51   linenoise] library to implement line editing.  linenoise comprises two
    51     52   source files which were copied from the upstream repository with only
    52     53   very minor portability edits:
    53     54   
    54     55     7.  linenoise.c
    55     56     8.  linenoise.h
    56     57   
    57     58   The TH1 script engine is implemented using files:
    58     59   
    59     60     9.  th.c
    60     61     10.  th.h
    61     62   
    62         -The proprocessing steps are omitted for all of these imported
    63         -files.
           63  +These two files are imports like the SQLite source files,
           64  +and so are not preprocessed.
    64     65   
    65     66   The VERSION.h header file is generated from other information sources
    66     67   using a small program called:
    67     68   
    68         -  11.  [/file/src/mkversion.c | mkversion.c]
           69  +  11.  mkversion.c
    69     70   
    70     71   The builtin_data.h header file contains the definitions of C-language
    71     72   byte-array constants that contain various resources such as scripts and
    72     73   images.  The builtin_data.h header file is generate from the original
    73     74   resource files using a small program called:
    74     75   
    75         -  12   [/file/src/mkbuiltin.c | mkbuildin.c]
    76         -
    77         -Examples of built-in resources include the [/file/src/diff.tcl | diff.tcl]
    78         -script used to implement the --tk option to [/help?cmd=diff| fossil diff],
    79         -the [/file/src/markdown.md | markdown documentation], and the various
    80         -CSS scripts, headers, and footers used to implement built-in skins.  New
    81         -resources files are added to the "extra_files" variable in
    82         -[/file/src/makemake.tcl | makemake.tcl].
           76  +  12   mkbuiltin.c
    83     77   
    84     78   The src/ subdirectory also contains documentation about the
    85     79   makeheaders preprocessor program:
    86     80   
    87     81     13.  [../src/makeheaders.html | makeheaders.html]
    88     82   
    89     83   Click on the link to read this documentation.  In addition there is
................................................................................
    92     86     14.  makemake.tcl
    93     87   
    94     88   Running this Tcl script will automatically regenerate all makefiles.
    95     89   In order to add a new source file to the Fossil implementation, simply
    96     90   edit makemake.tcl to add the new filename, then rerun the script, and
    97     91   all of the makefiles for all targets will be rebuild.
    98     92   
    99         -There is an option code verification step implemented using
   100         -
   101         -  15.  [/file/src/codecheck1.c | codecheck1.c]
   102         -
   103         -This file implements a small utility program ("codecheck1")
   104         -that scans other Fossil source files looking for errors in printf-style 
   105         -format strings.
   106         -The codecheck1 utility detects missing or surplus arguments on 
   107         -printf-like functions and dangerous uses of "%s" that might
   108         -permit SQL injection or cross-site scripting attacks.  This code
   109         -check step is run automatically on each build of Fossil, and can
   110         -also be run separately by typing "make codecheck".  Note that the
   111         -built-in printf format checking of GCC does not function for Fossil
   112         -since Fossil implements its own printf (in the
   113         -[/file/src/printf.c | printf.c] source file) that includes special
   114         -features and formatting letters that are useful to Fossil.  The
   115         -codecheck1 utility can be seen as an enhanced application-specific
   116         -replacement for the GCC printf format checker.
   117         -
   118     93   Finally, there is one of the makefiles generated by makemake.tcl:
   119     94   
   120         -  16.  main.mk
           95  +  15.  main.mk
   121     96   
   122     97   The main.mk makefile is invoked from the Makefile in the top-level
   123     98   directory.  The main.mk is generated by makemake.tcl and should not
   124     99   be hand edited.  Other makefiles generated by makemake.tcl are in
   125    100   other subdirectories (currently all in the win/ subdirectory).
   126    101   
   127    102   All the other files in the src/ subdirectory (79 files at the time of