merged default into test_diphoton test_diphoton
authorEdouard Tisserant <edouard@pep-project.org>
Wed, 19 Jul 2017 10:22:13 +0200
branchtest_diphoton
changeset 19280e69a91298bb
parent 1903 c2a9a756b1f5
parent 1919 335cdc692960
child 1944 881bbb35095d
merged default into test_diphoton
     1.1 --- a/Makefile	Fri Jun 30 16:33:08 2017 +0200
     1.2 +++ b/Makefile	Wed Jul 19 10:22:13 2017 +0200
     1.3 @@ -17,6 +17,7 @@
     1.4  
     1.5  install: all
     1.6  	$(MAKE) -C src install
     1.7 +	$(MAKE) -C asn.1 install
     1.8  
     1.9  uninstall:
    1.10  	$(MAKE) -C src uninstall
     2.1 --- a/asn.1/Makefile	Fri Jun 30 16:33:08 2017 +0200
     2.2 +++ b/asn.1/Makefile	Wed Jul 19 10:22:13 2017 +0200
     2.3 @@ -32,3 +32,6 @@
     2.4  
     2.5  clean:
     2.6  	rm -f *.a *.o *.c *.h *.sample
     2.7 +
     2.8 +install: libasn1.a
     2.9 +	cp $< $(PREFIX)/lib/
     3.1 --- a/build-mac/pEpEngine.xcodeproj/project.pbxproj	Fri Jun 30 16:33:08 2017 +0200
     3.2 +++ b/build-mac/pEpEngine.xcodeproj/project.pbxproj	Wed Jul 19 10:22:13 2017 +0200
     3.3 @@ -13,6 +13,7 @@
     3.4  		43BA0F461D7964750059172F /* asn1_helper.c in Sources */ = {isa = PBXBuildFile; fileRef = 43BA0F451D7964750059172F /* asn1_helper.c */; };
     3.5  		43E9BC6A1DB51A1E00AD2352 /* GroupUpdate.c in Sources */ = {isa = PBXBuildFile; fileRef = 43E9BC691DB51A1E00AD2352 /* GroupUpdate.c */; };
     3.6  		43E9BC7F1DB6720E00AD2352 /* UpdateRequest.c in Sources */ = {isa = PBXBuildFile; fileRef = 43E9BC7E1DB6720E00AD2352 /* UpdateRequest.c */; };
     3.7 +		43F6921D1F164A47009418F5 /* resource_id.c in Sources */ = {isa = PBXBuildFile; fileRef = 43F6921C1F164A47009418F5 /* resource_id.c */; };
     3.8  		6400FB861B8CA1C6005221E3 /* libnetpgp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 645922521B8BD32B00A5AF93 /* libnetpgp.a */; };
     3.9  		6400FB8B1B8CA1CF005221E3 /* libetpan-ios.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 64289E371B8B630200FC617B /* libetpan-ios.a */; };
    3.10  		644297C51BE11CE0002BC73B /* system.db in Resources */ = {isa = PBXBuildFile; fileRef = 64951A1B1BE0FCD800B10E71 /* system.db */; };
    3.11 @@ -196,6 +197,7 @@
    3.12  		43BA0F451D7964750059172F /* asn1_helper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = asn1_helper.c; path = ../src/asn1_helper.c; sourceTree = "<group>"; };
    3.13  		43E9BC691DB51A1E00AD2352 /* GroupUpdate.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = GroupUpdate.c; path = ../asn.1/GroupUpdate.c; sourceTree = "<group>"; };
    3.14  		43E9BC7E1DB6720E00AD2352 /* UpdateRequest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = UpdateRequest.c; path = ../asn.1/UpdateRequest.c; sourceTree = "<group>"; };
    3.15 +		43F6921C1F164A47009418F5 /* resource_id.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = resource_id.c; path = ../src/resource_id.c; sourceTree = "<group>"; };
    3.16  		644297BF1BE11C65002BC73B /* pEpTrustWords.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = pEpTrustWords.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
    3.17  		644297C11BE11C65002BC73B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
    3.18  		646788871CEB3D120001F54C /* map_asn1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = map_asn1.c; path = ../src/map_asn1.c; sourceTree = "<group>"; };
    3.19 @@ -507,6 +509,7 @@
    3.20  		64A8264B1B455C5600EECAF0 /* srcref */ = {
    3.21  			isa = PBXGroup;
    3.22  			children = (
    3.23 +				43F6921C1F164A47009418F5 /* resource_id.c */,
    3.24  				43BA0F451D7964750059172F /* asn1_helper.c */,
    3.25  				4354FF641D6EDF300033069C /* sync_impl.c */,
    3.26  				646C414C1D510D8800C63EFF /* baseprotocol.c */,
    3.27 @@ -854,6 +857,7 @@
    3.28  				646C41041D510CD800C63EFF /* constr_SEQUENCE.c in Sources */,
    3.29  				64A826881B455D0800EECAF0 /* timestamp.c in Sources */,
    3.30  				646C41221D510CD800C63EFF /* NativeEnumerated.c in Sources */,
    3.31 +				43F6921D1F164A47009418F5 /* resource_id.c in Sources */,
    3.32  				430D258B1C9ED75A00B94535 /* blacklist.c in Sources */,
    3.33  				646C414E1D510D8800C63EFF /* baseprotocol.c in Sources */,
    3.34  				6467888C1CEB3D120001F54C /* map_asn1.c in Sources */,
     4.1 --- a/build-windows/pEpEngine.vcxproj	Fri Jun 30 16:33:08 2017 +0200
     4.2 +++ b/build-windows/pEpEngine.vcxproj	Wed Jul 19 10:22:13 2017 +0200
     4.3 @@ -123,6 +123,7 @@
     4.4      <ClCompile Include="..\src\pEpEngine.c" />
     4.5      <ClCompile Include="..\src\pgp_gpg.c" />
     4.6      <ClCompile Include="..\src\platform_windows.cpp" />
     4.7 +    <ClCompile Include="..\src\resource_id.c" />
     4.8      <ClCompile Include="..\src\sqlite3.c" />
     4.9      <ClCompile Include="..\src\stringlist.c" />
    4.10      <ClCompile Include="..\src\stringpair.c" />
    4.11 @@ -159,6 +160,7 @@
    4.12      <ClInclude Include="..\src\platform.h" />
    4.13      <ClInclude Include="..\src\platform_windows.h" />
    4.14      <ClInclude Include="..\src\resource.h" />
    4.15 +    <ClInclude Include="..\src\resource_id.h" />
    4.16      <ClInclude Include="..\src\sqlite3.h" />
    4.17      <ClInclude Include="..\src\stringlist.h" />
    4.18      <ClInclude Include="..\src\stringpair.h" />
     5.1 --- a/build-windows/pEpEngine.vcxproj.filters	Fri Jun 30 16:33:08 2017 +0200
     5.2 +++ b/build-windows/pEpEngine.vcxproj.filters	Wed Jul 19 10:22:13 2017 +0200
     5.3 @@ -102,6 +102,9 @@
     5.4      <ClCompile Include="..\src\sync_impl.c">
     5.5        <Filter>Quelldateien</Filter>
     5.6      </ClCompile>
     5.7 +    <ClCompile Include="..\src\resource_id.c">
     5.8 +      <Filter>Quelldateien</Filter>
     5.9 +    </ClCompile>
    5.10    </ItemGroup>
    5.11    <ItemGroup>
    5.12      <ClInclude Include="..\src\keymanagement.h">
    5.13 @@ -200,6 +203,9 @@
    5.14      <ClInclude Include="..\src\sync_impl.h">
    5.15        <Filter>Headerdateien</Filter>
    5.16      </ClInclude>
    5.17 +    <ClInclude Include="..\src\resource_id.h">
    5.18 +      <Filter>Headerdateien</Filter>
    5.19 +    </ClInclude>
    5.20    </ItemGroup>
    5.21    <ItemGroup>
    5.22      <Text Include="..\LICENSE.txt" />
     9.1 --- a/src/etpan_mime.c	Fri Jun 30 16:33:08 2017 +0200
     9.2 +++ b/src/etpan_mime.c	Wed Jul 19 10:22:13 2017 +0200
     9.3 @@ -183,7 +183,7 @@
     9.4  }
     9.5  
     9.6  struct mailmime * get_text_part(
     9.7 -        const char * filename,
     9.8 +        pEp_rid_list_t* resource,
     9.9          const char * mime_type,
    9.10          const char * text,
    9.11          size_t length,
    9.12 @@ -197,33 +197,45 @@
    9.13  	struct mailmime_parameter * param = NULL;
    9.14  	struct mailmime_disposition * disposition = NULL;
    9.15  	struct mailmime_mechanism * encoding = NULL;
    9.16 +    char* content_id = NULL;
    9.17      int r;
    9.18 +                
    9.19 +    if (resource != NULL && resource->rid != NULL) {
    9.20 +        switch (resource->rid_type) {
    9.21 +            case PEP_RID_CID:
    9.22 +                content_id = strdup(resource->rid);
    9.23 +                break;
    9.24 +            case PEP_RID_FILENAME:
    9.25 +            default:
    9.26 +                disposition_name = strdup(resource->rid);
    9.27 +                if (disposition_name == NULL)
    9.28 +                    goto enomem;
    9.29 +                    
    9.30 +                disposition =
    9.31 +                        mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_INLINE,
    9.32 +                                disposition_name, NULL, NULL, NULL, (size_t) -1);
    9.33 +
    9.34 +                if (disposition == NULL)
    9.35 +                    goto enomem;
    9.36 +
    9.37 +                disposition_name = NULL;                
    9.38 +                break;
    9.39 +        }    
    9.40 +    }
    9.41      
    9.42 -    if (filename != NULL) {
    9.43 -        disposition_name = strdup(filename);
    9.44 -        if (disposition_name == NULL)
    9.45 -            goto enomem;
    9.46 -    }
    9.47 -
    9.48      if (encoding_type) {
    9.49          encoding = mailmime_mechanism_new(encoding_type, NULL);
    9.50          if (encoding == NULL)
    9.51              goto enomem;
    9.52      }
    9.53  
    9.54 -    disposition =
    9.55 -            mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_INLINE,
    9.56 -                    disposition_name, NULL, NULL, NULL, (size_t) -1);
    9.57 -    if (disposition == NULL)
    9.58 -        goto enomem;
    9.59 -    disposition_name = NULL;
    9.60 -
    9.61 -    mime_fields = mailmime_fields_new_with_data(encoding, NULL, NULL,
    9.62 +    mime_fields = mailmime_fields_new_with_data(encoding, content_id, NULL,
    9.63              disposition, NULL);
    9.64      if (mime_fields == NULL)
    9.65          goto enomem;
    9.66      encoding = NULL;
    9.67      disposition = NULL;
    9.68 +    content_id = NULL;
    9.69  
    9.70  	content = mailmime_content_new_with_str(mime_type);
    9.71      if (content == NULL)
    9.72 @@ -269,7 +281,7 @@
    9.73  }
    9.74  
    9.75  struct mailmime * get_file_part(
    9.76 -        const char * filename,
    9.77 +        pEp_rid_list_t* resource,
    9.78          const char * mime_type,
    9.79          char * data,
    9.80          size_t length
    9.81 @@ -282,20 +294,32 @@
    9.82      struct mailmime_content * content = NULL;
    9.83      struct mailmime * mime = NULL;
    9.84      struct mailmime_fields * mime_fields = NULL;
    9.85 +    char* content_id = NULL;
    9.86      int r;
    9.87 -
    9.88 -    if (filename != NULL) {
    9.89 -        disposition_name = strdup(filename);
    9.90 -        if (disposition_name == NULL)
    9.91 -            goto enomem;
    9.92 +                
    9.93 +    if (resource != NULL && resource->rid != NULL) {
    9.94 +        switch (resource->rid_type) {
    9.95 +            case PEP_RID_CID:
    9.96 +                content_id = strdup(resource->rid);
    9.97 +                break;
    9.98 +            case PEP_RID_FILENAME:
    9.99 +            default:
   9.100 +                disposition_name = strdup(resource->rid);
   9.101 +                if (disposition_name == NULL)
   9.102 +                    goto enomem;
   9.103 +                    
   9.104 +                disposition =
   9.105 +                        mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_ATTACHMENT,
   9.106 +                                disposition_name, NULL, NULL, NULL, (size_t) -1);
   9.107 +                                
   9.108 +                if (disposition == NULL)
   9.109 +                    goto enomem;
   9.110 +                disposition_name = NULL;
   9.111 +                
   9.112 +                break;
   9.113 +        }    
   9.114      }
   9.115 -
   9.116 -    disposition =
   9.117 -            mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_ATTACHMENT,
   9.118 -                    disposition_name, NULL, NULL, NULL, (size_t) -1);
   9.119 -    if (disposition == NULL)
   9.120 -        goto enomem;
   9.121 -    disposition_name = NULL;
   9.122 +    
   9.123  
   9.124      content = mailmime_content_new_with_str(mime_type);
   9.125      if (content == NULL)
   9.126 @@ -306,7 +330,7 @@
   9.127      if (encoding == NULL)
   9.128          goto enomem;
   9.129  
   9.130 -    mime_fields = mailmime_fields_new_with_data(encoding, NULL, NULL,
   9.131 +    mime_fields = mailmime_fields_new_with_data(encoding, content_id, NULL,
   9.132              disposition, NULL);
   9.133      if (mime_fields == NULL)
   9.134          goto enomem;
   9.135 @@ -340,7 +364,7 @@
   9.136          mailmime_fields_free(mime_fields);
   9.137      if (mime)
   9.138          mailmime_free(mime);
   9.139 -
   9.140 +    
   9.141      return NULL;
   9.142  }
   9.143  
   9.144 @@ -596,7 +620,9 @@
   9.145      return content;
   9.146  }
   9.147  
   9.148 -char * _get_filename(struct mailmime *mime)
   9.149 +
   9.150 +/* Return a list of identifier_type and resource id (filename, cid, etc) */
   9.151 +pEp_rid_list_t* _get_resource_id_list(struct mailmime *mime)
   9.152  {
   9.153      clist * _fieldlist = NULL;
   9.154  
   9.155 @@ -608,9 +634,22 @@
   9.156          return NULL;
   9.157  
   9.158      clistiter *cur;
   9.159 +
   9.160 +    pEp_rid_list_t* rid_list = NULL; 
   9.161 +    pEp_rid_list_t** rid_list_curr_p = &rid_list; 
   9.162 +        
   9.163      for (cur = clist_begin(_fieldlist); cur; cur = clist_next(cur)) {
   9.164          struct mailmime_field * _field = clist_content(cur);
   9.165 -        if (_field && _field->fld_type == MAILMIME_FIELD_DISPOSITION) {
   9.166 +        /* content_id */
   9.167 +        if (_field && _field->fld_type == MAILMIME_FIELD_ID) {
   9.168 +            pEp_rid_list_t* new_rid = (pEp_rid_list_t*)calloc(1, sizeof(pEp_rid_list_t));
   9.169 +            new_rid->rid_type = PEP_RID_CID;
   9.170 +            new_rid->rid = strdup(_field->fld_data.fld_id);
   9.171 +            *rid_list_curr_p = new_rid;
   9.172 +            rid_list_curr_p = &new_rid->next;
   9.173 +        }
   9.174 +        else if (_field && _field->fld_type == MAILMIME_FIELD_DISPOSITION) {
   9.175 +            /* filename */
   9.176              if (_field->fld_data.fld_disposition &&
   9.177                      _field->fld_data.fld_disposition->dsp_parms) {
   9.178                  clist * _parmlist =
   9.179 @@ -620,14 +659,66 @@
   9.180                          clist_next(cur2)) {
   9.181                      struct mailmime_disposition_parm * param =
   9.182                              clist_content(cur2);
   9.183 -                    if (param->pa_type == MAILMIME_DISPOSITION_PARM_FILENAME)
   9.184 -                        return param->pa_data.pa_filename;
   9.185 +                    if (param->pa_type == MAILMIME_DISPOSITION_PARM_FILENAME) {
   9.186 +                        pEp_rid_list_t* new_rid = (pEp_rid_list_t*)calloc(1, sizeof(pEp_rid_list_t));
   9.187 +                        new_rid->rid_type = PEP_RID_FILENAME;
   9.188 +                        new_rid->rid = strdup(param->pa_data.pa_filename);
   9.189 +                        *rid_list_curr_p = new_rid;
   9.190 +                        rid_list_curr_p = &new_rid->next;
   9.191 +                    }                
   9.192                  }
   9.193              }
   9.194          }
   9.195      }
   9.196 +    /* Will almost certainly usually be a singleton, but we need to be able to decide */
   9.197 +    return rid_list;
   9.198 +}
   9.199  
   9.200 -    return NULL;
   9.201 +
   9.202 +/* FIXME: about to be obsoleted? */
   9.203 +char * _get_filename_or_cid(struct mailmime *mime)
   9.204 +{
   9.205 +    clist * _fieldlist = NULL;
   9.206 +
   9.207 +    assert(mime);
   9.208 +
   9.209 +    if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list)
   9.210 +        _fieldlist = mime->mm_mime_fields->fld_list;
   9.211 +    else
   9.212 +        return NULL;
   9.213 +
   9.214 +    clistiter *cur;
   9.215 +    
   9.216 +    char* _temp_filename_ptr = NULL;
   9.217 +    
   9.218 +    for (cur = clist_begin(_fieldlist); cur; cur = clist_next(cur)) {
   9.219 +        struct mailmime_field * _field = clist_content(cur);
   9.220 +        if (_field && _field->fld_type == MAILMIME_FIELD_ID) {
   9.221 +            /* We prefer CIDs to filenames when both are present */
   9.222 +            free(_temp_filename_ptr); /* can be null, it's ok */
   9.223 +            return build_uri("cid", _field->fld_data.fld_id); 
   9.224 +        }
   9.225 +        else if (_field && _field->fld_type == MAILMIME_FIELD_DISPOSITION) {
   9.226 +            if (_field->fld_data.fld_disposition &&
   9.227 +                    _field->fld_data.fld_disposition->dsp_parms &&
   9.228 +                    !_temp_filename_ptr) {
   9.229 +                clist * _parmlist =
   9.230 +                        _field->fld_data.fld_disposition->dsp_parms;
   9.231 +                clistiter *cur2;
   9.232 +                for (cur2 = clist_begin(_parmlist); cur2; cur2 =
   9.233 +                        clist_next(cur2)) {
   9.234 +                    struct mailmime_disposition_parm * param =
   9.235 +                            clist_content(cur2);
   9.236 +                    if (param->pa_type == MAILMIME_DISPOSITION_PARM_FILENAME) {
   9.237 +                        _temp_filename_ptr = build_uri("file", param->pa_data.pa_filename);
   9.238 +                        break;
   9.239 +                    }                
   9.240 +                }
   9.241 +            }
   9.242 +        }
   9.243 +    }
   9.244 +    /* Ok, it wasn't a CID */
   9.245 +    return _temp_filename_ptr;
   9.246  }
   9.247  
   9.248  static bool parameter_has_value(
   9.249 @@ -784,4 +875,3 @@
   9.250  
   9.251      return EINVAL;
   9.252  }
   9.253 -
    10.1 --- a/src/etpan_mime.h	Fri Jun 30 16:33:08 2017 +0200
    10.2 +++ b/src/etpan_mime.h	Wed Jul 19 10:22:13 2017 +0200
    10.3 @@ -7,6 +7,8 @@
    10.4  #include <libetpan/mailmime.h>
    10.5  #include <libetpan/mailmime_encode.h>
    10.6  
    10.7 +#include "resource_id.h"
    10.8 +
    10.9  struct mailmime * part_new_empty(
   10.10          struct mailmime_content * content,
   10.11          struct mailmime_fields * mime_fields,
   10.12 @@ -16,7 +18,7 @@
   10.13  struct mailmime * get_pgp_encrypted_part(void);
   10.14  
   10.15  struct mailmime * get_text_part(
   10.16 -        const char * filename,
   10.17 +        pEp_rid_list_t* resource,
   10.18          const char * mime_type,
   10.19          const char * text,
   10.20          size_t length,
   10.21 @@ -24,7 +26,7 @@
   10.22      );
   10.23  
   10.24  struct mailmime * get_file_part(
   10.25 -        const char * filename,
   10.26 +        pEp_rid_list_t* resource,
   10.27          const char * mime_type,
   10.28          char * data,
   10.29          size_t length
   10.30 @@ -70,7 +72,9 @@
   10.31  
   10.32  clist * _get_fields(struct mailmime * mime);
   10.33  struct mailmime_content * _get_content(struct mailmime * mime);
   10.34 -char * _get_filename(struct mailmime *mime);
   10.35 +char * _get_filename_or_cid(struct mailmime *mime);
   10.36 +pEp_rid_list_t* _get_resource_id_list(struct mailmime *mime);
   10.37 +char* _build_uri(char* uri_prefix, char* resource);
   10.38  bool _is_multipart(struct mailmime_content *content, const char *subtype);
   10.39  bool _is_PGP_MIME(struct mailmime_content *content);
   10.40  bool _is_text_part(struct mailmime_content *content, const char *subtype);
   10.41 @@ -80,4 +84,3 @@
   10.42          char **type,
   10.43          char **charset
   10.44      );
   10.45 -
    11.1 --- a/src/message_api.c	Fri Jun 30 16:33:08 2017 +0200
    11.2 +++ b/src/message_api.c	Wed Jul 19 10:22:13 2017 +0200
    11.3 @@ -20,6 +20,29 @@
    11.4  #define _MAX(A, B) ((B) > (A) ? (B) : (A))
    11.5  #endif
    11.6  
    11.7 +static char* _get_resource_ptr_noown(char* uri) {
    11.8 +    char* uri_delim = strstr(uri, "://");
    11.9 +    if (!uri_delim)
   11.10 +        return uri;
   11.11 +    else
   11.12 +        return uri + 3;
   11.13 +}
   11.14 +
   11.15 +static char* get_resource(char* uri) {
   11.16 +    const char* resource_ptr = _get_resource_ptr_noown(uri);
   11.17 +    char* resource_str = NULL;
   11.18 +    if (resource_ptr)
   11.19 +        resource_str = strdup(resource_ptr);
   11.20 +    return resource_str;
   11.21 +}
   11.22 +
   11.23 +static bool is_file_uri(char* str) {
   11.24 +    return(strncmp(str, "file://", 7) == 0);
   11.25 +}
   11.26 +
   11.27 +static bool is_cid_uri(const char* str) {
   11.28 +    return(strncmp(str, "cid://", 6) == 0);
   11.29 +}
   11.30  
   11.31  static bool string_equality(const char *s1, const char *s2)
   11.32  {
   11.33 @@ -48,7 +71,7 @@
   11.34  {
   11.35      assert(fe);
   11.36  
   11.37 -    if (bl == NULL || bl->filename == NULL || fe == NULL)
   11.38 +    if (bl == NULL || bl->filename == NULL || fe == NULL || is_cid_uri(bl->filename))
   11.39          return false;
   11.40  
   11.41      assert(bl && bl->filename);
   11.42 @@ -427,7 +450,7 @@
   11.43      dst->attachments = _a;
   11.44  
   11.45      _a = bloblist_add(_a, ctext, csize, "application/octet-stream",
   11.46 -        "msg.asc");
   11.47 +        "file://msg.asc");
   11.48      if (_a == NULL)
   11.49          goto enomem;
   11.50  
   11.51 @@ -528,7 +551,7 @@
   11.52          if (ctext) {
   11.53  
   11.54              bloblist_t *_a = bloblist_add(dst->attachments, ctext, csize,
   11.55 -                "application/octet-stream", "PGPexch.htm.pgp");
   11.56 +                "application/octet-stream", "file://PGPexch.htm.pgp");
   11.57              if (_a == NULL)
   11.58                  goto enomem;
   11.59              if (dst->attachments == NULL)
   11.60 @@ -567,24 +590,34 @@
   11.61                  if (ctext) {
   11.62                      char *filename = NULL;
   11.63  
   11.64 -                    if (_s->filename) {
   11.65 +                    char *attach_fn = _s->filename;
   11.66 +                    if (attach_fn && !is_cid_uri(attach_fn)) {
   11.67                          size_t len = strlen(_s->filename);
   11.68                          size_t bufsize = len + 5; // length of .pgp extension + NUL
   11.69 +                        bool already_uri = false;
   11.70 +                        if (is_file_uri(attach_fn))
   11.71 +                            already_uri = true;
   11.72 +                        else
   11.73 +                            bufsize += 7; // length of file://
   11.74 +                            
   11.75                          filename = calloc(1, bufsize);
   11.76                          if (filename == NULL)
   11.77                              goto enomem;
   11.78  
   11.79 -                        strlcpy(filename, _s->filename, bufsize);
   11.80 +                        if (!already_uri)
   11.81 +                            strlcpy(filename, "file://", bufsize);
   11.82 +                        // First char is NUL, so we're ok, even if not copying above. (calloc)
   11.83 +                        strlcat(filename, _s->filename, bufsize);
   11.84                          strlcat(filename, ".pgp", bufsize);
   11.85                      }
   11.86                      else {
   11.87 -                        filename = calloc(1, 20);
   11.88 +                        filename = calloc(1, 27);
   11.89                          if (filename == NULL)
   11.90                              goto enomem;
   11.91  
   11.92                          ++n;
   11.93                          n &= 0xffff;
   11.94 -                        snprintf(filename, 20, "Attachment%d.pgp", n);
   11.95 +                        snprintf(filename, 20, "file://Attachment%d.pgp", n);
   11.96                      }
   11.97  
   11.98                      _d = bloblist_add(_d, ctext, csize, "application/octet-stream",
   11.99 @@ -736,7 +769,7 @@
  11.100  {
  11.101      assert(blob);
  11.102  
  11.103 -    if (blob == NULL || blob->filename == NULL)
  11.104 +    if (blob == NULL || blob->filename == NULL || is_cid_uri(blob->filename))
  11.105          return false;
  11.106  
  11.107      char *ext = strrchr(blob->filename, '.');
  11.108 @@ -760,12 +793,13 @@
  11.109  {
  11.110      assert(blob);
  11.111      assert(blob->filename);
  11.112 -    if (blob == NULL || blob->filename == NULL)
  11.113 +    if (blob == NULL || blob->filename == NULL || is_cid_uri(blob->filename))
  11.114          return false;
  11.115  
  11.116 -    if (strncmp(blob->filename, "PGPexch.htm.", 12) == 0) {
  11.117 -        if (strcmp(blob->filename + 11, ".pgp") == 0 ||
  11.118 -            strcmp(blob->filename + 11, ".asc") == 0)
  11.119 +    const char* bare_filename_ptr = _get_resource_ptr_noown(blob->filename);
  11.120 +    if (strncmp(bare_filename_ptr, "PGPexch.htm.", 12) == 0) {
  11.121 +        if (strcmp(bare_filename_ptr + 11, ".pgp") == 0 ||
  11.122 +            strcmp(bare_filename_ptr + 11, ".asc") == 0)
  11.123              return true;
  11.124      }
  11.125  
  11.126 @@ -775,7 +809,7 @@
  11.127  static char * without_double_ending(const char *filename)
  11.128  {
  11.129      assert(filename);
  11.130 -    if (filename == NULL)
  11.131 +    if (filename == NULL || is_cid_uri(filename))
  11.132          return NULL;
  11.133  
  11.134      char *ext = strrchr(filename, '.');
  11.135 @@ -1012,7 +1046,7 @@
  11.136      assert(size);
  11.137  
  11.138       bloblist_t *bl = bloblist_add(msg->attachments, keydata, size, "application/pgp-keys",
  11.139 -                      "pEpkey.asc");
  11.140 +                      "file://pEpkey.asc");
  11.141  
  11.142      if (msg->attachments == NULL && bl)
  11.143          msg->attachments = bl;
    12.1 --- a/src/mime.c	Fri Jun 30 16:33:08 2017 +0200
    12.2 +++ b/src/mime.c	Wed Jul 19 10:22:13 2017 +0200
    12.3 @@ -9,6 +9,7 @@
    12.4  #include <assert.h>
    12.5  #include <errno.h>
    12.6  
    12.7 +#include "resource_id.h"
    12.8  #include "etpan_mime.h"
    12.9  #include "wrappers.h"
   12.10  
   12.11 @@ -118,8 +119,13 @@
   12.12      if (mime == NULL)
   12.13          goto enomem;
   12.14  
   12.15 -    submime = get_text_part("msg.txt", "text/plain", plaintext, strlen(plaintext),
   12.16 +    pEp_rid_list_t* resource = new_rid_node(PEP_RID_FILENAME, "msg.txt");
   12.17 +    
   12.18 +    submime = get_text_part(resource, "text/plain", plaintext, strlen(plaintext),
   12.19              MAILMIME_MECHANISM_QUOTED_PRINTABLE);
   12.20 +    free_rid_list(resource);
   12.21 +    resource = NULL;
   12.22 +    
   12.23      assert(submime);
   12.24      if (submime == NULL)
   12.25          goto enomem;
   12.26 @@ -134,8 +140,12 @@
   12.27          submime = NULL;
   12.28      }
   12.29  
   12.30 -    submime = get_text_part("msg.html", "text/html", htmltext, strlen(htmltext),
   12.31 +    resource = new_rid_node(PEP_RID_FILENAME, "msg.html");
   12.32 +    submime = get_text_part(resource, "text/html", htmltext, strlen(htmltext),
   12.33              MAILMIME_MECHANISM_QUOTED_PRINTABLE);
   12.34 +    free_rid_list(resource);
   12.35 +    resource = NULL;
   12.36 +    
   12.37      assert(submime);
   12.38      if (submime == NULL)
   12.39          goto enomem;
   12.40 @@ -186,7 +196,10 @@
   12.41      else
   12.42          mime_type = blob->mime_type;
   12.43  
   12.44 -    mime = get_file_part(blob->filename, mime_type, blob->value, blob->size);
   12.45 +    pEp_rid_list_t* resource = parse_uri(blob->filename);
   12.46 +    mime = get_file_part(resource, mime_type, blob->value, blob->size);
   12.47 +    free_rid_list(resource);
   12.48 +    
   12.49      assert(mime);
   12.50      if (mime == NULL)
   12.51          goto enomem;
   12.52 @@ -559,6 +572,39 @@
   12.53      return status;
   12.54  }
   12.55  
   12.56 +static bool has_exceptional_extension(char* filename) {
   12.57 +    if (!filename)
   12.58 +        return false;
   12.59 +    int len = strlen(filename);
   12.60 +    if (len < 4)
   12.61 +        return false;
   12.62 +    char* ext_start = filename + (len - 4);
   12.63 +    if (strcmp(ext_start, ".pgp") == 0 || strcmp(ext_start, ".gpg") == 0 ||
   12.64 +        strcmp(ext_start, ".asc") == 0 || strcmp(ext_start, ".pEp") == 0)
   12.65 +        return true;
   12.66 +    return false;
   12.67 +}
   12.68 +
   12.69 +static pEp_rid_list_t* choose_resource_id(pEp_rid_list_t* rid_list) {
   12.70 +    pEp_rid_list_t* retval = rid_list;
   12.71 +    
   12.72 +    /* multiple elements - least common case */
   12.73 +    if (rid_list && rid_list->next) {
   12.74 +        pEp_rid_list_t* rid_list_curr = rid_list;
   12.75 +        retval = rid_list; 
   12.76 +        
   12.77 +        while (rid_list_curr) {
   12.78 +            pEp_resource_id_type rid_type = rid_list_curr->rid_type;
   12.79 +            if (rid_type == PEP_RID_CID)
   12.80 +                retval = rid_list_curr;
   12.81 +            else if (rid_type == PEP_RID_FILENAME && has_exceptional_extension(rid_list_curr->rid))
   12.82 +                return rid_list_curr;
   12.83 +            rid_list_curr = rid_list_curr->next;
   12.84 +        }
   12.85 +    } 
   12.86 +    return retval;
   12.87 +}
   12.88 +
   12.89  static PEP_STATUS mime_encode_message_plain(
   12.90          const message *msg,
   12.91          bool omit_fields,
   12.92 @@ -586,12 +632,19 @@
   12.93              goto pep_error;
   12.94      }
   12.95      else {
   12.96 -        if (is_PGP_message_text(plaintext))
   12.97 -            mime = get_text_part("msg.asc", "application/octet-stream", plaintext,
   12.98 +        pEp_rid_list_t* resource = NULL;
   12.99 +        if (is_PGP_message_text(plaintext)) {
  12.100 +            resource = new_rid_node(PEP_RID_FILENAME, "msg.asc");
  12.101 +            mime = get_text_part(resource, "application/octet-stream", plaintext,
  12.102                      strlen(plaintext), MAILMIME_MECHANISM_7BIT);
  12.103 -        else
  12.104 -            mime = get_text_part("msg.txt", "text/plain", plaintext, strlen(plaintext),
  12.105 +        }
  12.106 +        else {
  12.107 +            resource = new_rid_node(PEP_RID_FILENAME, "msg.txt");
  12.108 +            mime = get_text_part(resource, "text/plain", plaintext, strlen(plaintext),
  12.109                      MAILMIME_MECHANISM_QUOTED_PRINTABLE);
  12.110 +        }
  12.111 +        free_rid_list(resource);
  12.112 +        
  12.113          assert(mime);
  12.114          if (mime == NULL)
  12.115              goto enomem;
  12.116 @@ -694,8 +747,12 @@
  12.117          submime = NULL;
  12.118      }
  12.119  
  12.120 -    submime = get_text_part("msg.asc", "application/octet-stream", plaintext,
  12.121 +    pEp_rid_list_t* resource = new_rid_node(PEP_RID_FILENAME, "msg.asc");
  12.122 +    submime = get_text_part(resource, "application/octet-stream", plaintext,
  12.123              plaintext_size, MAILMIME_MECHANISM_7BIT);
  12.124 +            
  12.125 +    free_rid_list(resource);
  12.126 +    
  12.127      assert(submime);
  12.128      if (submime == NULL)
  12.129          goto enomem;
  12.130 @@ -1343,19 +1400,50 @@
  12.131                  if (status)
  12.132                      return status;
  12.133  
  12.134 -                filename = _get_filename(mime);
  12.135 +                pEp_rid_list_t* resource_id_list = _get_resource_id_list(mime);
  12.136 +                pEp_rid_list_t* chosen_resource_id = choose_resource_id(resource_id_list);
  12.137 +                
  12.138 +                //filename = _get_filename_or_cid(mime);
  12.139                  char *_filename = NULL;
  12.140 -                if (filename) {
  12.141 +                
  12.142 +                if (chosen_resource_id) {
  12.143 +                    filename = chosen_resource_id->rid;
  12.144                      size_t index = 0;
  12.145 +                    /* NOTA BENE */
  12.146 +                    /* The prefix we just added shouldn't be a problem - this is about decoding %XX (RFC 2392) */
  12.147 +                    /* If it becomes one, we have some MESSY fixing to do. :(                                  */
  12.148                      r = mailmime_encoded_phrase_parse("utf-8", filename,
  12.149                              strlen(filename), &index, "utf-8", &_filename);
  12.150 -                    if (r)
  12.151 +                    if (r) {
  12.152                          goto enomem;
  12.153 +                    }
  12.154 +                    char* file_prefix = NULL;
  12.155 +                    
  12.156 +                    /* in case there are others later */
  12.157 +                    switch (chosen_resource_id->rid_type) {
  12.158 +                        case PEP_RID_CID:
  12.159 +                            file_prefix = "cid";
  12.160 +                            break;
  12.161 +                        case PEP_RID_FILENAME:
  12.162 +                            file_prefix = "file";
  12.163 +                            break;
  12.164 +                        default:
  12.165 +                            break;
  12.166 +                    }
  12.167 +
  12.168 +                    
  12.169 +                    if (file_prefix) {
  12.170 +                        filename = build_uri(file_prefix, _filename);
  12.171 +                        free(_filename);
  12.172 +                        _filename = filename;
  12.173 +                    }
  12.174                  }
  12.175  
  12.176                  bloblist_t *_a = bloblist_add(msg->attachments, data, size,
  12.177                          mime_type, _filename);
  12.178                  free(_filename);
  12.179 +                free_rid_list(resource_id_list);
  12.180 +                resource_id_list = NULL;
  12.181                  if (_a == NULL)
  12.182                      return PEP_OUT_OF_MEMORY;
  12.183                  if (msg->attachments == NULL)
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/resource_id.c	Wed Jul 19 10:22:13 2017 +0200
    13.3 @@ -0,0 +1,70 @@
    13.4 +// This file is under GNU General Public License 3.0
    13.5 +// see LICENSE.txt
    13.6 +
    13.7 +#include "pEp_internal.h"
    13.8 +#include "resource_id.h"
    13.9 +
   13.10 +pEp_rid_list_t* new_rid_node(pEp_resource_id_type type, const char* resource) {
   13.11 +    pEp_rid_list_t* retval = (pEp_rid_list_t*)calloc(1, sizeof(pEp_rid_list_t));
   13.12 +    retval->rid_type = type;
   13.13 +    retval->rid = strdup(resource);
   13.14 +    return retval;
   13.15 +}
   13.16 +
   13.17 +void free_rid_list(pEp_rid_list_t* list) {
   13.18 +    while (list) {
   13.19 +        pEp_rid_list_t* nextptr = list->next;
   13.20 +        free(list->rid);
   13.21 +        free(list);
   13.22 +        list = nextptr;
   13.23 +    }
   13.24 +}
   13.25 +
   13.26 +const char* get_resource_ptr_noown(const char* uri) {
   13.27 +    char* uri_delim = strstr(uri, "://");
   13.28 +    if (!uri_delim)
   13.29 +        return uri;
   13.30 +    else
   13.31 +        return uri_delim + 3;
   13.32 +}
   13.33 +
   13.34 +char* get_resource(char* uri) {
   13.35 +    const char* resource_ptr = get_resource_ptr_noown(uri);
   13.36 +    char* resource_str = NULL;
   13.37 +    if (resource_ptr)
   13.38 +        resource_str = strdup(resource_ptr);
   13.39 +    return resource_str;
   13.40 +}
   13.41 +
   13.42 +bool is_file_uri(char* str) {
   13.43 +    return(!str ? false : strncmp(str, "file://", 7) == 0);
   13.44 +}
   13.45 +
   13.46 +bool is_cid_uri(const char* str) {
   13.47 +    return(!str ? false : strncmp(str, "cid://", 6) == 0);
   13.48 +}
   13.49 +
   13.50 +pEp_rid_list_t* parse_uri(const char* uri) {
   13.51 +    if (!uri)
   13.52 +        return NULL;
   13.53 +    pEp_resource_id_type type = (is_cid_uri(uri) ? PEP_RID_CID : PEP_RID_FILENAME);
   13.54 +    const char* resource = get_resource_ptr_noown(uri);
   13.55 +    return new_rid_node(type, resource);
   13.56 +}
   13.57 +
   13.58 +char* build_uri(const char* uri_prefix, const char* resource) {
   13.59 +    if (!uri_prefix || !resource)
   13.60 +        return NULL;
   13.61 +    const char* delim = "://";
   13.62 +    const int delim_len = 3;
   13.63 +    int prefix_len = strlen(uri_prefix);
   13.64 +    int resource_len = strlen(resource);
   13.65 +    int retval_len = prefix_len + delim_len + resource_len;
   13.66 +
   13.67 +    char* retval = calloc(1, retval_len + 1);
   13.68 +    strlcpy(retval, uri_prefix, retval_len + 1);
   13.69 +    strlcat(retval, delim, retval_len + 1);
   13.70 +    strlcat(retval, resource, retval_len + 1);
   13.71 +    
   13.72 +    return retval;
   13.73 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/resource_id.h	Wed Jul 19 10:22:13 2017 +0200
    14.3 @@ -0,0 +1,34 @@
    14.4 +// This file is under GNU General Public License 3.0
    14.5 +// see LICENSE.txt
    14.6 +
    14.7 +#pragma once
    14.8 +
    14.9 +/* structs to contain info about parsed resource ids (filenames, uids) */
   14.10 +typedef enum _resource_id_type {
   14.11 +    PEP_RID_FILENAME,
   14.12 +    PEP_RID_CID
   14.13 +} pEp_resource_id_type;
   14.14 +
   14.15 +typedef struct pEp_rid_list_t pEp_rid_list_t;
   14.16 +
   14.17 +struct pEp_rid_list_t {
   14.18 +    pEp_resource_id_type rid_type;
   14.19 +    char* rid;
   14.20 +    pEp_rid_list_t* next;    
   14.21 +};
   14.22 +
   14.23 +pEp_rid_list_t* new_rid_node(pEp_resource_id_type type, const char* resource);
   14.24 +
   14.25 +void free_rid_list(pEp_rid_list_t* list);
   14.26 +
   14.27 +pEp_rid_list_t* parse_uri(const char* uri);
   14.28 +
   14.29 +char* build_uri(const char* uri_prefix, const char* resource);
   14.30 +
   14.31 +const char* get_resource_ptr_noown(const char* uri);
   14.32 +
   14.33 +char* get_resource(char* uri);
   14.34 +
   14.35 +bool is_file_uri(char* str);
   14.36 +
   14.37 +bool is_cid_uri(const char* str);
    15.1 --- a/src/sqlite3.c	Fri Jun 30 16:33:08 2017 +0200
    15.2 +++ b/src/sqlite3.c	Wed Jul 19 10:22:13 2017 +0200
    15.3 @@ -1,6 +1,6 @@
    15.4  /******************************************************************************
    15.5  ** This file is an amalgamation of many separate C source files from SQLite
    15.6 -** version 3.13.0.  By combining all the individual C code files into this 
    15.7 +** version 3.19.3.  By combining all the individual C code files into this
    15.8  ** single large file, the entire code can be compiled as a single translation
    15.9  ** unit.  This allows many compilers to do optimizations that would not be
   15.10  ** possible if the files were compiled separately.  Performance improvements
   15.11 @@ -9,7 +9,7 @@
   15.12  **
   15.13  ** This file is all you need to compile SQLite.  To use SQLite in other
   15.14  ** programs, you need this file and the "sqlite3.h" header file that defines
   15.15 -** the programming interface to the SQLite library.  (If you do not have 
   15.16 +** the programming interface to the SQLite library.  (If you do not have
   15.17  ** the "sqlite3.h" header file at hand, you will find a copy embedded within
   15.18  ** the text of this file.  Search for "Begin file sqlite3.h" to find the start
   15.19  ** of the embedded sqlite3.h header file.) Additional code files may be needed
   15.20 @@ -37,8 +37,8 @@
   15.21  ** Internal interface definitions for SQLite.
   15.22  **
   15.23  */
   15.24 -#ifndef _SQLITEINT_H_
   15.25 -#define _SQLITEINT_H_
   15.26 +#ifndef SQLITEINT_H
   15.27 +#define SQLITEINT_H
   15.28  
   15.29  /* Special Comments:
   15.30  **
   15.31 @@ -68,6 +68,14 @@
   15.32  */
   15.33  
   15.34  /*
   15.35 +** Make sure the Tcl calling convention macro is defined.  This macro is
   15.36 +** only used by test code and Tcl integration code.
   15.37 +*/
   15.38 +#ifndef SQLITE_TCLAPI
   15.39 +#  define SQLITE_TCLAPI
   15.40 +#endif
   15.41 +
   15.42 +/*
   15.43  ** Make sure that rand_s() is available on Windows systems with MSVC 2005
   15.44  ** or higher.
   15.45  */
   15.46 @@ -97,8 +105,8 @@
   15.47  **
   15.48  ** This file contains code that is specific to MSVC.
   15.49  */
   15.50 -#ifndef _MSVC_H_
   15.51 -#define _MSVC_H_
   15.52 +#ifndef SQLITE_MSVC_H
   15.53 +#define SQLITE_MSVC_H
   15.54  
   15.55  #if defined(_MSC_VER)
   15.56  #pragma warning(disable : 4054)
   15.57 @@ -118,7 +126,7 @@
   15.58  #pragma warning(disable : 4706)
   15.59  #endif /* defined(_MSC_VER) */
   15.60  
   15.61 -#endif /* _MSVC_H_ */
   15.62 +#endif /* SQLITE_MSVC_H */
   15.63  
   15.64  /************** End of msvc.h ************************************************/
   15.65  /************** Continuing where we left off in sqliteInt.h ******************/
   15.66 @@ -196,12 +204,29 @@
   15.67  # define _LARGEFILE_SOURCE 1
   15.68  #endif
   15.69  
   15.70 -/* What version of GCC is being used.  0 means GCC is not being used */
   15.71 -#ifdef __GNUC__
   15.72 +/* The GCC_VERSION and MSVC_VERSION macros are used to
   15.73 +** conditionally include optimizations for each of these compilers.  A
   15.74 +** value of 0 means that compiler is not being used.  The
   15.75 +** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific
   15.76 +** optimizations, and hence set all compiler macros to 0
   15.77 +**
   15.78 +** There was once also a CLANG_VERSION macro.  However, we learn that the
   15.79 +** version numbers in clang are for "marketing" only and are inconsistent
   15.80 +** and unreliable.  Fortunately, all versions of clang also recognize the
   15.81 +** gcc version numbers and have reasonable settings for gcc version numbers,
   15.82 +** so the GCC_VERSION macro will be set to a correct non-zero value even
   15.83 +** when compiling with clang.
   15.84 +*/
   15.85 +#if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC)
   15.86  # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
   15.87  #else
   15.88  # define GCC_VERSION 0
   15.89  #endif
   15.90 +#if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC)
   15.91 +# define MSVC_VERSION _MSC_VER
   15.92 +#else
   15.93 +# define MSVC_VERSION 0
   15.94 +#endif
   15.95  
   15.96  /* Needed for various definitions... */
   15.97  #if defined(__GNUC__) && !defined(_GNU_SOURCE)
   15.98 @@ -282,8 +307,8 @@
   15.99  ** the version number) and changes its name to "sqlite3.h" as
  15.100  ** part of the build process.
  15.101  */
  15.102 -#ifndef _SQLITE3_H_
  15.103 -#define _SQLITE3_H_
  15.104 +#ifndef SQLITE3_H
  15.105 +#define SQLITE3_H
  15.106  #include <stdarg.h>     /* Needed for the definition of va_list */
  15.107  
  15.108  /*
  15.109 @@ -306,8 +331,17 @@
  15.110  #ifndef SQLITE_CDECL
  15.111  # define SQLITE_CDECL
  15.112  #endif
  15.113 +#ifndef SQLITE_APICALL
  15.114 +# define SQLITE_APICALL
  15.115 +#endif
  15.116  #ifndef SQLITE_STDCALL
  15.117 -# define SQLITE_STDCALL
  15.118 +# define SQLITE_STDCALL SQLITE_APICALL
  15.119 +#endif
  15.120 +#ifndef SQLITE_CALLBACK
  15.121 +# define SQLITE_CALLBACK
  15.122 +#endif
  15.123 +#ifndef SQLITE_SYSAPI
  15.124 +# define SQLITE_SYSAPI
  15.125  #endif
  15.126  
  15.127  /*
  15.128 @@ -351,25 +385,26 @@
  15.129  ** be held constant and Z will be incremented or else Y will be incremented
  15.130  ** and Z will be reset to zero.
  15.131  **
  15.132 -** Since version 3.6.18, SQLite source code has been stored in the
  15.133 +** Since [version 3.6.18] ([dateof:3.6.18]), 
  15.134 +** SQLite source code has been stored in the
  15.135  ** <a href="http://www.fossil-scm.org/">Fossil configuration management
  15.136  ** system</a>.  ^The SQLITE_SOURCE_ID macro evaluates to
  15.137  ** a string which identifies a particular check-in of SQLite
  15.138  ** within its configuration management system.  ^The SQLITE_SOURCE_ID
  15.139 -** string contains the date and time of the check-in (UTC) and an SHA1
  15.140 -** hash of the entire source tree.
  15.141 +** string contains the date and time of the check-in (UTC) and a SHA1
  15.142 +** or SHA3-256 hash of the entire source tree.
  15.143  **
  15.144  ** See also: [sqlite3_libversion()],
  15.145  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
  15.146  ** [sqlite_version()] and [sqlite_source_id()].
  15.147  */
  15.148 -#define SQLITE_VERSION        "3.13.0"
  15.149 -#define SQLITE_VERSION_NUMBER 3013000
  15.150 -#define SQLITE_SOURCE_ID      "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
  15.151 +#define SQLITE_VERSION        "3.19.3"
  15.152 +#define SQLITE_VERSION_NUMBER 3019003
  15.153 +#define SQLITE_SOURCE_ID      "2017-06-08 14:26:16 0ee482a1e0eae22e08edc8978c9733a96603d4509645f348ebf55b579e89636b"
  15.154  
  15.155  /*
  15.156  ** CAPI3REF: Run-Time Library Version Numbers
  15.157 -** KEYWORDS: sqlite3_version, sqlite3_sourceid
  15.158 +** KEYWORDS: sqlite3_version sqlite3_sourceid
  15.159  **
  15.160  ** These interfaces provide the same information as the [SQLITE_VERSION],
  15.161  ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
  15.162 @@ -398,9 +433,9 @@
  15.163  ** See also: [sqlite_version()] and [sqlite_source_id()].
  15.164  */
  15.165  SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
  15.166 -SQLITE_API const char *SQLITE_STDCALL sqlite3_libversion(void);
  15.167 -SQLITE_API const char *SQLITE_STDCALL sqlite3_sourceid(void);
  15.168 -SQLITE_API int SQLITE_STDCALL sqlite3_libversion_number(void);
  15.169 +SQLITE_API const char *sqlite3_libversion(void);
  15.170 +SQLITE_API const char *sqlite3_sourceid(void);
  15.171 +SQLITE_API int sqlite3_libversion_number(void);
  15.172  
  15.173  /*
  15.174  ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
  15.175 @@ -425,8 +460,8 @@
  15.176  ** [sqlite_compileoption_get()] and the [compile_options pragma].
  15.177  */
  15.178  #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  15.179 -SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName);
  15.180 -SQLITE_API const char *SQLITE_STDCALL sqlite3_compileoption_get(int N);
  15.181 +SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
  15.182 +SQLITE_API const char *sqlite3_compileoption_get(int N);
  15.183  #endif
  15.184  
  15.185  /*
  15.186 @@ -465,7 +500,7 @@
  15.187  **
  15.188  ** See the [threading mode] documentation for additional information.
  15.189  */
  15.190 -SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void);
  15.191 +SQLITE_API int sqlite3_threadsafe(void);
  15.192  
  15.193  /*
  15.194  ** CAPI3REF: Database Connection Handle
  15.195 @@ -501,7 +536,11 @@
  15.196  */
  15.197  #ifdef SQLITE_INT64_TYPE
  15.198    typedef SQLITE_INT64_TYPE sqlite_int64;
  15.199 -  typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  15.200 +# ifdef SQLITE_UINT64_TYPE
  15.201 +    typedef SQLITE_UINT64_TYPE sqlite_uint64;
  15.202 +# else  
  15.203 +    typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  15.204 +# endif
  15.205  #elif defined(_MSC_VER) || defined(__BORLANDC__)
  15.206    typedef __int64 sqlite_int64;
  15.207    typedef unsigned __int64 sqlite_uint64;
  15.208 @@ -562,8 +601,8 @@
  15.209  ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
  15.210  ** argument is a harmless no-op.
  15.211  */
  15.212 -SQLITE_API int SQLITE_STDCALL sqlite3_close(sqlite3*);
  15.213 -SQLITE_API int SQLITE_STDCALL sqlite3_close_v2(sqlite3*);
  15.214 +SQLITE_API int sqlite3_close(sqlite3*);
  15.215 +SQLITE_API int sqlite3_close_v2(sqlite3*);
  15.216  
  15.217  /*
  15.218  ** The type for a callback function.
  15.219 @@ -634,7 +673,7 @@
  15.220  **      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
  15.221  ** </ul>
  15.222  */
  15.223 -SQLITE_API int SQLITE_STDCALL sqlite3_exec(
  15.224 +SQLITE_API int sqlite3_exec(
  15.225    sqlite3*,                                  /* An open database */
  15.226    const char *sql,                           /* SQL to be evaluated */
  15.227    int (*callback)(void*,int,char**,char**),  /* Callback function */
  15.228 @@ -695,7 +734,8 @@
  15.229  ** [result codes].  However, experience has shown that many of
  15.230  ** these result codes are too coarse-grained.  They do not provide as
  15.231  ** much information about problems as programmers might like.  In an effort to
  15.232 -** address this, newer versions of SQLite (version 3.3.8 and later) include
  15.233 +** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
  15.234 +** and later) include
  15.235  ** support for additional result codes that provide more detailed information
  15.236  ** about errors. These [extended result codes] are enabled or disabled
  15.237  ** on a per database connection basis using the
  15.238 @@ -758,6 +798,7 @@
  15.239  #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
  15.240  #define SQLITE_WARNING_AUTOINDEX       (SQLITE_WARNING | (1<<8))
  15.241  #define SQLITE_AUTH_USER               (SQLITE_AUTH | (1<<8))
  15.242 +#define SQLITE_OK_LOAD_PERMANENTLY     (SQLITE_OK | (1<<8))
  15.243  
  15.244  /*
  15.245  ** CAPI3REF: Flags For File Open Operations
  15.246 @@ -812,7 +853,7 @@
  15.247  ** file that were written at the application level might have changed
  15.248  ** and that adjacent bytes, even bytes within the same sector are
  15.249  ** guaranteed to be unchanged.  The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
  15.250 -** flag indicate that a file cannot be deleted when open.  The
  15.251 +** flag indicates that a file cannot be deleted when open.  The
  15.252  ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
  15.253  ** read-only media and cannot be changed even by processes with
  15.254  ** elevated privileges.
  15.255 @@ -962,6 +1003,9 @@
  15.256  ** <li> [SQLITE_IOCAP_ATOMIC64K]
  15.257  ** <li> [SQLITE_IOCAP_SAFE_APPEND]
  15.258  ** <li> [SQLITE_IOCAP_SEQUENTIAL]
  15.259 +** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
  15.260 +** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
  15.261 +** <li> [SQLITE_IOCAP_IMMUTABLE]
  15.262  ** </ul>
  15.263  **
  15.264  ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  15.265 @@ -1090,7 +1134,7 @@
  15.266  ** opcode allows these two values (10 retries and 25 milliseconds of delay)
  15.267  ** to be adjusted.  The values are changed for all database connections
  15.268  ** within the same process.  The argument is a pointer to an array of two
  15.269 -** integers where the first integer i the new retry count and the second
  15.270 +** integers where the first integer is the new retry count and the second
  15.271  ** integer is the delay.  If either integer is negative, then the setting
  15.272  ** is not changed but instead the prior value of that setting is written
  15.273  ** into the array entry, allowing the current retry settings to be
  15.274 @@ -1218,6 +1262,12 @@
  15.275  ** on whether or not the file has been renamed, moved, or deleted since it
  15.276  ** was first opened.
  15.277  **
  15.278 +** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
  15.279 +** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
  15.280 +** underlying native file handle associated with a file handle.  This file
  15.281 +** control interprets its argument as a pointer to a native file handle and
  15.282 +** writes the resulting value there.
  15.283 +**
  15.284  ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
  15.285  ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging.  This
  15.286  ** opcode causes the xFileControl method to swap the file handle with the one
  15.287 @@ -1268,6 +1318,8 @@
  15.288  #define SQLITE_FCNTL_RBU                    26
  15.289  #define SQLITE_FCNTL_VFS_POINTER            27
  15.290  #define SQLITE_FCNTL_JOURNAL_POINTER        28
  15.291 +#define SQLITE_FCNTL_WIN32_GET_HANDLE       29
  15.292 +#define SQLITE_FCNTL_PDB                    30
  15.293  
  15.294  /* deprecated names */
  15.295  #define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE
  15.296 @@ -1288,6 +1340,16 @@
  15.297  typedef struct sqlite3_mutex sqlite3_mutex;
  15.298  
  15.299  /*
  15.300 +** CAPI3REF: Loadable Extension Thunk
  15.301 +**
  15.302 +** A pointer to the opaque sqlite3_api_routines structure is passed as
  15.303 +** the third parameter to entry points of [loadable extensions].  This
  15.304 +** structure must be typedefed in order to work around compiler warnings
  15.305 +** on some platforms.
  15.306 +*/
  15.307 +typedef struct sqlite3_api_routines sqlite3_api_routines;
  15.308 +
  15.309 +/*
  15.310  ** CAPI3REF: OS Interface Object
  15.311  **
  15.312  ** An instance of the sqlite3_vfs object defines the interface between
  15.313 @@ -1622,10 +1684,10 @@
  15.314  ** must return [SQLITE_OK] on success and some other [error code] upon
  15.315  ** failure.
  15.316  */
  15.317 -SQLITE_API int SQLITE_STDCALL sqlite3_initialize(void);
  15.318 -SQLITE_API int SQLITE_STDCALL sqlite3_shutdown(void);
  15.319 -SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void);
  15.320 -SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void);
  15.321 +SQLITE_API int sqlite3_initialize(void);
  15.322 +SQLITE_API int sqlite3_shutdown(void);
  15.323 +SQLITE_API int sqlite3_os_init(void);
  15.324 +SQLITE_API int sqlite3_os_end(void);
  15.325  
  15.326  /*
  15.327  ** CAPI3REF: Configuring The SQLite Library
  15.328 @@ -1658,7 +1720,7 @@
  15.329  ** ^If the option is unknown or SQLite is unable to set the option
  15.330  ** then this routine returns a non-zero [error code].
  15.331  */
  15.332 -SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
  15.333 +SQLITE_API int sqlite3_config(int, ...);
  15.334  
  15.335  /*
  15.336  ** CAPI3REF: Configure database connections
  15.337 @@ -1677,7 +1739,7 @@
  15.338  ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
  15.339  ** the call is considered successful.
  15.340  */
  15.341 -SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3*, int op, ...);
  15.342 +SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
  15.343  
  15.344  /*
  15.345  ** CAPI3REF: Memory Allocation Routines
  15.346 @@ -2191,7 +2253,7 @@
  15.347  ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
  15.348  ** There should be two additional arguments.
  15.349  ** When the first argument to this interface is 1, then only the C-API is
  15.350 -** enabled and the SQL function remains disabled.  If the first argment to
  15.351 +** enabled and the SQL function remains disabled.  If the first argument to
  15.352  ** this interface is 0, then both the C-API and the SQL function are disabled.
  15.353  ** If the first argument is -1, then no changes are made to state of either the
  15.354  ** C-API or the SQL function.
  15.355 @@ -2201,13 +2263,36 @@
  15.356  ** be a NULL pointer, in which case the new setting is not reported back.
  15.357  ** </dd>
  15.358  **
  15.359 +** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
  15.360 +** <dd> ^This option is used to change the name of the "main" database
  15.361 +** schema.  ^The sole argument is a pointer to a constant UTF8 string
  15.362 +** which will become the new schema name in place of "main".  ^SQLite
  15.363 +** does not make a copy of the new main schema name string, so the application
  15.364 +** must ensure that the argument passed into this DBCONFIG option is unchanged
  15.365 +** until after the database connection closes.
  15.366 +** </dd>
  15.367 +**
  15.368 +** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
  15.369 +** <dd> Usually, when a database in wal mode is closed or detached from a 
  15.370 +** database handle, SQLite checks if this will mean that there are now no 
  15.371 +** connections at all to the database. If so, it performs a checkpoint 
  15.372 +** operation before closing the connection. This option may be used to
  15.373 +** override this behaviour. The first parameter passed to this operation
  15.374 +** is an integer - non-zero to disable checkpoints-on-close, or zero (the
  15.375 +** default) to enable them. The second parameter is a pointer to an integer
  15.376 +** into which is written 0 or 1 to indicate whether checkpoints-on-close
  15.377 +** have been disabled - 0 if they are not disabled, 1 if they are.
  15.378 +** </dd>
  15.379 +**
  15.380  ** </dl>
  15.381  */
  15.382 +#define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
  15.383  #define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
  15.384  #define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
  15.385  #define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
  15.386  #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
  15.387  #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
  15.388 +#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */
  15.389  
  15.390  
  15.391  /*
  15.392 @@ -2218,7 +2303,7 @@
  15.393  ** [extended result codes] feature of SQLite. ^The extended result
  15.394  ** codes are disabled by default for historical compatibility.
  15.395  */
  15.396 -SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
  15.397 +SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
  15.398  
  15.399  /*
  15.400  ** CAPI3REF: Last Insert Rowid
  15.401 @@ -2232,20 +2317,30 @@
  15.402  ** the table has a column of type [INTEGER PRIMARY KEY] then that column
  15.403  ** is another alias for the rowid.
  15.404  **
  15.405 -** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the 
  15.406 -** most recent successful [INSERT] into a rowid table or [virtual table]
  15.407 -** on database connection D.
  15.408 -** ^Inserts into [WITHOUT ROWID] tables are not recorded.
  15.409 -** ^If no successful [INSERT]s into rowid tables
  15.410 -** have ever occurred on the database connection D, 
  15.411 -** then sqlite3_last_insert_rowid(D) returns zero.
  15.412 -**
  15.413 -** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
  15.414 -** method, then this routine will return the [rowid] of the inserted
  15.415 -** row as long as the trigger or virtual table method is running.
  15.416 -** But once the trigger or virtual table method ends, the value returned 
  15.417 -** by this routine reverts to what it was before the trigger or virtual
  15.418 -** table method began.)^
  15.419 +** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
  15.420 +** the most recent successful [INSERT] into a rowid table or [virtual table]
  15.421 +** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
  15.422 +** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred 
  15.423 +** on the database connection D, then sqlite3_last_insert_rowid(D) returns 
  15.424 +** zero.
  15.425 +**
  15.426 +** As well as being set automatically as rows are inserted into database
  15.427 +** tables, the value returned by this function may be set explicitly by
  15.428 +** [sqlite3_set_last_insert_rowid()]
  15.429 +**
  15.430 +** Some virtual table implementations may INSERT rows into rowid tables as
  15.431 +** part of committing a transaction (e.g. to flush data accumulated in memory
  15.432 +** to disk). In this case subsequent calls to this function return the rowid
  15.433 +** associated with these internal INSERT operations, which leads to 
  15.434 +** unintuitive results. Virtual table implementations that do write to rowid
  15.435 +** tables in this way can avoid this problem by restoring the original 
  15.436 +** rowid value using [sqlite3_set_last_insert_rowid()] before returning 
  15.437 +** control to the user.
  15.438 +**
  15.439 +** ^(If an [INSERT] occurs within a trigger then this routine will 
  15.440 +** return the [rowid] of the inserted row as long as the trigger is 
  15.441 +** running. Once the trigger program ends, the value returned 
  15.442 +** by this routine reverts to what it was before the trigger was fired.)^
  15.443  **
  15.444  ** ^An [INSERT] that fails due to a constraint violation is not a
  15.445  ** successful [INSERT] and does not change the value returned by this
  15.446 @@ -2270,7 +2365,17 @@
  15.447  ** unpredictable and might not equal either the old or the new
  15.448  ** last insert [rowid].
  15.449  */
  15.450 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
  15.451 +SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
  15.452 +
  15.453 +/*
  15.454 +** CAPI3REF: Set the Last Insert Rowid value.
  15.455 +** METHOD: sqlite3
  15.456 +**
  15.457 +** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
  15.458 +** set the value returned by calling sqlite3_last_insert_rowid(D) to R 
  15.459 +** without inserting a row into the database.
  15.460 +*/
  15.461 +SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
  15.462  
  15.463  /*
  15.464  ** CAPI3REF: Count The Number Of Rows Modified
  15.465 @@ -2323,7 +2428,7 @@
  15.466  ** while [sqlite3_changes()] is running then the value returned
  15.467  ** is unpredictable and not meaningful.
  15.468  */
  15.469 -SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
  15.470 +SQLITE_API int sqlite3_changes(sqlite3*);
  15.471  
  15.472  /*
  15.473  ** CAPI3REF: Total Number Of Rows Modified
  15.474 @@ -2347,7 +2452,7 @@
  15.475  ** while [sqlite3_total_changes()] is running then the value
  15.476  ** returned is unpredictable and not meaningful.
  15.477  */
  15.478 -SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
  15.479 +SQLITE_API int sqlite3_total_changes(sqlite3*);
  15.480  
  15.481  /*
  15.482  ** CAPI3REF: Interrupt A Long-Running Query
  15.483 @@ -2383,11 +2488,8 @@
  15.484  ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
  15.485  ** SQL statements is a no-op and has no effect on SQL statements
  15.486  ** that are started after the sqlite3_interrupt() call returns.
  15.487 -**
  15.488 -** If the database connection closes while [sqlite3_interrupt()]
  15.489 -** is running then bad things will likely happen.
  15.490 -*/
  15.491 -SQLITE_API void SQLITE_STDCALL sqlite3_interrupt(sqlite3*);
  15.492 +*/
  15.493 +SQLITE_API void sqlite3_interrupt(sqlite3*);
  15.494  
  15.495  /*
  15.496  ** CAPI3REF: Determine If An SQL Statement Is Complete
  15.497 @@ -2422,8 +2524,8 @@
  15.498  ** The input to [sqlite3_complete16()] must be a zero-terminated
  15.499  ** UTF-16 string in native byte order.
  15.500  */
  15.501 -SQLITE_API int SQLITE_STDCALL sqlite3_complete(const char *sql);
  15.502 -SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
  15.503 +SQLITE_API int sqlite3_complete(const char *sql);
  15.504 +SQLITE_API int sqlite3_complete16(const void *sql);
  15.505  
  15.506  /*
  15.507  ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
  15.508 @@ -2484,7 +2586,7 @@
  15.509  ** A busy handler must not close the database connection
  15.510  ** or [prepared statement] that invoked the busy handler.
  15.511  */
  15.512 -SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
  15.513 +SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);
  15.514  
  15.515  /*
  15.516  ** CAPI3REF: Set A Busy Timeout
  15.517 @@ -2507,7 +2609,7 @@
  15.518  **
  15.519  ** See also:  [PRAGMA busy_timeout]
  15.520  */
  15.521 -SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
  15.522 +SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
  15.523  
  15.524  /*
  15.525  ** CAPI3REF: Convenience Routines For Running Queries
  15.526 @@ -2582,7 +2684,7 @@
  15.527  ** reflected in subsequent calls to [sqlite3_errcode()] or
  15.528  ** [sqlite3_errmsg()].
  15.529  */
  15.530 -SQLITE_API int SQLITE_STDCALL sqlite3_get_table(
  15.531 +SQLITE_API int sqlite3_get_table(
  15.532    sqlite3 *db,          /* An open database */
  15.533    const char *zSql,     /* SQL to be evaluated */
  15.534    char ***pazResult,    /* Results of the query */
  15.535 @@ -2590,7 +2692,7 @@
  15.536    int *pnColumn,        /* Number of result columns written here */
  15.537    char **pzErrmsg       /* Error msg written here */
  15.538  );
  15.539 -SQLITE_API void SQLITE_STDCALL sqlite3_free_table(char **result);
  15.540 +SQLITE_API void sqlite3_free_table(char **result);
  15.541  
  15.542  /*
  15.543  ** CAPI3REF: Formatted String Printing Functions
  15.544 @@ -2696,10 +2798,10 @@
  15.545  ** addition that after the string has been read and copied into
  15.546  ** the result, [sqlite3_free()] is called on the input string.)^
  15.547  */
  15.548 -SQLITE_API char *SQLITE_CDECL sqlite3_mprintf(const char*,...);
  15.549 -SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char*, va_list);
  15.550 -SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int,char*,const char*, ...);
  15.551 -SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int,char*,const char*, va_list);
  15.552 +SQLITE_API char *sqlite3_mprintf(const char*,...);
  15.553 +SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
  15.554 +SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
  15.555 +SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
  15.556  
  15.557  /*
  15.558  ** CAPI3REF: Memory Allocation Subsystem
  15.559 @@ -2789,12 +2891,12 @@
  15.560  ** a block of memory after it has been released using
  15.561  ** [sqlite3_free()] or [sqlite3_realloc()].
  15.562  */
  15.563 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc(int);
  15.564 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64);
  15.565 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void*, int);
  15.566 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void*, sqlite3_uint64);
  15.567 -SQLITE_API void SQLITE_STDCALL sqlite3_free(void*);
  15.568 -SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void*);
  15.569 +SQLITE_API void *sqlite3_malloc(int);
  15.570 +SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
  15.571 +SQLITE_API void *sqlite3_realloc(void*, int);
  15.572 +SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
  15.573 +SQLITE_API void sqlite3_free(void*);
  15.574 +SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
  15.575  
  15.576  /*
  15.577  ** CAPI3REF: Memory Allocator Statistics
  15.578 @@ -2819,8 +2921,8 @@
  15.579  ** by [sqlite3_memory_highwater(1)] is the high-water mark
  15.580  ** prior to the reset.
  15.581  */
  15.582 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void);
  15.583 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag);
  15.584 +SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
  15.585 +SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
  15.586  
  15.587  /*
  15.588  ** CAPI3REF: Pseudo-Random Number Generator
  15.589 @@ -2843,11 +2945,12 @@
  15.590  ** internally and without recourse to the [sqlite3_vfs] xRandomness
  15.591  ** method.
  15.592  */
  15.593 -SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
  15.594 +SQLITE_API void sqlite3_randomness(int N, void *P);
  15.595  
  15.596  /*
  15.597  ** CAPI3REF: Compile-Time Authorization Callbacks
  15.598  ** METHOD: sqlite3
  15.599 +** KEYWORDS: {authorizer callback}
  15.600  **
  15.601  ** ^This routine registers an authorizer callback with a particular
  15.602  ** [database connection], supplied in the first argument.
  15.603 @@ -2875,8 +2978,10 @@
  15.604  ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
  15.605  ** to the callback is an integer [SQLITE_COPY | action code] that specifies
  15.606  ** the particular action to be authorized. ^The third through sixth parameters
  15.607 -** to the callback are zero-terminated strings that contain additional
  15.608 -** details about the action to be authorized.
  15.609 +** to the callback are either NULL pointers or zero-terminated strings
  15.610 +** that contain additional details about the action to be authorized.
  15.611 +** Applications must always be prepared to encounter a NULL pointer in any
  15.612 +** of the third through the sixth parameters of the authorization callback.
  15.613  **
  15.614  ** ^If the action code is [SQLITE_READ]
  15.615  ** and the callback returns [SQLITE_IGNORE] then the
  15.616 @@ -2885,6 +2990,10 @@
  15.617  ** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
  15.618  ** return can be used to deny an untrusted user access to individual
  15.619  ** columns of a table.
  15.620 +** ^When a table is referenced by a [SELECT] but no column values are
  15.621 +** extracted from that table (for example in a query like
  15.622 +** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
  15.623 +** is invoked once for that table with a column name that is an empty string.
  15.624  ** ^If the action code is [SQLITE_DELETE] and the callback returns
  15.625  ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  15.626  ** [truncate optimization] is disabled and all rows are deleted individually.
  15.627 @@ -2926,7 +3035,7 @@
  15.628  ** as stated in the previous paragraph, sqlite3_step() invokes
  15.629  ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
  15.630  */
  15.631 -SQLITE_API int SQLITE_STDCALL sqlite3_set_authorizer(
  15.632 +SQLITE_API int sqlite3_set_authorizer(
  15.633    sqlite3*,
  15.634    int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  15.635    void *pUserData
  15.636 @@ -3006,6 +3115,9 @@
  15.637  ** CAPI3REF: Tracing And Profiling Functions
  15.638  ** METHOD: sqlite3
  15.639  **
  15.640 +** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
  15.641 +** instead of the routines described here.
  15.642 +**
  15.643  ** These routines register callback functions that can be used for
  15.644  ** tracing and profiling the execution of SQL statements.
  15.645  **
  15.646 @@ -3031,11 +3143,105 @@
  15.647  ** sqlite3_profile() function is considered experimental and is
  15.648  ** subject to change in future versions of SQLite.
  15.649  */
  15.650 -SQLITE_API void *SQLITE_STDCALL sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
  15.651 -SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
  15.652 +SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
  15.653 +   void(*xTrace)(void*,const char*), void*);
  15.654 +SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
  15.655     void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
  15.656  
  15.657  /*
  15.658 +** CAPI3REF: SQL Trace Event Codes
  15.659 +** KEYWORDS: SQLITE_TRACE
  15.660 +**
  15.661 +** These constants identify classes of events that can be monitored
  15.662 +** using the [sqlite3_trace_v2()] tracing logic.  The third argument
  15.663 +** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
  15.664 +** the following constants.  ^The first argument to the trace callback
  15.665 +** is one of the following constants.
  15.666 +**
  15.667 +** New tracing constants may be added in future releases.
  15.668 +**
  15.669 +** ^A trace callback has four arguments: xCallback(T,C,P,X).
  15.670 +** ^The T argument is one of the integer type codes above.
  15.671 +** ^The C argument is a copy of the context pointer passed in as the
  15.672 +** fourth argument to [sqlite3_trace_v2()].
  15.673 +** The P and X arguments are pointers whose meanings depend on T.
  15.674 +**
  15.675 +** <dl>
  15.676 +** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
  15.677 +** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
  15.678 +** first begins running and possibly at other times during the
  15.679 +** execution of the prepared statement, such as at the start of each
  15.680 +** trigger subprogram. ^The P argument is a pointer to the
  15.681 +** [prepared statement]. ^The X argument is a pointer to a string which
  15.682 +** is the unexpanded SQL text of the prepared statement or an SQL comment 
  15.683 +** that indicates the invocation of a trigger.  ^The callback can compute
  15.684 +** the same text that would have been returned by the legacy [sqlite3_trace()]
  15.685 +** interface by using the X argument when X begins with "--" and invoking
  15.686 +** [sqlite3_expanded_sql(P)] otherwise.
  15.687 +**
  15.688 +** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
  15.689 +** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
  15.690 +** information as is provided by the [sqlite3_profile()] callback.
  15.691 +** ^The P argument is a pointer to the [prepared statement] and the
  15.692 +** X argument points to a 64-bit integer which is the estimated of
  15.693 +** the number of nanosecond that the prepared statement took to run.
  15.694 +** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
  15.695 +**
  15.696 +** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
  15.697 +** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
  15.698 +** statement generates a single row of result.  
  15.699 +** ^The P argument is a pointer to the [prepared statement] and the
  15.700 +** X argument is unused.
  15.701 +**
  15.702 +** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
  15.703 +** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
  15.704 +** connection closes.
  15.705 +** ^The P argument is a pointer to the [database connection] object
  15.706 +** and the X argument is unused.
  15.707 +** </dl>
  15.708 +*/
  15.709 +#define SQLITE_TRACE_STMT       0x01
  15.710 +#define SQLITE_TRACE_PROFILE    0x02
  15.711 +#define SQLITE_TRACE_ROW        0x04
  15.712 +#define SQLITE_TRACE_CLOSE      0x08
  15.713 +
  15.714 +/*
  15.715 +** CAPI3REF: SQL Trace Hook
  15.716 +** METHOD: sqlite3
  15.717 +**
  15.718 +** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
  15.719 +** function X against [database connection] D, using property mask M
  15.720 +** and context pointer P.  ^If the X callback is
  15.721 +** NULL or if the M mask is zero, then tracing is disabled.  The
  15.722 +** M argument should be the bitwise OR-ed combination of
  15.723 +** zero or more [SQLITE_TRACE] constants.
  15.724 +**
  15.725 +** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides 
  15.726 +** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
  15.727 +**
  15.728 +** ^The X callback is invoked whenever any of the events identified by 
  15.729 +** mask M occur.  ^The integer return value from the callback is currently
  15.730 +** ignored, though this may change in future releases.  Callback
  15.731 +** implementations should return zero to ensure future compatibility.
  15.732 +**
  15.733 +** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
  15.734 +** ^The T argument is one of the [SQLITE_TRACE]
  15.735 +** constants to indicate why the callback was invoked.
  15.736 +** ^The C argument is a copy of the context pointer.
  15.737 +** The P and X arguments are pointers whose meanings depend on T.
  15.738 +**
  15.739 +** The sqlite3_trace_v2() interface is intended to replace the legacy
  15.740 +** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
  15.741 +** are deprecated.
  15.742 +*/
  15.743 +SQLITE_API int sqlite3_trace_v2(
  15.744 +  sqlite3*,
  15.745 +  unsigned uMask,
  15.746 +  int(*xCallback)(unsigned,void*,void*,void*),
  15.747 +  void *pCtx
  15.748 +);
  15.749 +
  15.750 +/*
  15.751  ** CAPI3REF: Query Progress Callbacks
  15.752  ** METHOD: sqlite3
  15.753  **
  15.754 @@ -3067,7 +3273,7 @@
  15.755  ** database connections for the meaning of "modify" in this paragraph.
  15.756  **
  15.757  */
  15.758 -SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  15.759 +SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  15.760  
  15.761  /*
  15.762  ** CAPI3REF: Opening A New Database Connection
  15.763 @@ -3296,15 +3502,15 @@
  15.764  **
  15.765  ** See also: [sqlite3_temp_directory]
  15.766  */
  15.767 -SQLITE_API int SQLITE_STDCALL sqlite3_open(
  15.768 +SQLITE_API int sqlite3_open(
  15.769    const char *filename,   /* Database filename (UTF-8) */
  15.770    sqlite3 **ppDb          /* OUT: SQLite db handle */
  15.771  );
  15.772 -SQLITE_API int SQLITE_STDCALL sqlite3_open16(
  15.773 +SQLITE_API int sqlite3_open16(
  15.774    const void *filename,   /* Database filename (UTF-16) */
  15.775    sqlite3 **ppDb          /* OUT: SQLite db handle */
  15.776  );
  15.777 -SQLITE_API int SQLITE_STDCALL sqlite3_open_v2(
  15.778 +SQLITE_API int sqlite3_open_v2(
  15.779    const char *filename,   /* Database filename (UTF-8) */
  15.780    sqlite3 **ppDb,         /* OUT: SQLite db handle */
  15.781    int flags,              /* Flags */
  15.782 @@ -3350,9 +3556,9 @@
  15.783  ** VFS method, then the behavior of this routine is undefined and probably
  15.784  ** undesirable.
  15.785  */
  15.786 -SQLITE_API const char *SQLITE_STDCALL sqlite3_uri_parameter(const char *zFilename, const char *zParam);
  15.787 -SQLITE_API int SQLITE_STDCALL sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
  15.788 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
  15.789 +SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
  15.790 +SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
  15.791 +SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
  15.792  
  15.793  
  15.794  /*
  15.795 @@ -3396,11 +3602,11 @@
  15.796  ** was invoked incorrectly by the application.  In that case, the
  15.797  ** error code and message may or may not be set.
  15.798  */
  15.799 -SQLITE_API int SQLITE_STDCALL sqlite3_errcode(sqlite3 *db);
  15.800 -SQLITE_API int SQLITE_STDCALL sqlite3_extended_errcode(sqlite3 *db);
  15.801 -SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
  15.802 -SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
  15.803 -SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
  15.804 +SQLITE_API int sqlite3_errcode(sqlite3 *db);
  15.805 +SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
  15.806 +SQLITE_API const char *sqlite3_errmsg(sqlite3*);
  15.807 +SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
  15.808 +SQLITE_API const char *sqlite3_errstr(int);
  15.809  
  15.810  /*
  15.811  ** CAPI3REF: Prepared Statement Object
  15.812 @@ -3468,7 +3674,7 @@
  15.813  **
  15.814  ** New run-time limit categories may be added in future releases.
  15.815  */
  15.816 -SQLITE_API int SQLITE_STDCALL sqlite3_limit(sqlite3*, int id, int newVal);
  15.817 +SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
  15.818  
  15.819  /*
  15.820  ** CAPI3REF: Run-Time Limit Categories
  15.821 @@ -3499,9 +3705,9 @@
  15.822  **
  15.823  ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
  15.824  ** <dd>The maximum number of instructions in a virtual machine program
  15.825 -** used to implement an SQL statement.  This limit is not currently
  15.826 -** enforced, though that might be added in some future release of
  15.827 -** SQLite.</dd>)^
  15.828 +** used to implement an SQL statement.  If [sqlite3_prepare_v2()] or
  15.829 +** the equivalent tries to allocate space for more than this many opcodes
  15.830 +** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
  15.831  **
  15.832  ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
  15.833  ** <dd>The maximum number of arguments on a function.</dd>)^
  15.834 @@ -3539,6 +3745,7 @@
  15.835  #define SQLITE_LIMIT_TRIGGER_DEPTH            10
  15.836  #define SQLITE_LIMIT_WORKER_THREADS           11
  15.837  
  15.838 +
  15.839  /*
  15.840  ** CAPI3REF: Compiling An SQL Statement
  15.841  ** KEYWORDS: {SQL statement compiler}
  15.842 @@ -3620,28 +3827,28 @@
  15.843  ** </li>
  15.844  ** </ol>
  15.845  */
  15.846 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare(
  15.847 +SQLITE_API int sqlite3_prepare(
  15.848    sqlite3 *db,            /* Database handle */
  15.849    const char *zSql,       /* SQL statement, UTF-8 encoded */
  15.850    int nByte,              /* Maximum length of zSql in bytes. */
  15.851    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  15.852    const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  15.853  );
  15.854 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare_v2(
  15.855 +SQLITE_API int sqlite3_prepare_v2(
  15.856    sqlite3 *db,            /* Database handle */
  15.857    const char *zSql,       /* SQL statement, UTF-8 encoded */
  15.858    int nByte,              /* Maximum length of zSql in bytes. */
  15.859    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  15.860    const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  15.861  );
  15.862 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare16(
  15.863 +SQLITE_API int sqlite3_prepare16(
  15.864    sqlite3 *db,            /* Database handle */
  15.865    const void *zSql,       /* SQL statement, UTF-16 encoded */
  15.866    int nByte,              /* Maximum length of zSql in bytes. */
  15.867    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  15.868    const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  15.869  );
  15.870 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare16_v2(
  15.871 +SQLITE_API int sqlite3_prepare16_v2(
  15.872    sqlite3 *db,            /* Database handle */
  15.873    const void *zSql,       /* SQL statement, UTF-16 encoded */
  15.874    int nByte,              /* Maximum length of zSql in bytes. */
  15.875 @@ -3653,11 +3860,35 @@
  15.876  ** CAPI3REF: Retrieving Statement SQL
  15.877  ** METHOD: sqlite3_stmt
  15.878  **
  15.879 -** ^This interface can be used to retrieve a saved copy of the original
  15.880 -** SQL text used to create a [prepared statement] if that statement was
  15.881 -** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  15.882 -*/
  15.883 -SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
  15.884 +** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
  15.885 +** SQL text used to create [prepared statement] P if P was
  15.886 +** created by either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  15.887 +** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
  15.888 +** string containing the SQL text of prepared statement P with
  15.889 +** [bound parameters] expanded.
  15.890 +**
  15.891 +** ^(For example, if a prepared statement is created using the SQL
  15.892 +** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
  15.893 +** and parameter :xyz is unbound, then sqlite3_sql() will return
  15.894 +** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
  15.895 +** will return "SELECT 2345,NULL".)^
  15.896 +**
  15.897 +** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
  15.898 +** is available to hold the result, or if the result would exceed the
  15.899 +** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
  15.900 +**
  15.901 +** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
  15.902 +** bound parameter expansions.  ^The [SQLITE_OMIT_TRACE] compile-time
  15.903 +** option causes sqlite3_expanded_sql() to always return NULL.
  15.904 +**
  15.905 +** ^The string returned by sqlite3_sql(P) is managed by SQLite and is
  15.906 +** automatically freed when the prepared statement is finalized.
  15.907 +** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
  15.908 +** is obtained from [sqlite3_malloc()] and must be free by the application
  15.909 +** by passing it to [sqlite3_free()].
  15.910 +*/
  15.911 +SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
  15.912 +SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
  15.913  
  15.914  /*
  15.915  ** CAPI3REF: Determine If An SQL Statement Writes The Database
  15.916 @@ -3688,8 +3919,12 @@
  15.917  ** sqlite3_stmt_readonly() to return true since, while those statements
  15.918  ** change the configuration of a database connection, they do not make 
  15.919  ** changes to the content of the database files on disk.
  15.920 -*/
  15.921 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  15.922 +** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
  15.923 +** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
  15.924 +** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
  15.925 +** sqlite3_stmt_readonly() returns false for those commands.
  15.926 +*/
  15.927 +SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  15.928  
  15.929  /*
  15.930  ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  15.931 @@ -3710,7 +3945,7 @@
  15.932  ** for example, in diagnostic routines to search for prepared 
  15.933  ** statements that are holding a transaction open.
  15.934  */
  15.935 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_busy(sqlite3_stmt*);
  15.936 +SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
  15.937  
  15.938  /*
  15.939  ** CAPI3REF: Dynamically Typed Value Object
  15.940 @@ -3751,7 +3986,7 @@
  15.941  ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  15.942  ** interfaces require protected sqlite3_value objects.
  15.943  */
  15.944 -typedef struct Mem sqlite3_value;
  15.945 +typedef struct sqlite3_value sqlite3_value;
  15.946  
  15.947  /*
  15.948  ** CAPI3REF: SQL Function Context Object
  15.949 @@ -3874,20 +4109,20 @@
  15.950  ** See also: [sqlite3_bind_parameter_count()],
  15.951  ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
  15.952  */
  15.953 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  15.954 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
  15.955 +SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  15.956 +SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
  15.957                          void(*)(void*));
  15.958 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_double(sqlite3_stmt*, int, double);
  15.959 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_int(sqlite3_stmt*, int, int);
  15.960 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  15.961 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_null(sqlite3_stmt*, int);
  15.962 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
  15.963 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  15.964 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
  15.965 +SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
  15.966 +SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
  15.967 +SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  15.968 +SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
  15.969 +SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
  15.970 +SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  15.971 +SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
  15.972                           void(*)(void*), unsigned char encoding);
  15.973 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  15.974 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  15.975 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
  15.976 +SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  15.977 +SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  15.978 +SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
  15.979  
  15.980  /*
  15.981  ** CAPI3REF: Number Of SQL Parameters
  15.982 @@ -3908,7 +4143,7 @@
  15.983  ** [sqlite3_bind_parameter_name()], and
  15.984  ** [sqlite3_bind_parameter_index()].
  15.985  */
  15.986 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
  15.987 +SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
  15.988  
  15.989  /*
  15.990  ** CAPI3REF: Name Of A Host Parameter
  15.991 @@ -3936,7 +4171,7 @@
  15.992  ** [sqlite3_bind_parameter_count()], and
  15.993  ** [sqlite3_bind_parameter_index()].
  15.994  */
  15.995 -SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  15.996 +SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  15.997  
  15.998  /*
  15.999  ** CAPI3REF: Index Of A Parameter With A Given Name
 15.1000 @@ -3953,7 +4188,7 @@
 15.1001  ** [sqlite3_bind_parameter_count()], and
 15.1002  ** [sqlite3_bind_parameter_name()].
 15.1003  */
 15.1004 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
 15.1005 +SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
 15.1006  
 15.1007  /*
 15.1008  ** CAPI3REF: Reset All Bindings On A Prepared Statement
 15.1009 @@ -3963,19 +4198,23 @@
 15.1010  ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
 15.1011  ** ^Use this routine to reset all host parameters to NULL.
 15.1012  */
 15.1013 -SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
 15.1014 +SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
 15.1015  
 15.1016  /*
 15.1017  ** CAPI3REF: Number Of Columns In A Result Set
 15.1018  ** METHOD: sqlite3_stmt
 15.1019  **
 15.1020  ** ^Return the number of columns in the result set returned by the
 15.1021 -** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
 15.1022 -** statement that does not return data (for example an [UPDATE]).
 15.1023 +** [prepared statement]. ^If this routine returns 0, that means the 
 15.1024 +** [prepared statement] returns no data (for example an [UPDATE]).
 15.1025 +** ^However, just because this routine returns a positive number does not
 15.1026 +** mean that one or more rows of data will be returned.  ^A SELECT statement
 15.1027 +** will always have a positive sqlite3_column_count() but depending on the
 15.1028 +** WHERE clause constraints and the table content, it might return no rows.
 15.1029  **
 15.1030  ** See also: [sqlite3_data_count()]
 15.1031  */
 15.1032 -SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
 15.1033 +SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
 15.1034  
 15.1035  /*
 15.1036  ** CAPI3REF: Column Names In A Result Set
 15.1037 @@ -4004,8 +4243,8 @@
 15.1038  ** then the name of the column is unspecified and may change from
 15.1039  ** one release of SQLite to the next.
 15.1040  */
 15.1041 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
 15.1042 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
 15.1043 +SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
 15.1044 +SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
 15.1045  
 15.1046  /*
 15.1047  ** CAPI3REF: Source Of Data In A Query Result
 15.1048 @@ -4053,12 +4292,12 @@
 15.1049  ** for the same [prepared statement] and result column
 15.1050  ** at the same time then the results are undefined.
 15.1051  */
 15.1052 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_database_name(sqlite3_stmt*,int);
 15.1053 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_database_name16(sqlite3_stmt*,int);
 15.1054 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_table_name(sqlite3_stmt*,int);
 15.1055 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_table_name16(sqlite3_stmt*,int);
 15.1056 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
 15.1057 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
 15.1058 +SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
 15.1059 +SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
 15.1060 +SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
 15.1061 +SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
 15.1062 +SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
 15.1063 +SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
 15.1064  
 15.1065  /*
 15.1066  ** CAPI3REF: Declared Datatype Of A Query Result
 15.1067 @@ -4090,8 +4329,8 @@
 15.1068  ** is associated with individual values, not with the containers
 15.1069  ** used to hold those values.
 15.1070  */
 15.1071 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
 15.1072 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
 15.1073 +SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
 15.1074 +SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
 15.1075  
 15.1076  /*
 15.1077  ** CAPI3REF: Evaluate An SQL Statement
 15.1078 @@ -4152,7 +4391,8 @@
 15.1079  ** other than [SQLITE_ROW] before any subsequent invocation of
 15.1080  ** sqlite3_step().  Failure to reset the prepared statement using 
 15.1081  ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
 15.1082 -** sqlite3_step().  But after version 3.6.23.1, sqlite3_step() began
 15.1083 +** sqlite3_step().  But after [version 3.6.23.1] ([dateof:3.6.23.1],
 15.1084 +** sqlite3_step() began
 15.1085  ** calling [sqlite3_reset()] automatically in this circumstance rather
 15.1086  ** than returning [SQLITE_MISUSE].  This is not considered a compatibility
 15.1087  ** break because any application that ever receives an SQLITE_MISUSE error
 15.1088 @@ -4171,7 +4411,7 @@
 15.1089  ** then the more specific [error codes] are returned directly
 15.1090  ** by sqlite3_step().  The use of the "v2" interface is recommended.
 15.1091  */
 15.1092 -SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
 15.1093 +SQLITE_API int sqlite3_step(sqlite3_stmt*);
 15.1094  
 15.1095  /*
 15.1096  ** CAPI3REF: Number of columns in a result set
 15.1097 @@ -4192,7 +4432,7 @@
 15.1098  **
 15.1099  ** See also: [sqlite3_column_count()]
 15.1100  */
 15.1101 -SQLITE_API int SQLITE_STDCALL sqlite3_data_count(sqlite3_stmt *pStmt);
 15.1102 +SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
 15.1103  
 15.1104  /*
 15.1105  ** CAPI3REF: Fundamental Datatypes
 15.1106 @@ -4382,16 +4622,16 @@
 15.1107  ** pointer.  Subsequent calls to [sqlite3_errcode()] will return
 15.1108  ** [SQLITE_NOMEM].)^
 15.1109  */
 15.1110 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_blob(sqlite3_stmt*, int iCol);
 15.1111 -SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes(sqlite3_stmt*, int iCol);
 15.1112 -SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
 15.1113 -SQLITE_API double SQLITE_STDCALL sqlite3_column_double(sqlite3_stmt*, int iCol);
 15.1114 -SQLITE_API int SQLITE_STDCALL sqlite3_column_int(sqlite3_stmt*, int iCol);
 15.1115 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_column_int64(sqlite3_stmt*, int iCol);
 15.1116 -SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_column_text(sqlite3_stmt*, int iCol);
 15.1117 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_text16(sqlite3_stmt*, int iCol);
 15.1118 -SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
 15.1119 -SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
 15.1120 +SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
 15.1121 +SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
 15.1122 +SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
 15.1123 +SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
 15.1124 +SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
 15.1125 +SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
 15.1126 +SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
 15.1127 +SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
 15.1128 +SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
 15.1129 +SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
 15.1130  
 15.1131  /*
 15.1132  ** CAPI3REF: Destroy A Prepared Statement Object
 15.1133 @@ -4419,7 +4659,7 @@
 15.1134  ** statement after it has been finalized can result in undefined and
 15.1135  ** undesirable behavior such as segfaults and heap corruption.
 15.1136  */
 15.1137 -SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
 15.1138 +SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
 15.1139  
 15.1140  /*
 15.1141  ** CAPI3REF: Reset A Prepared Statement Object
 15.1142 @@ -4446,7 +4686,7 @@
 15.1143  ** ^The [sqlite3_reset(S)] interface does not change the values
 15.1144  ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
 15.1145  */
 15.1146 -SQLITE_API int SQLITE_STDCALL sqlite3_reset(sqlite3_stmt *pStmt);
 15.1147 +SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
 15.1148  
 15.1149  /*
 15.1150  ** CAPI3REF: Create Or Redefine SQL Functions
 15.1151 @@ -4546,7 +4786,7 @@
 15.1152  ** close the database connection nor finalize or reset the prepared
 15.1153  ** statement in which the function is running.
 15.1154  */
 15.1155 -SQLITE_API int SQLITE_STDCALL sqlite3_create_function(
 15.1156 +SQLITE_API int sqlite3_create_function(
 15.1157    sqlite3 *db,
 15.1158    const char *zFunctionName,
 15.1159    int nArg,
 15.1160 @@ -4556,7 +4796,7 @@
 15.1161    void (*xStep)(sqlite3_context*,int,sqlite3_value**),
 15.1162    void (*xFinal)(sqlite3_context*)
 15.1163  );
 15.1164 -SQLITE_API int SQLITE_STDCALL sqlite3_create_function16(
 15.1165 +SQLITE_API int sqlite3_create_function16(
 15.1166    sqlite3 *db,
 15.1167    const void *zFunctionName,
 15.1168    int nArg,
 15.1169 @@ -4566,7 +4806,7 @@
 15.1170    void (*xStep)(sqlite3_context*,int,sqlite3_value**),
 15.1171    void (*xFinal)(sqlite3_context*)
 15.1172  );
 15.1173 -SQLITE_API int SQLITE_STDCALL sqlite3_create_function_v2(
 15.1174 +SQLITE_API int sqlite3_create_function_v2(
 15.1175    sqlite3 *db,
 15.1176    const char *zFunctionName,
 15.1177    int nArg,
 15.1178 @@ -4612,12 +4852,12 @@
 15.1179  ** these functions, we will not explain what they do.
 15.1180  */
 15.1181  #ifndef SQLITE_OMIT_DEPRECATED
 15.1182 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_aggregate_count(sqlite3_context*);
 15.1183 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_expired(sqlite3_stmt*);
 15.1184 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
 15.1185 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_global_recover(void);
 15.1186 -SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_thread_cleanup(void);
 15.1187 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
 15.1188 +SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
 15.1189 +SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
 15.1190 +SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
 15.1191 +SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
 15.1192 +SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
 15.1193 +SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
 15.1194                        void*,sqlite3_int64);
 15.1195  #endif
 15.1196  
 15.1197 @@ -4667,18 +4907,18 @@
 15.1198  ** These routines must be called from the same thread as
 15.1199  ** the SQL function that supplied the [sqlite3_value*] parameters.
 15.1200  */
 15.1201 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_blob(sqlite3_value*);
 15.1202 -SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes(sqlite3_value*);
 15.1203 -SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes16(sqlite3_value*);
 15.1204 -SQLITE_API double SQLITE_STDCALL sqlite3_value_double(sqlite3_value*);
 15.1205 -SQLITE_API int SQLITE_STDCALL sqlite3_value_int(sqlite3_value*);
 15.1206 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_value_int64(sqlite3_value*);
 15.1207 -SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_value_text(sqlite3_value*);
 15.1208 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16(sqlite3_value*);
 15.1209 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*);
 15.1210 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*);
 15.1211 -SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
 15.1212 -SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
 15.1213 +SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
 15.1214 +SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
 15.1215 +SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
 15.1216 +SQLITE_API double sqlite3_value_double(sqlite3_value*);
 15.1217 +SQLITE_API int sqlite3_value_int(sqlite3_value*);
 15.1218 +SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
 15.1219 +SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
 15.1220 +SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
 15.1221 +SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
 15.1222 +SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
 15.1223 +SQLITE_API int sqlite3_value_type(sqlite3_value*);
 15.1224 +SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
 15.1225  
 15.1226  /*
 15.1227  ** CAPI3REF: Finding The Subtype Of SQL Values
 15.1228 @@ -4694,7 +4934,7 @@
 15.1229  ** from the result of one [application-defined SQL function] into the
 15.1230  ** input of another.
 15.1231  */
 15.1232 -SQLITE_API unsigned int SQLITE_STDCALL sqlite3_value_subtype(sqlite3_value*);
 15.1233 +SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);
 15.1234  
 15.1235  /*
 15.1236  ** CAPI3REF: Copy And Free SQL Values
 15.1237 @@ -4710,8 +4950,8 @@
 15.1238  ** previously obtained from [sqlite3_value_dup()].  ^If V is a NULL pointer
 15.1239  ** then sqlite3_value_free(V) is a harmless no-op.
 15.1240  */
 15.1241 -SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_value_dup(const sqlite3_value*);
 15.1242 -SQLITE_API void SQLITE_STDCALL sqlite3_value_free(sqlite3_value*);
 15.1243 +SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*);
 15.1244 +SQLITE_API void sqlite3_value_free(sqlite3_value*);
 15.1245  
 15.1246  /*
 15.1247  ** CAPI3REF: Obtain Aggregate Function Context
 15.1248 @@ -4756,7 +4996,7 @@
 15.1249  ** This routine must be called from the same thread in which
 15.1250  ** the aggregate SQL function is running.
 15.1251  */
 15.1252 -SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
 15.1253 +SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
 15.1254  
 15.1255  /*
 15.1256  ** CAPI3REF: User Data For Functions
 15.1257 @@ -4771,7 +5011,7 @@
 15.1258  ** This routine must be called from the same thread in which
 15.1259  ** the application-defined function is running.
 15.1260  */
 15.1261 -SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
 15.1262 +SQLITE_API void *sqlite3_user_data(sqlite3_context*);
 15.1263  
 15.1264  /*
 15.1265  ** CAPI3REF: Database Connection For Functions
 15.1266 @@ -4783,7 +5023,7 @@
 15.1267  ** and [sqlite3_create_function16()] routines that originally
 15.1268  ** registered the application defined function.
 15.1269  */
 15.1270 -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
 15.1271 +SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
 15.1272  
 15.1273  /*
 15.1274  ** CAPI3REF: Function Auxiliary Data
 15.1275 @@ -4800,10 +5040,11 @@
 15.1276  ** the compiled regular expression can be reused on multiple
 15.1277  ** invocations of the same function.
 15.1278  **
 15.1279 -** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
 15.1280 -** associated by the sqlite3_set_auxdata() function with the Nth argument
 15.1281 -** value to the application-defined function. ^If there is no metadata
 15.1282 -** associated with the function argument, this sqlite3_get_auxdata() interface
 15.1283 +** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
 15.1284 +** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
 15.1285 +** value to the application-defined function.  ^N is zero for the left-most
 15.1286 +** function argument.  ^If there is no metadata
 15.1287 +** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
 15.1288  ** returns a NULL pointer.
 15.1289  **
 15.1290  ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
 15.1291 @@ -4815,12 +5056,13 @@
 15.1292  ** SQLite will invoke the destructor function X with parameter P exactly
 15.1293  ** once, when the metadata is discarded.
 15.1294  ** SQLite is free to discard the metadata at any time, including: <ul>
 15.1295 -** <li> when the corresponding function parameter changes, or
 15.1296 -** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
 15.1297 -**      SQL statement, or
 15.1298 -** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
 15.1299 -** <li> during the original sqlite3_set_auxdata() call when a memory 
 15.1300 -**      allocation error occurs. </ul>)^
 15.1301 +** <li> ^(when the corresponding function parameter changes)^, or
 15.1302 +** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
 15.1303 +**      SQL statement)^, or
 15.1304 +** <li> ^(when sqlite3_set_auxdata() is invoked again on the same
 15.1305 +**       parameter)^, or
 15.1306 +** <li> ^(during the original sqlite3_set_auxdata() call when a memory 
 15.1307 +**      allocation error occurs.)^ </ul>
 15.1308  **
 15.1309  ** Note the last bullet in particular.  The destructor X in 
 15.1310  ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
 15.1311 @@ -4833,11 +5075,15 @@
 15.1312  ** function parameters that are compile-time constants, including literal
 15.1313  ** values and [parameters] and expressions composed from the same.)^
 15.1314  **
 15.1315 +** The value of the N parameter to these interfaces should be non-negative.
 15.1316 +** Future enhancements may make use of negative N values to define new
 15.1317 +** kinds of function caching behavior.
 15.1318 +**
 15.1319  ** These routines must be called from the same thread in which
 15.1320  ** the SQL function is running.
 15.1321  */
 15.1322 -SQLITE_API void *SQLITE_STDCALL sqlite3_get_auxdata(sqlite3_context*, int N);
 15.1323 -SQLITE_API void SQLITE_STDCALL sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
 15.1324 +SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
 15.1325 +SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
 15.1326  
 15.1327  
 15.1328  /*
 15.1329 @@ -4973,27 +5219,27 @@
 15.1330  ** than the one containing the application-defined function that received
 15.1331  ** the [sqlite3_context] pointer, the results are undefined.
 15.1332  */
 15.1333 -SQLITE_API void SQLITE_STDCALL sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
 15.1334 -SQLITE_API void SQLITE_STDCALL sqlite3_result_blob64(sqlite3_context*,const void*,
 15.1335 +SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
 15.1336 +SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
 15.1337                             sqlite3_uint64,void(*)(void*));
 15.1338 -SQLITE_API void SQLITE_STDCALL sqlite3_result_double(sqlite3_context*, double);
 15.1339 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error(sqlite3_context*, const char*, int);
 15.1340 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error16(sqlite3_context*, const void*, int);
 15.1341 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_toobig(sqlite3_context*);
 15.1342 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_nomem(sqlite3_context*);
 15.1343 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_code(sqlite3_context*, int);
 15.1344 -SQLITE_API void SQLITE_STDCALL sqlite3_result_int(sqlite3_context*, int);
 15.1345 -SQLITE_API void SQLITE_STDCALL sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
 15.1346 -SQLITE_API void SQLITE_STDCALL sqlite3_result_null(sqlite3_context*);
 15.1347 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
 15.1348 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
 15.1349 +SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
 15.1350 +SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
 15.1351 +SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
 15.1352 +SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
 15.1353 +SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
 15.1354 +SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
 15.1355 +SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
 15.1356 +SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
 15.1357 +SQLITE_API void sqlite3_result_null(sqlite3_context*);
 15.1358 +SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
 15.1359 +SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
 15.1360                             void(*)(void*), unsigned char encoding);
 15.1361 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
 15.1362 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
 15.1363 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
 15.1364 -SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
 15.1365 -SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
 15.1366 -SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
 15.1367 +SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
 15.1368 +SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
 15.1369 +SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
 15.1370 +SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
 15.1371 +SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
 15.1372 +SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
 15.1373  
 15.1374  
 15.1375  /*
 15.1376 @@ -5008,7 +5254,7 @@
 15.1377  ** The number of subtype bytes preserved by SQLite might increase
 15.1378  ** in future releases of SQLite.
 15.1379  */
 15.1380 -SQLITE_API void SQLITE_STDCALL sqlite3_result_subtype(sqlite3_context*,unsigned int);
 15.1381 +SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int);
 15.1382  
 15.1383  /*
 15.1384  ** CAPI3REF: Define New Collating Sequences
 15.1385 @@ -5090,14 +5336,14 @@
 15.1386  **
 15.1387  ** See also:  [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
 15.1388  */
 15.1389 -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation(
 15.1390 +SQLITE_API int sqlite3_create_collation(
 15.1391    sqlite3*, 
 15.1392    const char *zName, 
 15.1393    int eTextRep, 
 15.1394    void *pArg,
 15.1395    int(*xCompare)(void*,int,const void*,int,const void*)
 15.1396  );
 15.1397 -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation_v2(
 15.1398 +SQLITE_API int sqlite3_create_collation_v2(
 15.1399    sqlite3*, 
 15.1400    const char *zName, 
 15.1401    int eTextRep, 
 15.1402 @@ -5105,7 +5351,7 @@
 15.1403    int(*xCompare)(void*,int,const void*,int,const void*),
 15.1404    void(*xDestroy)(void*)
 15.1405  );
 15.1406 -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation16(
 15.1407 +SQLITE_API int sqlite3_create_collation16(
 15.1408    sqlite3*, 
 15.1409    const void *zName,
 15.1410    int eTextRep, 
 15.1411 @@ -5140,12 +5386,12 @@
 15.1412  ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
 15.1413  ** [sqlite3_create_collation_v2()].
 15.1414  */
 15.1415 -SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed(
 15.1416 +SQLITE_API int sqlite3_collation_needed(
 15.1417    sqlite3*, 
 15.1418    void*, 
 15.1419    void(*)(void*,sqlite3*,int eTextRep,const char*)
 15.1420  );
 15.1421 -SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed16(
 15.1422 +SQLITE_API int sqlite3_collation_needed16(
 15.1423    sqlite3*, 
 15.1424    void*,
 15.1425    void(*)(void*,sqlite3*,int eTextRep,const void*)
 15.1426 @@ -5159,11 +5405,11 @@
 15.1427  ** The code to implement this API is not available in the public release
 15.1428  ** of SQLite.
 15.1429  */
 15.1430 -SQLITE_API int SQLITE_STDCALL sqlite3_key(
 15.1431 +SQLITE_API int sqlite3_key(
 15.1432    sqlite3 *db,                   /* Database to be rekeyed */
 15.1433    const void *pKey, int nKey     /* The key */
 15.1434  );
 15.1435 -SQLITE_API int SQLITE_STDCALL sqlite3_key_v2(
 15.1436 +SQLITE_API int sqlite3_key_v2(
 15.1437    sqlite3 *db,                   /* Database to be rekeyed */
 15.1438    const char *zDbName,           /* Name of the database */
 15.1439    const void *pKey, int nKey     /* The key */
 15.1440 @@ -5177,11 +5423,11 @@
 15.1441  ** The code to implement this API is not available in the public release
 15.1442  ** of SQLite.
 15.1443  */
 15.1444 -SQLITE_API int SQLITE_STDCALL sqlite3_rekey(
 15.1445 +SQLITE_API int sqlite3_rekey(
 15.1446    sqlite3 *db,                   /* Database to be rekeyed */
 15.1447    const void *pKey, int nKey     /* The new key */
 15.1448  );
 15.1449 -SQLITE_API int SQLITE_STDCALL sqlite3_rekey_v2(
 15.1450 +SQLITE_API int sqlite3_rekey_v2(
 15.1451    sqlite3 *db,                   /* Database to be rekeyed */
 15.1452    const char *zDbName,           /* Name of the database */
 15.1453    const void *pKey, int nKey     /* The new key */
 15.1454 @@ -5191,7 +5437,7 @@
 15.1455  ** Specify the activation key for a SEE database.  Unless 
 15.1456  ** activated, none of the SEE routines will work.
 15.1457  */
 15.1458 -SQLITE_API void SQLITE_STDCALL sqlite3_activate_see(
 15.1459 +SQLITE_API void sqlite3_activate_see(
 15.1460    const char *zPassPhrase        /* Activation phrase */
 15.1461  );
 15.1462  #endif
 15.1463 @@ -5201,7 +5447,7 @@
 15.1464  ** Specify the activation key for a CEROD database.  Unless 
 15.1465  ** activated, none of the CEROD routines will work.
 15.1466  */
 15.1467 -SQLITE_API void SQLITE_STDCALL sqlite3_activate_cerod(
 15.1468 +SQLITE_API void sqlite3_activate_cerod(
 15.1469    const char *zPassPhrase        /* Activation phrase */
 15.1470  );
 15.1471  #endif
 15.1472 @@ -5223,7 +5469,7 @@
 15.1473  ** all, then the behavior of sqlite3_sleep() may deviate from the description
 15.1474  ** in the previous paragraphs.
 15.1475  */
 15.1476 -SQLITE_API int SQLITE_STDCALL sqlite3_sleep(int);
 15.1477 +SQLITE_API int sqlite3_sleep(int);
 15.1478  
 15.1479  /*
 15.1480  ** CAPI3REF: Name Of The Folder Holding Temporary Files
 15.1481 @@ -5342,7 +5588,7 @@
 15.1482  ** connection while this routine is running, then the return value
 15.1483  ** is undefined.
 15.1484  */
 15.1485 -SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
 15.1486 +SQLITE_API int sqlite3_get_autocommit(sqlite3*);
 15.1487  
 15.1488  /*
 15.1489  ** CAPI3REF: Find The Database Handle Of A Prepared Statement
 15.1490 @@ -5355,7 +5601,7 @@
 15.1491  ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
 15.1492  ** create the statement in the first place.
 15.1493  */
 15.1494 -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
 15.1495 +SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
 15.1496  
 15.1497  /*
 15.1498  ** CAPI3REF: Return The Filename For A Database Connection
 15.1499 @@ -5372,7 +5618,7 @@
 15.1500  ** will be an absolute pathname, even if the filename used
 15.1501  ** to open the database originally was a URI or relative pathname.
 15.1502  */
 15.1503 -SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
 15.1504 +SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
 15.1505  
 15.1506  /*
 15.1507  ** CAPI3REF: Determine if a database is read-only
 15.1508 @@ -5382,7 +5628,7 @@
 15.1509  ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
 15.1510  ** the name of a database on connection D.
 15.1511  */
 15.1512 -SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
 15.1513 +SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
 15.1514  
 15.1515  /*
 15.1516  ** CAPI3REF: Find the next prepared statement
 15.1517 @@ -5398,7 +5644,7 @@
 15.1518  ** [sqlite3_next_stmt(D,S)] must refer to an open database
 15.1519  ** connection and in particular must not be a NULL pointer.
 15.1520  */
 15.1521 -SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
 15.1522 +SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
 15.1523  
 15.1524  /*
 15.1525  ** CAPI3REF: Commit And Rollback Notification Callbacks
 15.1526 @@ -5447,8 +5693,8 @@
 15.1527  **
 15.1528  ** See also the [sqlite3_update_hook()] interface.
 15.1529  */
 15.1530 -SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
 15.1531 -SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
 15.1532 +SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
 15.1533 +SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
 15.1534  
 15.1535  /*
 15.1536  ** CAPI3REF: Data Change Notification Callbacks
 15.1537 @@ -5478,7 +5724,7 @@
 15.1538  ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
 15.1539  **
 15.1540  ** ^In the current implementation, the update hook
 15.1541 -** is not invoked when duplication rows are deleted because of an
 15.1542 +** is not invoked when conflicting rows are deleted because of an
 15.1543  ** [ON CONFLICT | ON CONFLICT REPLACE] clause.  ^Nor is the update hook
 15.1544  ** invoked when rows are deleted using the [truncate optimization].
 15.1545  ** The exceptions defined in this paragraph might change in a future
 15.1546 @@ -5499,7 +5745,7 @@
 15.1547  ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
 15.1548  ** and [sqlite3_preupdate_hook()] interfaces.
 15.1549  */
 15.1550 -SQLITE_API void *SQLITE_STDCALL sqlite3_update_hook(
 15.1551 +SQLITE_API void *sqlite3_update_hook(
 15.1552    sqlite3*, 
 15.1553    void(*)(void *,int ,char const *,char const *,sqlite3_int64),
 15.1554    void*
 15.1555 @@ -5514,7 +5760,8 @@
 15.1556  ** and disabled if the argument is false.)^
 15.1557  **
 15.1558  ** ^Cache sharing is enabled and disabled for an entire process.
 15.1559 -** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
 15.1560 +** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]). 
 15.1561 +** In prior versions of SQLite,
 15.1562  ** sharing was enabled or disabled for each thread separately.
 15.1563  **
 15.1564  ** ^(The cache sharing mode set by this interface effects all subsequent
 15.1565 @@ -5539,7 +5786,7 @@
 15.1566  **
 15.1567  ** See Also:  [SQLite Shared-Cache Mode]
 15.1568  */
 15.1569 -SQLITE_API int SQLITE_STDCALL sqlite3_enable_shared_cache(int);
 15.1570 +SQLITE_API int sqlite3_enable_shared_cache(int);
 15.1571  
 15.1572  /*
 15.1573  ** CAPI3REF: Attempt To Free Heap Memory
 15.1574 @@ -5555,7 +5802,7 @@
 15.1575  **
 15.1576  ** See also: [sqlite3_db_release_memory()]
 15.1577  */
 15.1578 -SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
 15.1579 +SQLITE_API int sqlite3_release_memory(int);
 15.1580  
 15.1581  /*
 15.1582  ** CAPI3REF: Free Memory Used By A Database Connection
 15.1583 @@ -5569,7 +5816,7 @@
 15.1584  **
 15.1585  ** See also: [sqlite3_release_memory()]
 15.1586  */
 15.1587 -SQLITE_API int SQLITE_STDCALL sqlite3_db_release_memory(sqlite3*);
 15.1588 +SQLITE_API int sqlite3_db_release_memory(sqlite3*);
 15.1589  
 15.1590  /*
 15.1591  ** CAPI3REF: Impose A Limit On Heap Size
 15.1592 @@ -5608,7 +5855,8 @@
 15.1593  **      from the heap.
 15.1594  ** </ul>)^
 15.1595  **
 15.1596 -** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
 15.1597 +** Beginning with SQLite [version 3.7.3] ([dateof:3.7.3]), 
 15.1598 +** the soft heap limit is enforced
 15.1599  ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
 15.1600  ** compile-time option is invoked.  With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
 15.1601  ** the soft heap limit is enforced on every memory allocation.  Without
 15.1602 @@ -5621,7 +5869,7 @@
 15.1603  ** The circumstances under which SQLite will enforce the soft heap limit may
 15.1604  ** changes in future releases of SQLite.
 15.1605  */
 15.1606 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 N);
 15.1607 +SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
 15.1608  
 15.1609  /*
 15.1610  ** CAPI3REF: Deprecated Soft Heap Limit Interface
 15.1611 @@ -5632,7 +5880,7 @@
 15.1612  ** only.  All new applications should use the
 15.1613  ** [sqlite3_soft_heap_limit64()] interface rather than this one.
 15.1614  */
 15.1615 -SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
 15.1616 +SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
 15.1617  
 15.1618  
 15.1619  /*
 15.1620 @@ -5647,7 +5895,7 @@
 15.1621  ** column exists.  ^The sqlite3_table_column_metadata() interface returns
 15.1622  ** SQLITE_ERROR and if the specified column does not exist.
 15.1623  ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
 15.1624 -** NULL pointer, then this routine simply checks for the existance of the
 15.1625 +** NULL pointer, then this routine simply checks for the existence of the
 15.1626  ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
 15.1627  ** does not.
 15.1628  **
 15.1629 @@ -5702,7 +5950,7 @@
 15.1630  ** parsed, if that has not already been done, and returns an error if
 15.1631  ** any errors are encountered while loading the schema.
 15.1632  */
 15.1633 -SQLITE_API int SQLITE_STDCALL sqlite3_table_column_metadata(
 15.1634 +SQLITE_API int sqlite3_table_column_metadata(
 15.1635    sqlite3 *db,                /* Connection handle */
 15.1636    const char *zDbName,        /* Database name or NULL */
 15.1637    const char *zTableName,     /* Table name */
 15.1638 @@ -5758,7 +6006,7 @@
 15.1639  **
 15.1640  ** See also the [load_extension() SQL function].
 15.1641  */
 15.1642 -SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
 15.1643 +SQLITE_API int sqlite3_load_extension(
 15.1644    sqlite3 *db,          /* Load the extension into this database connection */
 15.1645    const char *zFile,    /* Name of the shared library containing extension */
 15.1646    const char *zProc,    /* Entry point.  Derived from zFile if 0 */
 15.1647 @@ -5781,8 +6029,8 @@
 15.1648  **
 15.1649  ** ^This interface enables or disables both the C-API
 15.1650  ** [sqlite3_load_extension()] and the SQL function [load_extension()].
 15.1651 -** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
 15.1652 -** to enable or disable only the C-API.
 15.1653 +** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
 15.1654 +** to enable or disable only the C-API.)^
 15.1655  **
 15.1656  ** <b>Security warning:</b> It is recommended that extension loading
 15.1657  ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
 15.1658 @@ -5790,7 +6038,7 @@
 15.1659  ** remains disabled. This will prevent SQL injections from giving attackers
 15.1660  ** access to extension loading capabilities.
 15.1661  */
 15.1662 -SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
 15.1663 +SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
 15.1664  
 15.1665  /*
 15.1666  ** CAPI3REF: Automatically Load Statically Linked Extensions
 15.1667 @@ -5802,7 +6050,7 @@
 15.1668  **
 15.1669  ** ^(Even though the function prototype shows that xEntryPoint() takes
 15.1670  ** no arguments and returns void, SQLite invokes xEntryPoint() with three
 15.1671 -** arguments and expects and integer result as if the signature of the
 15.1672 +** arguments and expects an integer result as if the signature of the
 15.1673  ** entry point where as follows:
 15.1674  **
 15.1675  ** <blockquote><pre>
 15.1676 @@ -5828,7 +6076,7 @@
 15.1677  ** See also: [sqlite3_reset_auto_extension()]
 15.1678  ** and [sqlite3_cancel_auto_extension()]
 15.1679  */
 15.1680 -SQLITE_API int SQLITE_STDCALL sqlite3_auto_extension(void (*xEntryPoint)(void));
 15.1681 +SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void));
 15.1682  
 15.1683  /*
 15.1684  ** CAPI3REF: Cancel Automatic Extension Loading
 15.1685 @@ -5840,7 +6088,7 @@
 15.1686  ** unregistered and it returns 0 if X was not on the list of initialization
 15.1687  ** routines.
 15.1688  */
 15.1689 -SQLITE_API int SQLITE_STDCALL sqlite3_cancel_auto_extension(void (*xEntryPoint)(void));
 15.1690 +SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void));
 15.1691  
 15.1692  /*
 15.1693  ** CAPI3REF: Reset Automatic Extension Loading
 15.1694 @@ -5848,7 +6096,7 @@
 15.1695  ** ^This interface disables all automatic extensions previously
 15.1696  ** registered using [sqlite3_auto_extension()].
 15.1697  */
 15.1698 -SQLITE_API void SQLITE_STDCALL sqlite3_reset_auto_extension(void);
 15.1699 +SQLITE_API void sqlite3_reset_auto_extension(void);
 15.1700  
 15.1701  /*
 15.1702  ** The interface to the virtual-table mechanism is currently considered
 15.1703 @@ -6002,13 +6250,15 @@
 15.1704  ** the xUpdate method are automatically rolled back by SQLite.
 15.1705  **
 15.1706  ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
 15.1707 -** structure for SQLite version 3.8.2. If a virtual table extension is
 15.1708 +** structure for SQLite [version 3.8.2] ([dateof:3.8.2]). 
 15.1709 +** If a virtual table extension is
 15.1710  ** used with an SQLite version earlier than 3.8.2, the results of attempting 
 15.1711  ** to read or write the estimatedRows field are undefined (but are likely 
 15.1712  ** to included crashing the application). The estimatedRows field should
 15.1713  ** therefore only be used if [sqlite3_libversion_number()] returns a
 15.1714  ** value greater than or equal to 3008002. Similarly, the idxFlags field
 15.1715 -** was added for version 3.9.0. It may therefore only be used if
 15.1716 +** was added for [version 3.9.0] ([dateof:3.9.0]). 
 15.1717 +** It may therefore only be used if
 15.1718  ** sqlite3_libversion_number() returns a value greater than or equal to
 15.1719  ** 3009000.
 15.1720  */
 15.1721 @@ -6093,13 +6343,13 @@
 15.1722  ** interface is equivalent to sqlite3_create_module_v2() with a NULL
 15.1723  ** destructor.
 15.1724  */
 15.1725 -SQLITE_API int SQLITE_STDCALL sqlite3_create_module(
 15.1726 +SQLITE_API int sqlite3_create_module(
 15.1727    sqlite3 *db,               /* SQLite connection to register module with */
 15.1728    const char *zName,         /* Name of the module */
 15.1729    const sqlite3_module *p,   /* Methods for the module */
 15.1730    void *pClientData          /* Client data for xCreate/xConnect */
 15.1731  );
 15.1732 -SQLITE_API int SQLITE_STDCALL sqlite3_create_module_v2(
 15.1733 +SQLITE_API int sqlite3_create_module_v2(
 15.1734    sqlite3 *db,               /* SQLite connection to register module with */
 15.1735    const char *zName,         /* Name of the module */
 15.1736    const sqlite3_module *p,   /* Methods for the module */
 15.1737 @@ -6162,7 +6412,7 @@
 15.1738  ** to declare the format (the names and datatypes of the columns) of
 15.1739  ** the virtual tables they implement.
 15.1740  */
 15.1741 -SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
 15.1742 +SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
 15.1743  
 15.1744  /*
 15.1745  ** CAPI3REF: Overload A Function For A Virtual Table
 15.1746 @@ -6181,7 +6431,7 @@
 15.1747  ** purpose is to be a placeholder function that can be overloaded
 15.1748  ** by a [virtual table].
 15.1749  */
 15.1750 -SQLITE_API int SQLITE_STDCALL sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
 15.1751 +SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
 15.1752  
 15.1753  /*
 15.1754  ** The interface to the virtual-table mechanism defined above (back up
 15.1755 @@ -6256,6 +6506,12 @@
 15.1756  ** [database connection] error code and message accessible via 
 15.1757  ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. 
 15.1758  **
 15.1759 +** A BLOB referenced by sqlite3_blob_open() may be read using the
 15.1760 +** [sqlite3_blob_read()] interface and modified by using
 15.1761 +** [sqlite3_blob_write()].  The [BLOB handle] can be moved to a
 15.1762 +** different row of the same table using the [sqlite3_blob_reopen()]
 15.1763 +** interface.  However, the column, table, or database of a [BLOB handle]
 15.1764 +** cannot be changed after the [BLOB handle] is opened.
 15.1765  **
 15.1766  ** ^(If the row that a BLOB handle points to is modified by an
 15.1767  ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
 15.1768 @@ -6279,8 +6535,12 @@
 15.1769  **
 15.1770  ** To avoid a resource leak, every open [BLOB handle] should eventually
 15.1771  ** be released by a call to [sqlite3_blob_close()].
 15.1772 -*/
 15.1773 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_open(
 15.1774 +**
 15.1775 +** See also: [sqlite3_blob_close()],
 15.1776 +** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
 15.1777 +** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
 15.1778 +*/
 15.1779 +SQLITE_API int sqlite3_blob_open(
 15.1780    sqlite3*,
 15.1781    const char *zDb,
 15.1782    const char *zTable,
 15.1783 @@ -6294,11 +6554,11 @@
 15.1784  ** CAPI3REF: Move a BLOB Handle to a New Row
 15.1785  ** METHOD: sqlite3_blob
 15.1786  **
 15.1787 -** ^This function is used to move an existing blob handle so that it points
 15.1788 +** ^This function is used to move an existing [BLOB handle] so that it points
 15.1789  ** to a different row of the same database table. ^The new row is identified
 15.1790  ** by the rowid value passed as the second argument. Only the row can be
 15.1791  ** changed. ^The database, table and column on which the blob handle is open
 15.1792 -** remain the same. Moving an existing blob handle to a new row can be
 15.1793 +** remain the same. Moving an existing [BLOB handle] to a new row is
 15.1794  ** faster than closing the existing handle and opening a new one.
 15.1795  **
 15.1796  ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
 15.1797 @@ -6313,7 +6573,7 @@
 15.1798  **
 15.1799  ** ^This function sets the database handle error code and message.
 15.1800  */
 15.1801 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
 15.1802 +SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
 15.1803  
 15.1804  /*
 15.1805  ** CAPI3REF: Close A BLOB Handle
 15.1806 @@ -6336,7 +6596,7 @@
 15.1807  ** is passed a valid open blob handle, the values returned by the 
 15.1808  ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
 15.1809  */
 15.1810 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
 15.1811 +SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
 15.1812  
 15.1813  /*
 15.1814  ** CAPI3REF: Return The Size Of An Open BLOB
 15.1815 @@ -6352,7 +6612,7 @@
 15.1816  ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
 15.1817  ** to this routine results in undefined and probably undesirable behavior.
 15.1818  */
 15.1819 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
 15.1820 +SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
 15.1821  
 15.1822  /*
 15.1823  ** CAPI3REF: Read Data From A BLOB Incrementally
 15.1824 @@ -6381,7 +6641,7 @@
 15.1825  **
 15.1826  ** See also: [sqlite3_blob_write()].
 15.1827  */
 15.1828 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
 15.1829 +SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
 15.1830  
 15.1831  /*
 15.1832  ** CAPI3REF: Write Data Into A BLOB Incrementally
 15.1833 @@ -6423,7 +6683,7 @@
 15.1834  **
 15.1835  ** See also: [sqlite3_blob_read()].
 15.1836  */
 15.1837 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
 15.1838 +SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
 15.1839  
 15.1840  /*
 15.1841  ** CAPI3REF: Virtual File System Objects
 15.1842 @@ -6454,9 +6714,9 @@
 15.1843  ** ^(If the default VFS is unregistered, another VFS is chosen as
 15.1844  ** the default.  The choice for the new VFS is arbitrary.)^
 15.1845  */
 15.1846 -SQLITE_API sqlite3_vfs *SQLITE_STDCALL sqlite3_vfs_find(const char *zVfsName);
 15.1847 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
 15.1848 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_unregister(sqlite3_vfs*);
 15.1849 +SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
 15.1850 +SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
 15.1851 +SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
 15.1852  
 15.1853  /*
 15.1854  ** CAPI3REF: Mutexes
 15.1855 @@ -6572,11 +6832,11 @@
 15.1856  **
 15.1857  ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
 15.1858  */
 15.1859 -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int);
 15.1860 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex*);
 15.1861 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex*);
 15.1862 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex*);
 15.1863 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex*);
 15.1864 +SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
 15.1865 +SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
 15.1866 +SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
 15.1867 +SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
 15.1868 +SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
 15.1869  
 15.1870  /*
 15.1871  ** CAPI3REF: Mutex Methods Object
 15.1872 @@ -6686,8 +6946,8 @@
 15.1873  ** interface should also return 1 when given a NULL pointer.
 15.1874  */
 15.1875  #ifndef NDEBUG
 15.1876 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex*);
 15.1877 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex*);
 15.1878 +SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
 15.1879 +SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
 15.1880  #endif
 15.1881  
 15.1882  /*
 15.1883 @@ -6706,7 +6966,7 @@
 15.1884  #define SQLITE_MUTEX_STATIC_MEM       3  /* sqlite3_malloc() */
 15.1885  #define SQLITE_MUTEX_STATIC_MEM2      4  /* NOT USED */
 15.1886  #define SQLITE_MUTEX_STATIC_OPEN      4  /* sqlite3BtreeOpen() */
 15.1887 -#define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_random() */
 15.1888 +#define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_randomness() */
 15.1889  #define SQLITE_MUTEX_STATIC_LRU       6  /* lru page list */
 15.1890  #define SQLITE_MUTEX_STATIC_LRU2      7  /* NOT USED */
 15.1891  #define SQLITE_MUTEX_STATIC_PMEM      7  /* sqlite3PageMalloc() */
 15.1892 @@ -6727,7 +6987,7 @@
 15.1893  ** ^If the [threading mode] is Single-thread or Multi-thread then this
 15.1894  ** routine returns a NULL pointer.
 15.1895  */
 15.1896 -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
 15.1897 +SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
 15.1898  
 15.1899  /*
 15.1900  ** CAPI3REF: Low-Level Control Of Database Files
 15.1901 @@ -6762,7 +7022,7 @@
 15.1902  **
 15.1903  ** See also: [SQLITE_FCNTL_LOCKSTATE]
 15.1904  */
 15.1905 -SQLITE_API int SQLITE_STDCALL sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
 15.1906 +SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
 15.1907  
 15.1908  /*
 15.1909  ** CAPI3REF: Testing Interface
 15.1910 @@ -6781,7 +7041,7 @@
 15.1911  ** Unlike most of the SQLite API, this function is not guaranteed to
 15.1912  ** operate consistently from one release to the next.
 15.1913  */
 15.1914 -SQLITE_API int SQLITE_CDECL sqlite3_test_control(int op, ...);
 15.1915 +SQLITE_API int sqlite3_test_control(int op, ...);
 15.1916  
 15.1917  /*
 15.1918  ** CAPI3REF: Testing Interface Operation Codes
 15.1919 @@ -6810,6 +7070,7 @@
 15.1920  #define SQLITE_TESTCTRL_SCRATCHMALLOC           17
 15.1921  #define SQLITE_TESTCTRL_LOCALTIME_FAULT         18
 15.1922  #define SQLITE_TESTCTRL_EXPLAIN_STMT            19  /* NOT USED */
 15.1923 +#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD    19
 15.1924  #define SQLITE_TESTCTRL_NEVER_CORRUPT           20
 15.1925  #define SQLITE_TESTCTRL_VDBE_COVERAGE           21
 15.1926  #define SQLITE_TESTCTRL_BYTEORDER               22
 15.1927 @@ -6844,8 +7105,8 @@
 15.1928  **
 15.1929  ** See also: [sqlite3_db_status()]
 15.1930  */
 15.1931 -SQLITE_API int SQLITE_STDCALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
 15.1932 -SQLITE_API int SQLITE_STDCALL sqlite3_status64(
 15.1933 +SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
 15.1934 +SQLITE_API int sqlite3_status64(
 15.1935    int op,
 15.1936    sqlite3_int64 *pCurrent,
 15.1937    sqlite3_int64 *pHighwater,
 15.1938 @@ -6970,7 +7231,7 @@
 15.1939  **
 15.1940  ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
 15.1941  */
 15.1942 -SQLITE_API int SQLITE_STDCALL sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
 15.1943 +SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
 15.1944  
 15.1945  /*
 15.1946  ** CAPI3REF: Status Parameters for database connections
 15.1947 @@ -7016,6 +7277,18 @@
 15.1948  ** memory used by all pager caches associated with the database connection.)^
 15.1949  ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
 15.1950  **
 15.1951 +** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]] 
 15.1952 +** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
 15.1953 +** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
 15.1954 +** pager cache is shared between two or more connections the bytes of heap
 15.1955 +** memory used by that pager cache is divided evenly between the attached
 15.1956 +** connections.)^  In other words, if none of the pager caches associated
 15.1957 +** with the database connection are shared, this request returns the same
 15.1958 +** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
 15.1959 +** shared, the value returned by this call will be smaller than that returned
 15.1960 +** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
 15.1961 +** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
 15.1962 +**
 15.1963  ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
 15.1964  ** <dd>This parameter returns the approximate number of bytes of heap
 15.1965  ** memory used to store the schema for all databases associated
 15.1966 @@ -7073,7 +7346,8 @@
 15.1967  #define SQLITE_DBSTATUS_CACHE_MISS           8
 15.1968  #define SQLITE_DBSTATUS_CACHE_WRITE          9
 15.1969  #define SQLITE_DBSTATUS_DEFERRED_FKS        10
 15.1970 -#define SQLITE_DBSTATUS_MAX                 10   /* Largest defined DBSTATUS */
 15.1971 +#define SQLITE_DBSTATUS_CACHE_USED_SHARED   11
 15.1972 +#define SQLITE_DBSTATUS_MAX                 11   /* Largest defined DBSTATUS */
 15.1973  
 15.1974  
 15.1975  /*
 15.1976 @@ -7100,7 +7374,7 @@
 15.1977  **
 15.1978  ** See also: [sqlite3_status()] and [sqlite3_db_status()].
 15.1979  */
 15.1980 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
 15.1981 +SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
 15.1982  
 15.1983  /*
 15.1984  ** CAPI3REF: Status Parameters for prepared statements
 15.1985 @@ -7569,16 +7843,16 @@
 15.1986  ** same time as another thread is invoking sqlite3_backup_step() it is
 15.1987  ** possible that they return invalid values.
 15.1988  */
 15.1989 -SQLITE_API sqlite3_backup *SQLITE_STDCALL sqlite3_backup_init(
 15.1990 +SQLITE_API sqlite3_backup *sqlite3_backup_init(
 15.1991    sqlite3 *pDest,                        /* Destination database handle */
 15.1992    const char *zDestName,                 /* Destination database name */
 15.1993    sqlite3 *pSource,                      /* Source database handle */
 15.1994    const char *zSourceName                /* Source database name */
 15.1995  );
 15.1996 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_step(sqlite3_backup *p, int nPage);
 15.1997 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_finish(sqlite3_backup *p);
 15.1998 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
 15.1999 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
 15.2000 +SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
 15.2001 +SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
 15.2002 +SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
 15.2003 +SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
 15.2004  
 15.2005  /*
 15.2006  ** CAPI3REF: Unlock Notification
 15.2007 @@ -7695,7 +7969,7 @@
 15.2008  ** the special "DROP TABLE/INDEX" case, the extended error code is just 
 15.2009  ** SQLITE_LOCKED.)^
 15.2010  */
 15.2011 -SQLITE_API int SQLITE_STDCALL sqlite3_unlock_notify(
 15.2012 +SQLITE_API int sqlite3_unlock_notify(
 15.2013    sqlite3 *pBlocked,                          /* Waiting connection */
 15.2014    void (*xNotify)(void **apArg, int nArg),    /* Callback function to invoke */
 15.2015    void *pNotifyArg                            /* Argument to pass to xNotify */
 15.2016 @@ -7710,8 +7984,8 @@
 15.2017  ** strings in a case-independent fashion, using the same definition of "case
 15.2018  ** independence" that SQLite uses internally when comparing identifiers.
 15.2019  */
 15.2020 -SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *, const char *);
 15.2021 -SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *, const char *, int);
 15.2022 +SQLITE_API int sqlite3_stricmp(const char *, const char *);
 15.2023 +SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
 15.2024  
 15.2025  /*
 15.2026  ** CAPI3REF: String Globbing
 15.2027 @@ -7728,7 +8002,7 @@
 15.2028  **
 15.2029  ** See also: [sqlite3_strlike()].
 15.2030  */
 15.2031 -SQLITE_API int SQLITE_STDCALL sqlite3_strglob(const char *zGlob, const char *zStr);
 15.2032 +SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
 15.2033  
 15.2034  /*
 15.2035  ** CAPI3REF: String LIKE Matching
 15.2036 @@ -7751,7 +8025,7 @@
 15.2037  **
 15.2038  ** See also: [sqlite3_strglob()].
 15.2039  */
 15.2040 -SQLITE_API int SQLITE_STDCALL sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
 15.2041 +SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
 15.2042  
 15.2043  /*
 15.2044  ** CAPI3REF: Error Logging Interface
 15.2045 @@ -7774,7 +8048,7 @@
 15.2046  ** a few hundred characters, it will be truncated to the length of the
 15.2047  ** buffer.
 15.2048  */
 15.2049 -SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
 15.2050 +SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
 15.2051  
 15.2052  /*
 15.2053  ** CAPI3REF: Write-Ahead Log Commit Hook
 15.2054 @@ -7810,7 +8084,7 @@
 15.2055  ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
 15.2056  ** overwrite any prior [sqlite3_wal_hook()] settings.
 15.2057  */
 15.2058 -SQLITE_API void *SQLITE_STDCALL sqlite3_wal_hook(
 15.2059 +SQLITE_API void *sqlite3_wal_hook(
 15.2060    sqlite3*, 
 15.2061    int(*)(void *,sqlite3*,const char*,int),
 15.2062    void*
 15.2063 @@ -7845,7 +8119,7 @@
 15.2064  ** is only necessary if the default setting is found to be suboptimal
 15.2065  ** for a particular application.
 15.2066  */
 15.2067 -SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
 15.2068 +SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
 15.2069  
 15.2070  /*
 15.2071  ** CAPI3REF: Checkpoint a database
 15.2072 @@ -7867,7 +8141,7 @@
 15.2073  ** start a callback but which do not need the full power (and corresponding
 15.2074  ** complication) of [sqlite3_wal_checkpoint_v2()].
 15.2075  */
 15.2076 -SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
 15.2077 +SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
 15.2078  
 15.2079  /*
 15.2080  ** CAPI3REF: Checkpoint a database
 15.2081 @@ -7961,7 +8235,7 @@
 15.2082  ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
 15.2083  ** from SQL.
 15.2084  */
 15.2085 -SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint_v2(
 15.2086 +SQLITE_API int sqlite3_wal_checkpoint_v2(
 15.2087    sqlite3 *db,                    /* Database handle */
 15.2088    const char *zDb,                /* Name of attached database (or NULL) */
 15.2089    int eMode,                      /* SQLITE_CHECKPOINT_* value */
 15.2090 @@ -7997,7 +8271,7 @@
 15.2091  ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].)  Further options
 15.2092  ** may be added in the future.
 15.2093  */
 15.2094 -SQLITE_API int SQLITE_CDECL sqlite3_vtab_config(sqlite3*, int op, ...);
 15.2095 +SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
 15.2096  
 15.2097  /*
 15.2098  ** CAPI3REF: Virtual Table Configuration Options
 15.2099 @@ -8050,7 +8324,7 @@
 15.2100  ** of the SQL statement that triggered the call to the [xUpdate] method of the
 15.2101  ** [virtual table].
 15.2102  */
 15.2103 -SQLITE_API int SQLITE_STDCALL sqlite3_vtab_on_conflict(sqlite3 *);
 15.2104 +SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
 15.2105  
 15.2106  /*
 15.2107  ** CAPI3REF: Conflict resolution modes
 15.2108 @@ -8155,7 +8429,7 @@
 15.2109  **
 15.2110  ** See also: [sqlite3_stmt_scanstatus_reset()]
 15.2111  */
 15.2112 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_scanstatus(
 15.2113 +SQLITE_API int sqlite3_stmt_scanstatus(
 15.2114    sqlite3_stmt *pStmt,      /* Prepared statement for which info desired */
 15.2115    int idx,                  /* Index of loop to report on */
 15.2116    int iScanStatusOp,        /* Information desired.  SQLITE_SCANSTAT_* */
 15.2117 @@ -8171,7 +8445,7 @@
 15.2118  ** This API is only available if the library is built with pre-processor
 15.2119  ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
 15.2120  */
 15.2121 -SQLITE_API void SQLITE_STDCALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
 15.2122 +SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
 15.2123  
 15.2124  /*
 15.2125  ** CAPI3REF: Flush caches to disk mid-transaction
 15.2126 @@ -8203,7 +8477,7 @@
 15.2127  ** ^This function does not set the database handle error code or message
 15.2128  ** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.
 15.2129  */
 15.2130 -SQLITE_API int SQLITE_STDCALL sqlite3_db_cacheflush(sqlite3*);
 15.2131 +SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
 15.2132  
 15.2133  /*
 15.2134  ** CAPI3REF: The pre-update hook.
 15.2135 @@ -8213,7 +8487,7 @@
 15.2136  **
 15.2137  ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
 15.2138  ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
 15.2139 -** on a [rowid table].
 15.2140 +** on a database table.
 15.2141  ** ^At most one preupdate hook may be registered at a time on a single
 15.2142  ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
 15.2143  ** the previous setting.
 15.2144 @@ -8222,14 +8496,14 @@
 15.2145  ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
 15.2146  ** the first parameter to callbacks.
 15.2147  **
 15.2148 -** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate
 15.2149 -** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID]
 15.2150 -** tables.
 15.2151 +** ^The preupdate hook only fires for changes to real database tables; the
 15.2152 +** preupdate hook is not invoked for changes to [virtual tables] or to
 15.2153 +** system tables like sqlite_master or sqlite_stat1.
 15.2154  **
 15.2155  ** ^The second parameter to the preupdate callback is a pointer to
 15.2156  ** the [database connection] that registered the preupdate hook.
 15.2157  ** ^The third parameter to the preupdate callback is one of the constants
 15.2158 -** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to indentify the
 15.2159 +** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
 15.2160  ** kind of update operation that is about to occur.
 15.2161  ** ^(The fourth parameter to the preupdate callback is the name of the
 15.2162  ** database within the database connection that is being modified.  This
 15.2163 @@ -8238,12 +8512,16 @@
 15.2164  ** databases.)^
 15.2165  ** ^The fifth parameter to the preupdate callback is the name of the
 15.2166  ** table that is being modified.
 15.2167 -** ^The sixth parameter to the preupdate callback is the initial [rowid] of the
 15.2168 -** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is
 15.2169 -** undefined for SQLITE_INSERT changes.
 15.2170 -** ^The seventh parameter to the preupdate callback is the final [rowid] of
 15.2171 -** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is
 15.2172 -** undefined for SQLITE_DELETE changes.
 15.2173 +**
 15.2174 +** For an UPDATE or DELETE operation on a [rowid table], the sixth
 15.2175 +** parameter passed to the preupdate callback is the initial [rowid] of the 
 15.2176 +** row being modified or deleted. For an INSERT operation on a rowid table,
 15.2177 +** or any operation on a WITHOUT ROWID table, the value of the sixth 
 15.2178 +** parameter is undefined. For an INSERT or UPDATE on a rowid table the
 15.2179 +** seventh parameter is the final rowid value of the row being inserted
 15.2180 +** or updated. The value of the seventh parameter passed to the callback
 15.2181 +** function is not defined for operations on WITHOUT ROWID tables, or for
 15.2182 +** INSERT operations on rowid tables.
 15.2183  **
 15.2184  ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
 15.2185  ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
 15.2186 @@ -8283,7 +8561,8 @@
 15.2187  **
 15.2188  ** See also:  [sqlite3_update_hook()]
 15.2189  */
 15.2190 -SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_preupdate_hook(
 15.2191 +#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
 15.2192 +SQLITE_API void *sqlite3_preupdate_hook(
 15.2193    sqlite3 *db,
 15.2194    void(*xPreUpdate)(
 15.2195      void *pCtx,                   /* Copy of third arg to preupdate_hook() */
 15.2196 @@ -8296,10 +8575,11 @@
 15.2197    ),
 15.2198    void*
 15.2199  );
 15.2200 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
 15.2201 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_count(sqlite3 *);
 15.2202 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_depth(sqlite3 *);
 15.2203 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
 15.2204 +SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
 15.2205 +SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
 15.2206 +SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
 15.2207 +SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
 15.2208 +#endif
 15.2209  
 15.2210  /*
 15.2211  ** CAPI3REF: Low-level system error code
 15.2212 @@ -8311,11 +8591,11 @@
 15.2213  ** called to get back the underlying "errno" that caused the problem, such
 15.2214  ** as ENOSPC, EAUTH, EISDIR, and so forth.  
 15.2215  */
 15.2216 -SQLITE_API int SQLITE_STDCALL sqlite3_system_errno(sqlite3*);
 15.2217 +SQLITE_API int sqlite3_system_errno(sqlite3*);
 15.2218  
 15.2219  /*
 15.2220  ** CAPI3REF: Database Snapshot
 15.2221 -** KEYWORDS: {snapshot}
 15.2222 +** KEYWORDS: {snapshot} {sqlite3_snapshot}
 15.2223  ** EXPERIMENTAL
 15.2224  **
 15.2225  ** An instance of the snapshot object records the state of a [WAL mode]
 15.2226 @@ -8339,7 +8619,9 @@
 15.2227  ** to an historical snapshot (if possible).  The destructor for 
 15.2228  ** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
 15.2229  */
 15.2230 -typedef struct sqlite3_snapshot sqlite3_snapshot;
 15.2231 +typedef struct sqlite3_snapshot {
 15.2232 +  unsigned char hidden[48];
 15.2233 +} sqlite3_snapshot;
 15.2234  
 15.2235  /*
 15.2236  ** CAPI3REF: Record A Database Snapshot
 15.2237 @@ -8350,9 +8632,32 @@
 15.2238  ** schema S in database connection D.  ^On success, the
 15.2239  ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
 15.2240  ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
 15.2241 -** ^If schema S of [database connection] D is not a [WAL mode] database
 15.2242 -** that is in a read transaction, then [sqlite3_snapshot_get(D,S,P)]
 15.2243 -** leaves the *P value unchanged and returns an appropriate [error code].
 15.2244 +** If there is not already a read-transaction open on schema S when
 15.2245 +** this function is called, one is opened automatically. 
 15.2246 +**
 15.2247 +** The following must be true for this function to succeed. If any of
 15.2248 +** the following statements are false when sqlite3_snapshot_get() is
 15.2249 +** called, SQLITE_ERROR is returned. The final value of *P is undefined
 15.2250 +** in this case. 
 15.2251 +**
 15.2252 +** <ul>
 15.2253 +**   <li> The database handle must be in [autocommit mode].
 15.2254 +**
 15.2255 +**   <li> Schema S of [database connection] D must be a [WAL mode] database.
 15.2256 +**
 15.2257 +**   <li> There must not be a write transaction open on schema S of database
 15.2258 +**        connection D.
 15.2259 +**
 15.2260 +**   <li> One or more transactions must have been written to the current wal
 15.2261 +**        file since it was created on disk (by any connection). This means
 15.2262 +**        that a snapshot cannot be taken on a wal mode database with no wal 
 15.2263 +**        file immediately after it is first opened. At least one transaction
 15.2264 +**        must be written to it first.
 15.2265 +** </ul>
 15.2266 +**
 15.2267 +** This function may also return SQLITE_NOMEM.  If it is called with the
 15.2268 +** database handle in autocommit mode but fails for some other reason, 
 15.2269 +** whether or not a read transaction is opened on schema S is undefined.
 15.2270  **
 15.2271  ** The [sqlite3_snapshot] object returned from a successful call to
 15.2272  ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
 15.2273 @@ -8361,7 +8666,7 @@
 15.2274  ** The [sqlite3_snapshot_get()] interface is only available when the
 15.2275  ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
 15.2276  */
 15.2277 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_get(
 15.2278 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
 15.2279    sqlite3 *db,
 15.2280    const char *zSchema,
 15.2281    sqlite3_snapshot **ppSnapshot
 15.2282 @@ -8399,7 +8704,7 @@
 15.2283  ** The [sqlite3_snapshot_open()] interface is only available when the
 15.2284  ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
 15.2285  */
 15.2286 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_open(
 15.2287 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
 15.2288    sqlite3 *db,
 15.2289    const char *zSchema,
 15.2290    sqlite3_snapshot *pSnapshot
 15.2291 @@ -8416,7 +8721,7 @@
 15.2292  ** The [sqlite3_snapshot_free()] interface is only available when the
 15.2293  ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
 15.2294  */
 15.2295 -SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
 15.2296 +SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
 15.2297  
 15.2298  /*
 15.2299  ** CAPI3REF: Compare the ages of two snapshot handles.
 15.2300 @@ -8440,12 +8745,34 @@
 15.2301  ** snapshot than P2, zero if the two handles refer to the same database
 15.2302  ** snapshot, and a positive value if P1 is a newer snapshot than P2.
 15.2303  */
 15.2304 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
 15.2305 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
 15.2306    sqlite3_snapshot *p1,
 15.2307    sqlite3_snapshot *p2
 15.2308  );
 15.2309  
 15.2310  /*
 15.2311 +** CAPI3REF: Recover snapshots from a wal file
 15.2312 +** EXPERIMENTAL
 15.2313 +**
 15.2314 +** If all connections disconnect from a database file but do not perform
 15.2315 +** a checkpoint, the existing wal file is opened along with the database
 15.2316 +** file the next time the database is opened. At this point it is only
 15.2317 +** possible to successfully call sqlite3_snapshot_open() to open the most
 15.2318 +** recent snapshot of the database (the one at the head of the wal file),
 15.2319 +** even though the wal file may contain other valid snapshots for which
 15.2320 +** clients have sqlite3_snapshot handles.
 15.2321 +**
 15.2322 +** This function attempts to scan the wal file associated with database zDb
 15.2323 +** of database handle db and make all valid snapshots available to
 15.2324 +** sqlite3_snapshot_open(). It is an error if there is already a read
 15.2325 +** transaction open on the database, or if the database is not a wal mode
 15.2326 +** database.
 15.2327 +**
 15.2328 +** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
 15.2329 +*/
 15.2330 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
 15.2331 +
 15.2332 +/*
 15.2333  ** Undo the hack that converts floating point types to integer for
 15.2334  ** builds on processors without floating point support.
 15.2335  */
 15.2336 @@ -8456,7 +8783,7 @@
 15.2337  #if 0
 15.2338  }  /* End of the 'extern "C"' block */
 15.2339  #endif
 15.2340 -#endif /* _SQLITE3_H_ */
 15.2341 +#endif /* SQLITE3_H */
 15.2342  
 15.2343  /******** Begin file sqlite3rtree.h *********/
 15.2344  /*
 15.2345 @@ -8498,7 +8825,7 @@
 15.2346  **
 15.2347  **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
 15.2348  */
 15.2349 -SQLITE_API int SQLITE_STDCALL sqlite3_rtree_geometry_callback(
 15.2350 +SQLITE_API int sqlite3_rtree_geometry_callback(
 15.2351    sqlite3 *db,
 15.2352    const char *zGeom,
 15.2353    int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
 15.2354 @@ -8524,7 +8851,7 @@
 15.2355  **
 15.2356  **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
 15.2357  */
 15.2358 -SQLITE_API int SQLITE_STDCALL sqlite3_rtree_query_callback(
 15.2359 +SQLITE_API int sqlite3_rtree_query_callback(
 15.2360    sqlite3 *db,
 15.2361    const char *zQueryFunc,
 15.2362    int (*xQueryFunc)(sqlite3_rtree_query_info*),
 15.2363 @@ -8630,7 +8957,7 @@
 15.2364  ** attached database. It is not an error if database zDb is not attached
 15.2365  ** to the database when the session object is created.
 15.2366  */
 15.2367 -int sqlite3session_create(
 15.2368 +SQLITE_API int sqlite3session_create(
 15.2369    sqlite3 *db,                    /* Database handle */
 15.2370    const char *zDb,                /* Name of db (e.g. "main") */
 15.2371    sqlite3_session **ppSession     /* OUT: New session object */
 15.2372 @@ -8648,7 +8975,7 @@
 15.2373  ** are attached is closed. Refer to the documentation for 
 15.2374  ** [sqlite3session_create()] for details.
 15.2375  */
 15.2376 -void sqlite3session_delete(sqlite3_session *pSession);
 15.2377 +SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
 15.2378  
 15.2379  
 15.2380  /*
 15.2381 @@ -8668,7 +8995,7 @@
 15.2382  ** The return value indicates the final state of the session object: 0 if 
 15.2383  ** the session is disabled, or 1 if it is enabled.
 15.2384  */
 15.2385 -int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
 15.2386 +SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
 15.2387  
 15.2388  /*
 15.2389  ** CAPI3REF: Set Or Clear the Indirect Change Flag
 15.2390 @@ -8697,7 +9024,7 @@
 15.2391  ** The return value indicates the final state of the indirect flag: 0 if 
 15.2392  ** it is clear, or 1 if it is set.
 15.2393  */
 15.2394 -int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
 15.2395 +SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
 15.2396  
 15.2397  /*
 15.2398  ** CAPI3REF: Attach A Table To A Session Object
 15.2399 @@ -8727,7 +9054,7 @@
 15.2400  ** SQLITE_OK is returned if the call completes without error. Or, if an error 
 15.2401  ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
 15.2402  */
 15.2403 -int sqlite3session_attach(
 15.2404 +SQLITE_API int sqlite3session_attach(
 15.2405    sqlite3_session *pSession,      /* Session object */
 15.2406    const char *zTab                /* Table name */
 15.2407  );
 15.2408 @@ -8736,12 +9063,12 @@
 15.2409  ** CAPI3REF: Set a table filter on a Session Object.
 15.2410  **
 15.2411  ** The second argument (xFilter) is the "filter callback". For changes to rows 
 15.2412 -** in tables that are not attached to the Session oject, the filter is called
 15.2413 +** in tables that are not attached to the Session object, the filter is called
 15.2414  ** to determine whether changes to the table's rows should be tracked or not. 
 15.2415  ** If xFilter returns 0, changes is not tracked. Note that once a table is 
 15.2416  ** attached, xFilter will not be called again.
 15.2417  */
 15.2418 -void sqlite3session_table_filter(
 15.2419 +SQLITE_API void sqlite3session_table_filter(
 15.2420    sqlite3_session *pSession,      /* Session object */
 15.2421    int(*xFilter)(
 15.2422      void *pCtx,                   /* Copy of third arg to _filter_table() */
 15.2423 @@ -8854,7 +9181,7 @@
 15.2424  ** another field of the same row is updated while the session is enabled, the
 15.2425  ** resulting changeset will contain an UPDATE change that updates both fields.
 15.2426  */
 15.2427 -int sqlite3session_changeset(
 15.2428 +SQLITE_API int sqlite3session_changeset(
 15.2429    sqlite3_session *pSession,      /* Session object */
 15.2430    int *pnChangeset,               /* OUT: Size of buffer at *ppChangeset */
 15.2431    void **ppChangeset              /* OUT: Buffer containing changeset */
 15.2432 @@ -8898,7 +9225,8 @@
 15.2433  **     the from-table, a DELETE record is added to the session object.
 15.2434  **
 15.2435  **   <li> For each row (primary key) that exists in both tables, but features 
 15.2436 -**     different in each, an UPDATE record is added to the session.
 15.2437 +**     different non-PK values in each, an UPDATE record is added to the
 15.2438 +**     session.  
 15.2439  ** </ul>
 15.2440  **
 15.2441  ** To clarify, if this function is called and then a changeset constructed
 15.2442 @@ -8915,7 +9243,7 @@
 15.2443  ** message. It is the responsibility of the caller to free this buffer using
 15.2444  ** sqlite3_free().
 15.2445  */
 15.2446 -int sqlite3session_diff(
 15.2447 +SQLITE_API int sqlite3session_diff(
 15.2448    sqlite3_session *pSession,
 15.2449    const char *zFromDb,
 15.2450    const char *zTbl,
 15.2451 @@ -8951,7 +9279,7 @@
 15.2452  ** a single table are grouped together, tables appear in the order in which
 15.2453  ** they were attached to the session object).
 15.2454  */
 15.2455 -int sqlite3session_patchset(
 15.2456 +SQLITE_API int sqlite3session_patchset(
 15.2457    sqlite3_session *pSession,      /* Session object */
 15.2458    int *pnPatchset,                /* OUT: Size of buffer at *ppChangeset */
 15.2459    void **ppPatchset               /* OUT: Buffer containing changeset */
 15.2460 @@ -8972,7 +9300,7 @@
 15.2461  ** guaranteed that a call to sqlite3session_changeset() will return a 
 15.2462  ** changeset containing zero changes.
 15.2463  */
 15.2464 -int sqlite3session_isempty(sqlite3_session *pSession);
 15.2465 +SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
 15.2466  
 15.2467  /*
 15.2468  ** CAPI3REF: Create An Iterator To Traverse A Changeset 
 15.2469 @@ -9002,12 +9330,12 @@
 15.2470  ** [sqlite3changeset_invert()] functions, all changes within the changeset 
 15.2471  ** that apply to a single table are grouped together. This means that when 
 15.2472  ** an application iterates through a changeset using an iterator created by 
 15.2473 -** this function, all changes that relate to a single table are visted 
 15.2474 +** this function, all changes that relate to a single table are visited 
 15.2475  ** consecutively. There is no chance that the iterator will visit a change 
 15.2476  ** the applies to table X, then one for table Y, and then later on visit 
 15.2477  ** another change for table X.
 15.2478  */
 15.2479 -int sqlite3changeset_start(
 15.2480 +SQLITE_API int sqlite3changeset_start(
 15.2481    sqlite3_changeset_iter **pp,    /* OUT: New changeset iterator handle */
 15.2482    int nChangeset,                 /* Size of changeset blob in bytes */
 15.2483    void *pChangeset                /* Pointer to blob containing changeset */
 15.2484 @@ -9036,7 +9364,7 @@
 15.2485  ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or 
 15.2486  ** SQLITE_NOMEM.
 15.2487  */
 15.2488 -int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
 15.2489 +SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
 15.2490  
 15.2491  /*
 15.2492  ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
 15.2493 @@ -9064,7 +9392,7 @@
 15.2494  ** SQLite error code is returned. The values of the output variables may not
 15.2495  ** be trusted in this case.
 15.2496  */
 15.2497 -int sqlite3changeset_op(
 15.2498 +SQLITE_API int sqlite3changeset_op(
 15.2499    sqlite3_changeset_iter *pIter,  /* Iterator object */
 15.2500    const char **pzTab,             /* OUT: Pointer to table name */
 15.2501    int *pnCol,                     /* OUT: Number of columns in table */
 15.2502 @@ -9089,7 +9417,7 @@
 15.2503  ** 0x01 if the corresponding column is part of the tables primary key, or
 15.2504  ** 0x00 if it is not.
 15.2505  **
 15.2506 -** If argumet pnCol is not NULL, then *pnCol is set to the number of columns
 15.2507 +** If argument pnCol is not NULL, then *pnCol is set to the number of columns
 15.2508  ** in the table.
 15.2509  **
 15.2510  ** If this function is called when the iterator does not point to a valid
 15.2511 @@ -9097,7 +9425,7 @@
 15.2512  ** SQLITE_OK is returned and the output variables populated as described
 15.2513  ** above.
 15.2514  */
 15.2515 -int sqlite3changeset_pk(
 15.2516 +SQLITE_API int sqlite3changeset_pk(
 15.2517    sqlite3_changeset_iter *pIter,  /* Iterator object */
 15.2518    unsigned char **pabPK,          /* OUT: Array of boolean - true for PK cols */
 15.2519    int *pnCol                      /* OUT: Number of entries in output array */
 15.2520 @@ -9127,7 +9455,7 @@
 15.2521  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
 15.2522  ** is returned and *ppValue is set to NULL.
 15.2523  */
 15.2524 -int sqlite3changeset_old(
 15.2525 +SQLITE_API int sqlite3changeset_old(
 15.2526    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
 15.2527    int iVal,                       /* Column number */
 15.2528    sqlite3_value **ppValue         /* OUT: Old value (or NULL pointer) */
 15.2529 @@ -9160,7 +9488,7 @@
 15.2530  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
 15.2531  ** is returned and *ppValue is set to NULL.
 15.2532  */
 15.2533 -int sqlite3changeset_new(
 15.2534 +SQLITE_API int sqlite3changeset_new(
 15.2535    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
 15.2536    int iVal,                       /* Column number */
 15.2537    sqlite3_value **ppValue         /* OUT: New value (or NULL pointer) */
 15.2538 @@ -9187,7 +9515,7 @@
 15.2539  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
 15.2540  ** is returned and *ppValue is set to NULL.
 15.2541  */
 15.2542 -int sqlite3changeset_conflict(
 15.2543 +SQLITE_API int sqlite3changeset_conflict(
 15.2544    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
 15.2545    int iVal,                       /* Column number */
 15.2546    sqlite3_value **ppValue         /* OUT: Value from conflicting row */
 15.2547 @@ -9203,7 +9531,7 @@
 15.2548  **
 15.2549  ** In all other cases this function returns SQLITE_MISUSE.
 15.2550  */
 15.2551 -int sqlite3changeset_fk_conflicts(
 15.2552 +SQLITE_API int sqlite3changeset_fk_conflicts(
 15.2553    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
 15.2554    int *pnOut                      /* OUT: Number of FK violations */
 15.2555  );
 15.2556 @@ -9236,7 +9564,7 @@
 15.2557  **     // An error has occurred 
 15.2558  **   }
 15.2559  */
 15.2560 -int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
 15.2561 +SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
 15.2562  
 15.2563  /*
 15.2564  ** CAPI3REF: Invert A Changeset
 15.2565 @@ -9266,7 +9594,7 @@
 15.2566  ** WARNING/TODO: This function currently assumes that the input is a valid
 15.2567  ** changeset. If it is not, the results are undefined.
 15.2568  */
 15.2569 -int sqlite3changeset_invert(
 15.2570 +SQLITE_API int sqlite3changeset_invert(
 15.2571    int nIn, const void *pIn,       /* Input changeset */
 15.2572    int *pnOut, void **ppOut        /* OUT: Inverse of input */
 15.2573  );
 15.2574 @@ -9295,7 +9623,7 @@
 15.2575  **
 15.2576  ** Refer to the sqlite3_changegroup documentation below for details.
 15.2577  */
 15.2578 -int sqlite3changeset_concat(
 15.2579 +SQLITE_API int sqlite3changeset_concat(
 15.2580    int nA,                         /* Number of bytes in buffer pA */
 15.2581    void *pA,                       /* Pointer to buffer containing changeset A */
 15.2582    int nB,                         /* Number of bytes in buffer pB */
 15.2583 @@ -9306,12 +9634,12 @@
 15.2584  
 15.2585  
 15.2586  /*
 15.2587 -** Changegroup handle.
 15.2588 +** CAPI3REF: Changegroup Handle
 15.2589  */
 15.2590  typedef struct sqlite3_changegroup sqlite3_changegroup;
 15.2591  
 15.2592  /*
 15.2593 -** CAPI3REF: Combine two or more changesets into a single changeset.
 15.2594 +** CAPI3REF: Create A New Changegroup Object
 15.2595  **
 15.2596  ** An sqlite3_changegroup object is used to combine two or more changesets
 15.2597  ** (or patchsets) into a single changeset (or patchset). A single changegroup
 15.2598 @@ -9345,9 +9673,11 @@
 15.2599  ** sqlite3changegroup_output() functions, also available are the streaming
 15.2600  ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
 15.2601  */
 15.2602 -int sqlite3changegroup_new(sqlite3_changegroup **pp);
 15.2603 -
 15.2604 -/*
 15.2605 +SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
 15.2606 +
 15.2607 +/*
 15.2608 +** CAPI3REF: Add A Changeset To A Changegroup
 15.2609 +**
 15.2610  ** Add all changes within the changeset (or patchset) in buffer pData (size
 15.2611  ** nData bytes) to the changegroup. 
 15.2612  **
 15.2613 @@ -9362,7 +9692,7 @@
 15.2614  ** apply to the same row as a change already present in the changegroup if
 15.2615  ** the two rows have the same primary key.
 15.2616  **
 15.2617 -** Changes to rows that that do not already appear in the changegroup are
 15.2618 +** Changes to rows that do not already appear in the changegroup are
 15.2619  ** simply copied into it. Or, if both the new changeset and the changegroup
 15.2620  ** contain changes that apply to a single row, the final contents of the
 15.2621  ** changegroup depends on the type of each change, as follows:
 15.2622 @@ -9420,9 +9750,11 @@
 15.2623  **
 15.2624  ** If no error occurs, SQLITE_OK is returned.
 15.2625  */
 15.2626 -int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
 15.2627 -
 15.2628 -/*
 15.2629 +SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
 15.2630 +
 15.2631 +/*
 15.2632 +** CAPI3REF: Obtain A Composite Changeset From A Changegroup
 15.2633 +**
 15.2634  ** Obtain a buffer containing a changeset (or patchset) representing the
 15.2635  ** current contents of the changegroup. If the inputs to the changegroup
 15.2636  ** were themselves changesets, the output is a changeset. Or, if the
 15.2637 @@ -9444,16 +9776,16 @@
 15.2638  ** responsibility of the caller to eventually free the buffer using a
 15.2639  ** call to sqlite3_free().
 15.2640  */
 15.2641 -int sqlite3changegroup_output(
 15.2642 +SQLITE_API int sqlite3changegroup_output(
 15.2643    sqlite3_changegroup*,
 15.2644    int *pnData,                    /* OUT: Size of output buffer in bytes */
 15.2645    void **ppData                   /* OUT: Pointer to output buffer */
 15.2646  );
 15.2647  
 15.2648  /*
 15.2649 -** Delete a changegroup object.
 15.2650 -*/
 15.2651 -void sqlite3changegroup_delete(sqlite3_changegroup*);
 15.2652 +** CAPI3REF: Delete A Changegroup Object
 15.2653 +*/
 15.2654 +SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
 15.2655  
 15.2656  /*
 15.2657  ** CAPI3REF: Apply A Changeset To A Database
 15.2658 @@ -9479,7 +9811,7 @@
 15.2659  ** <ul>
 15.2660  **   <li> The table has the same name as the name recorded in the 
 15.2661  **        changeset, and
 15.2662 -**   <li> The table has the same number of columns as recorded in the 
 15.2663 +**   <li> The table has at least as many columns as recorded in the 
 15.2664  **        changeset, and
 15.2665  **   <li> The table has primary key columns in the same position as 
 15.2666  **        recorded in the changeset.
 15.2667 @@ -9524,7 +9856,11 @@
 15.2668  **   If a row with matching primary key values is found, but one or more of
 15.2669  **   the non-primary key fields contains a value different from the original
 15.2670  **   row value stored in the changeset, the conflict-handler function is
 15.2671 -**   invoked with [SQLITE_CHANGESET_DATA] as the second argument.
 15.2672 +**   invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
 15.2673 +**   database table has more columns than are recorded in the changeset,
 15.2674 +**   only the values of those non-primary key fields are compared against
 15.2675 +**   the current database contents - any trailing database table columns
 15.2676 +**   are ignored.
 15.2677  **
 15.2678  **   If no row with matching primary key values is found in the database,
 15.2679  **   the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
 15.2680 @@ -9539,7 +9875,9 @@
 15.2681  **
 15.2682  ** <dt>INSERT Changes<dd>
 15.2683  **   For each INSERT change, an attempt is made to insert the new row into
 15.2684 -**   the database.
 15.2685 +**   the database. If the changeset row contains fewer fields than the
 15.2686 +**   database table, the trailing fields are populated with their default
 15.2687 +**   values.
 15.2688  **
 15.2689  **   If the attempt to insert the row fails because the database already 
 15.2690  **   contains a row with the same primary key values, the conflict handler
 15.2691 @@ -9557,13 +9895,13 @@
 15.2692  **   For each UPDATE change, this function checks if the target database 
 15.2693  **   contains a row with the same primary key value (or values) as the 
 15.2694  **   original row values stored in the changeset. If it does, and the values 
 15.2695 -**   stored in all non-primary key columns also match the values stored in 
 15.2696 -**   the changeset the row is updated within the target database.
 15.2697 +**   stored in all modified non-primary key columns also match the values
 15.2698 +**   stored in the changeset the row is updated within the target database.
 15.2699  **
 15.2700  **   If a row with matching primary key values is found, but one or more of
 15.2701 -**   the non-primary key fields contains a value different from an original
 15.2702 -**   row value stored in the changeset, the conflict-handler function is
 15.2703 -**   invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
 15.2704 +**   the modified non-primary key fields contains a value different from an
 15.2705 +**   original row value stored in the changeset, the conflict-handler function
 15.2706 +**   is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
 15.2707  **   UPDATE changes only contain values for non-primary key fields that are
 15.2708  **   to be modified, only those fields need to match the original values to
 15.2709  **   avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
 15.2710 @@ -9591,7 +9929,7 @@
 15.2711  ** rolled back, restoring the target database to its original state, and an 
 15.2712  ** SQLite error code returned.
 15.2713  */
 15.2714 -int sqlite3changeset_apply(
 15.2715 +SQLITE_API int sqlite3changeset_apply(
 15.2716    sqlite3 *db,                    /* Apply change to "main" db of this handle */
 15.2717    int nChangeset,                 /* Size of changeset in bytes */
 15.2718    void *pChangeset,               /* Changeset blob */
 15.2719 @@ -9792,7 +10130,7 @@
 15.2720  ** parameter set to a value less than or equal to zero. Other than this,
 15.2721  ** no guarantees are made as to the size of the chunks of data returned.
 15.2722  */
 15.2723 -int sqlite3changeset_apply_strm(
 15.2724 +SQLITE_API int sqlite3changeset_apply_strm(
 15.2725    sqlite3 *db,                    /* Apply change to "main" db of this handle */
 15.2726    int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
 15.2727    void *pIn,                                          /* First arg for xInput */
 15.2728 @@ -9807,7 +10145,7 @@
 15.2729    ),
 15.2730    void *pCtx                      /* First argument passed to xConflict */
 15.2731  );
 15.2732 -int sqlite3changeset_concat_strm(
 15.2733 +SQLITE_API int sqlite3changeset_concat_strm(
 15.2734    int (*xInputA)(void *pIn, void *pData, int *pnData),
 15.2735    void *pInA,
 15.2736    int (*xInputB)(void *pIn, void *pData, int *pnData),
 15.2737 @@ -9815,32 +10153,32 @@
 15.2738    int (*xOutput)(void *pOut, const void *pData, int nData),
 15.2739    void *pOut
 15.2740  );
 15.2741 -int sqlite3changeset_invert_strm(
 15.2742 +SQLITE_API int sqlite3changeset_invert_strm(
 15.2743    int (*xInput)(void *pIn, void *pData, int *pnData),
 15.2744    void *pIn,
 15.2745    int (*xOutput)(void *pOut, const void *pData, int nData),
 15.2746    void *pOut
 15.2747  );
 15.2748 -int sqlite3changeset_start_strm(
 15.2749 +SQLITE_API int sqlite3changeset_start_strm(
 15.2750    sqlite3_changeset_iter **pp,
 15.2751    int (*xInput)(void *pIn, void *pData, int *pnData),
 15.2752    void *pIn
 15.2753  );
 15.2754 -int sqlite3session_changeset_strm(
 15.2755 +SQLITE_API int sqlite3session_changeset_strm(
 15.2756    sqlite3_session *pSession,
 15.2757    int (*xOutput)(void *pOut, const void *pData, int nData),
 15.2758    void *pOut
 15.2759  );
 15.2760 -int sqlite3session_patchset_strm(
 15.2761 +SQLITE_API int sqlite3session_patchset_strm(
 15.2762    sqlite3_session *pSession,
 15.2763    int (*xOutput)(void *pOut, const void *pData, int nData),
 15.2764    void *pOut
 15.2765  );
 15.2766 -int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
 15.2767 +SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
 15.2768      int (*xInput)(void *pIn, void *pData, int *pnData),
 15.2769      void *pIn
 15.2770  );
 15.2771 -int sqlite3changegroup_output_strm(sqlite3_changegroup*,
 15.2772 +SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
 15.2773      int (*xOutput)(void *pOut, const void *pData, int nData), 
 15.2774      void *pOut
 15.2775  );
 15.2776 @@ -10176,7 +10514,7 @@
 15.2777  ** behaviour. The structure methods are expected to function as follows:
 15.2778  **
 15.2779  ** xCreate:
 15.2780 -**   This function is used to allocate and inititalize a tokenizer instance.
 15.2781 +**   This function is used to allocate and initialize a tokenizer instance.
 15.2782  **   A tokenizer instance is required to actually tokenize text.
 15.2783  **
 15.2784  **   The first argument passed to this function is a copy of the (void*)
 15.2785 @@ -10436,7 +10774,6 @@
 15.2786  
 15.2787  #endif /* _FTS5_H */
 15.2788  
 15.2789 -
 15.2790  /******** End of fts5.h *********/
 15.2791  
 15.2792  /************** End of sqlite3.h *********************************************/
 15.2793 @@ -10541,7 +10878,7 @@
 15.2794  ** Not currently enforced.
 15.2795  */
 15.2796  #ifndef SQLITE_MAX_VDBE_OP
 15.2797 -# define SQLITE_MAX_VDBE_OP 25000
 15.2798 +# define SQLITE_MAX_VDBE_OP 250000000
 15.2799  #endif
 15.2800  
 15.2801  /*
 15.2802 @@ -10734,11 +11071,12 @@
 15.2803  ** the SQLITE_DISABLE_INTRINSIC define.
 15.2804  */
 15.2805  #if !defined(SQLITE_DISABLE_INTRINSIC)
 15.2806 -#  if defined(_MSC_VER) && _MSC_VER>=1300
 15.2807 +#  if defined(_MSC_VER) && _MSC_VER>=1400
 15.2808  #    if !defined(_WIN32_WCE)
 15.2809  #      include <intrin.h>
 15.2810  #      pragma intrinsic(_byteswap_ushort)
 15.2811  #      pragma intrinsic(_byteswap_ulong)
 15.2812 +#      pragma intrinsic(_byteswap_uint64)
 15.2813  #      pragma intrinsic(_ReadWriteBarrier)
 15.2814  #    else
 15.2815  #      include <cmnintrin.h>
 15.2816 @@ -11011,8 +11349,8 @@
 15.2817  ** This is the header file for the generic hash-table implementation
 15.2818  ** used in SQLite.
 15.2819  */
 15.2820 -#ifndef _SQLITE_HASH_H_
 15.2821 -#define _SQLITE_HASH_H_
 15.2822 +#ifndef SQLITE_HASH_H
 15.2823 +#define SQLITE_HASH_H
 15.2824  
 15.2825  /* Forward declarations of structures. */
 15.2826  typedef struct Hash Hash;
 15.2827 @@ -11092,7 +11430,7 @@
 15.2828  */
 15.2829  /* #define sqliteHashCount(H)  ((H)->count) // NOT USED */
 15.2830  
 15.2831 -#endif /* _SQLITE_HASH_H_ */
 15.2832 +#endif /* SQLITE_HASH_H */
 15.2833  
 15.2834  /************** End of hash.h ************************************************/
 15.2835  /************** Continuing where we left off in sqliteInt.h ******************/
 15.2836 @@ -11124,76 +11462,76 @@
 15.2837  #define TK_AS                              24
 15.2838  #define TK_WITHOUT                         25
 15.2839  #define TK_COMMA                           26
 15.2840 -#define TK_OR                              27
 15.2841 -#define TK_AND                             28
 15.2842 -#define TK_IS                              29
 15.2843 -#define TK_MATCH                           30
 15.2844 -#define TK_LIKE_KW                         31
 15.2845 -#define TK_BETWEEN                         32
 15.2846 -#define TK_IN                              33
 15.2847 -#define TK_ISNULL                          34
 15.2848 -#define TK_NOTNULL                         35
 15.2849 -#define TK_NE                              36
 15.2850 -#define TK_EQ                              37
 15.2851 -#define TK_GT                              38
 15.2852 -#define TK_LE                              39
 15.2853 -#define TK_LT                              40
 15.2854 -#define TK_GE                              41
 15.2855 -#define TK_ESCAPE                          42
 15.2856 -#define TK_BITAND                          43
 15.2857 -#define TK_BITOR                           44
 15.2858 -#define TK_LSHIFT                          45
 15.2859 -#define TK_RSHIFT                          46
 15.2860 -#define TK_PLUS                            47
 15.2861 -#define TK_MINUS                           48
 15.2862 -#define TK_STAR                            49
 15.2863 -#define TK_SLASH                           50
 15.2864 -#define TK_REM                             51
 15.2865 -#define TK_CONCAT                          52
 15.2866 -#define TK_COLLATE                         53
 15.2867 -#define TK_BITNOT                          54
 15.2868 -#define TK_ID                              55
 15.2869 -#define TK_INDEXED                         56
 15.2870 -#define TK_ABORT                           57
 15.2871 -#define TK_ACTION                          58
 15.2872 -#define TK_AFTER                           59
 15.2873 -#define TK_ANALYZE                         60
 15.2874 -#define TK_ASC                             61
 15.2875 -#define TK_ATTACH                          62
 15.2876 -#define TK_BEFORE                          63
 15.2877 -#define TK_BY                              64
 15.2878 -#define TK_CASCADE                         65
 15.2879 -#define TK_CAST                            66
 15.2880 -#define TK_COLUMNKW                        67
 15.2881 -#define TK_CONFLICT                        68
 15.2882 -#define TK_DATABASE                        69
 15.2883 -#define TK_DESC                            70
 15.2884 -#define TK_DETACH                          71
 15.2885 -#define TK_EACH                            72
 15.2886 -#define TK_FAIL                            73
 15.2887 -#define TK_FOR                             74
 15.2888 -#define TK_IGNORE                          75
 15.2889 -#define TK_INITIALLY                       76
 15.2890 -#define TK_INSTEAD                         77
 15.2891 -#define TK_NO                              78
 15.2892 -#define TK_KEY                             79
 15.2893 -#define TK_OF                              80
 15.2894 -#define TK_OFFSET                          81
 15.2895 -#define TK_PRAGMA                          82
 15.2896 -#define TK_RAISE                           83
 15.2897 -#define TK_RECURSIVE                       84
 15.2898 -#define TK_REPLACE                         85
 15.2899 -#define TK_RESTRICT                        86
 15.2900 -#define TK_ROW                             87
 15.2901 -#define TK_TRIGGER                         88
 15.2902 -#define TK_VACUUM                          89
 15.2903 -#define TK_VIEW                            90
 15.2904 -#define TK_VIRTUAL                         91
 15.2905 -#define TK_WITH                            92
 15.2906 -#define TK_REINDEX                         93
 15.2907 -#define TK_RENAME                          94
 15.2908 -#define TK_CTIME_KW                        95
 15.2909 -#define TK_ANY                             96
 15.2910 +#define TK_ID                              27
 15.2911 +#define TK_ABORT                           28
 15.2912 +#define TK_ACTION                          29
 15.2913 +#define TK_AFTER                           30
 15.2914 +#define TK_ANALYZE                         31
 15.2915 +#define TK_ASC                             32
 15.2916 +#define TK_ATTACH                          33
 15.2917 +#define TK_BEFORE                          34
 15.2918 +#define TK_BY                              35
 15.2919 +#define TK_CASCADE                         36
 15.2920 +#define TK_CAST                            37
 15.2921 +#define TK_COLUMNKW                        38
 15.2922 +#define TK_CONFLICT                        39
 15.2923 +#define TK_DATABASE                        40
 15.2924 +#define TK_DESC                            41
 15.2925 +#define TK_DETACH                          42
 15.2926 +#define TK_EACH                            43
 15.2927 +#define TK_FAIL                            44
 15.2928 +#define TK_FOR                             45
 15.2929 +#define TK_IGNORE                          46
 15.2930 +#define TK_INITIALLY                       47
 15.2931 +#define TK_INSTEAD                         48
 15.2932 +#define TK_LIKE_KW                         49
 15.2933 +#define TK_MATCH                           50
 15.2934 +#define TK_NO                              51
 15.2935 +#define TK_KEY                             52
 15.2936 +#define TK_OF                              53
 15.2937 +#define TK_OFFSET                          54
 15.2938 +#define TK_PRAGMA                          55
 15.2939 +#define TK_RAISE                           56
 15.2940 +#define TK_RECURSIVE                       57
 15.2941 +#define TK_REPLACE                         58
 15.2942 +#define TK_RESTRICT                        59
 15.2943 +#define TK_ROW                             60
 15.2944 +#define TK_TRIGGER                         61
 15.2945 +#define TK_VACUUM                          62
 15.2946 +#define TK_VIEW                            63
 15.2947 +#define TK_VIRTUAL                         64
 15.2948 +#define TK_WITH                            65
 15.2949 +#define TK_REINDEX                         66
 15.2950 +#define TK_RENAME                          67
 15.2951 +#define TK_CTIME_KW                        68
 15.2952 +#define TK_ANY                             69
 15.2953 +#define TK_OR                              70
 15.2954 +#define TK_AND                             71
 15.2955 +#define TK_IS                              72
 15.2956 +#define TK_BETWEEN                         73
 15.2957 +#define TK_IN                              74
 15.2958 +#define TK_ISNULL                          75
 15.2959 +#define TK_NOTNULL                         76
 15.2960 +#define TK_NE                              77
 15.2961 +#define TK_EQ                              78
 15.2962 +#define TK_GT                              79
 15.2963 +#define TK_LE                              80
 15.2964 +#define TK_LT                              81
 15.2965 +#define TK_GE                              82
 15.2966 +#define TK_ESCAPE                          83
 15.2967 +#define TK_BITAND                          84
 15.2968 +#define TK_BITOR                           85
 15.2969 +#define TK_LSHIFT                          86
 15.2970 +#define TK_RSHIFT                          87
 15.2971 +#define TK_PLUS                            88
 15.2972 +#define TK_MINUS                           89
 15.2973 +#define TK_STAR                            90
 15.2974 +#define TK_SLASH                           91
 15.2975 +#define TK_REM                             92
 15.2976 +#define TK_CONCAT                          93
 15.2977 +#define TK_COLLATE                         94
 15.2978 +#define TK_BITNOT                          95
 15.2979 +#define TK_INDEXED                         96
 15.2980  #define TK_STRING                          97
 15.2981  #define TK_JOIN_KW                         98
 15.2982  #define TK_CONSTRAINT                      99
 15.2983 @@ -11229,9 +11567,9 @@
 15.2984  #define TK_LIMIT                          129
 15.2985  #define TK_WHERE                          130
 15.2986  #define TK_INTO                           131
 15.2987 -#define TK_INTEGER                        132
 15.2988 -#define TK_FLOAT                          133
 15.2989 -#define TK_BLOB                           134
 15.2990 +#define TK_FLOAT                          132
 15.2991 +#define TK_BLOB                           133
 15.2992 +#define TK_INTEGER                        134
 15.2993  #define TK_VARIABLE                       135
 15.2994  #define TK_CASE                           136
 15.2995  #define TK_WHEN                           137
 15.2996 @@ -11255,10 +11593,13 @@
 15.2997  #define TK_UMINUS                         155
 15.2998  #define TK_UPLUS                          156
 15.2999  #define TK_REGISTER                       157
 15.3000 -#define TK_ASTERISK                       158
 15.3001 -#define TK_SPAN                           159
 15.3002 -#define TK_SPACE                          160
 15.3003 -#define TK_ILLEGAL                        161
 15.3004 +#define TK_VECTOR                         158
 15.3005 +#define TK_SELECT_COLUMN                  159
 15.3006 +#define TK_IF_NULL_ROW                    160
 15.3007 +#define TK_ASTERISK                       161
 15.3008 +#define TK_SPAN                           162
 15.3009 +#define TK_SPACE                          163
 15.3010 +#define TK_ILLEGAL                        164
 15.3011  
 15.3012  /* The token codes above must all fit in 8 bits */
 15.3013  #define TKFLG_MASK           0xff  
 15.3014 @@ -11276,6 +11617,18 @@
 15.3015  #include <stddef.h>
 15.3016  
 15.3017  /*
 15.3018 +** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY.
 15.3019 +** This allows better measurements of where memcpy() is used when running
 15.3020 +** cachegrind.  But this macro version of memcpy() is very slow so it
 15.3021 +** should not be used in production.  This is a performance measurement
 15.3022 +** hack only.
 15.3023 +*/
 15.3024 +#ifdef SQLITE_INLINE_MEMCPY
 15.3025 +# define memcpy(D,S,N) {char*xxd=(char*)(D);const char*xxs=(const char*)(S);\
 15.3026 +                        int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);}
 15.3027 +#endif
 15.3028 +
 15.3029 +/*
 15.3030  ** If compiling for a processor that lacks floating point support,
 15.3031  ** substitute integer for floating-point
 15.3032  */
 15.3033 @@ -11359,9 +11712,12 @@
 15.3034  ** pagecaches for each database connection.  A positive number is the
 15.3035  ** number of pages.  A negative number N translations means that a buffer
 15.3036  ** of -1024*N bytes is allocated and used for as many pages as it will hold.
 15.3037 +**
 15.3038 +** The default value of "20" was choosen to minimize the run-time of the
 15.3039 +** speedtest1 test program with options: --shrink-memory --reprepare
 15.3040  */
 15.3041  #ifndef SQLITE_DEFAULT_PCACHE_INITSZ
 15.3042 -# define SQLITE_DEFAULT_PCACHE_INITSZ 100
 15.3043 +# define SQLITE_DEFAULT_PCACHE_INITSZ 20
 15.3044  #endif
 15.3045  
 15.3046  /*
 15.3047 @@ -11536,32 +11892,35 @@
 15.3048  **
 15.3049  ** For best performance, an attempt is made to guess at the byte-order
 15.3050  ** using C-preprocessor macros.  If that is unsuccessful, or if
 15.3051 -** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
 15.3052 +** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
 15.3053  ** at run-time.
 15.3054  */
 15.3055 -#if (defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
 15.3056 +#ifndef SQLITE_BYTEORDER
 15.3057 +# if defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
 15.3058       defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)  ||    \
 15.3059       defined(_M_AMD64) || defined(_M_ARM)     || defined(__x86)   ||    \
 15.3060 -     defined(__arm__)) && !defined(SQLITE_RUNTIME_BYTEORDER)
 15.3061 -# define SQLITE_BYTEORDER    1234
 15.3062 +     defined(__arm__)
 15.3063 +#   define SQLITE_BYTEORDER    1234
 15.3064 +# elif defined(sparc)    || defined(__ppc__)
 15.3065 +#   define SQLITE_BYTEORDER    4321
 15.3066 +# else
 15.3067 +#   define SQLITE_BYTEORDER 0
 15.3068 +# endif
 15.3069 +#endif
 15.3070 +#if SQLITE_BYTEORDER==4321
 15.3071 +# define SQLITE_BIGENDIAN    1
 15.3072 +# define SQLITE_LITTLEENDIAN 0
 15.3073 +# define SQLITE_UTF16NATIVE  SQLITE_UTF16BE
 15.3074 +#elif SQLITE_BYTEORDER==1234
 15.3075  # define SQLITE_BIGENDIAN    0
 15.3076  # define SQLITE_LITTLEENDIAN 1
 15.3077  # define SQLITE_UTF16NATIVE  SQLITE_UTF16LE
 15.3078 -#endif
 15.3079 -#if (defined(sparc)    || defined(__ppc__))  \
 15.3080 -    && !defined(SQLITE_RUNTIME_BYTEORDER)
 15.3081 -# define SQLITE_BYTEORDER    4321
 15.3082 -# define SQLITE_BIGENDIAN    1
 15.3083 -# define SQLITE_LITTLEENDIAN 0
 15.3084 -# define SQLITE_UTF16NATIVE  SQLITE_UTF16BE
 15.3085 -#endif
 15.3086 -#if !defined(SQLITE_BYTEORDER)
 15.3087 +#else
 15.3088  # ifdef SQLITE_AMALGAMATION
 15.3089    const int sqlite3one = 1;
 15.3090  # else
 15.3091    extern const int sqlite3one;
 15.3092  # endif
 15.3093 -# define SQLITE_BYTEORDER    0     /* 0 means "unknown at compile-time" */
 15.3094  # define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0)
 15.3095  # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
 15.3096  # define SQLITE_UTF16NATIVE  (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
 15.3097 @@ -11740,8 +12099,8 @@
 15.3098    #define SQLITE_WSD const
 15.3099    #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v)))
 15.3100    #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config)
 15.3101 -SQLITE_API int SQLITE_STDCALL sqlite3_wsd_init(int N, int J);
 15.3102 -SQLITE_API void *SQLITE_STDCALL sqlite3_wsd_find(void *K, int L);
 15.3103 +SQLITE_API int sqlite3_wsd_init(int N, int J);
 15.3104 +SQLITE_API void *sqlite3_wsd_find(void *K, int L);
 15.3105  #else
 15.3106    #define SQLITE_WSD
 15.3107    #define GLOBAL(t,v) v
 15.3108 @@ -11818,6 +12177,14 @@
 15.3109  typedef struct WhereInfo WhereInfo;
 15.3110  typedef struct With With;
 15.3111  
 15.3112 +/* A VList object records a mapping between parameters/variables/wildcards
 15.3113 +** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
 15.3114 +** variable number associated with that parameter.  See the format description
 15.3115 +** on the sqlite3VListAdd() routine for more information.  A VList is really
 15.3116 +** just an array of integers.
 15.3117 +*/
 15.3118 +typedef int VList;
 15.3119 +
 15.3120  /*
 15.3121  ** Defer sourcing vdbe.h and btree.h until after the "u8" and
 15.3122  ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
 15.3123 @@ -11840,8 +12207,8 @@
 15.3124  ** subsystem.  See comments in the source code for a detailed description
 15.3125  ** of what each interface routine does.
 15.3126  */
 15.3127 -#ifndef _BTREE_H_
 15.3128 -#define _BTREE_H_
 15.3129 +#ifndef SQLITE_BTREE_H
 15.3130 +#define SQLITE_BTREE_H
 15.3131  
 15.3132  /* TODO: This definition is just included so other modules compile. It
 15.3133  ** needs to be revisited.
 15.3134 @@ -11866,6 +12233,7 @@
 15.3135  typedef struct Btree Btree;
 15.3136  typedef struct BtCursor BtCursor;
 15.3137  typedef struct BtShared BtShared;
 15.3138 +typedef struct BtreePayload BtreePayload;
 15.3139  
 15.3140  
 15.3141  SQLITE_PRIVATE int sqlite3BtreeOpen(
 15.3142 @@ -11916,7 +12284,9 @@
 15.3143  SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
 15.3144  SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
 15.3145  SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
 15.3146 +#ifndef SQLITE_OMIT_SHARED_CACHE
 15.3147  SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
 15.3148 +#endif
 15.3149  SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int);
 15.3150  
 15.3151  SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
 15.3152 @@ -12073,30 +12443,60 @@
 15.3153  SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*);
 15.3154  SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags);
 15.3155  
 15.3156 -/* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */
 15.3157 +/* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */
 15.3158  #define BTREE_SAVEPOSITION 0x02  /* Leave cursor pointing at NEXT or PREV */
 15.3159  #define BTREE_AUXDELETE    0x04  /* not the primary delete operation */
 15.3160 -
 15.3161 -SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
 15.3162 -                                  const void *pData, int nData,
 15.3163 -                                  int nZero, int bias, int seekResult);
 15.3164 +#define BTREE_APPEND       0x08  /* Insert is likely an append */
 15.3165 +
 15.3166 +/* An instance of the BtreePayload object describes the content of a single
 15.3167 +** entry in either an index or table btree.
 15.3168 +**
 15.3169 +** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
 15.3170 +** an arbitrary key and no data.  These btrees have pKey,nKey set to their
 15.3171 +** key and pData,nData,nZero set to zero.
 15.3172 +**
 15.3173 +** Table btrees (used for rowid tables) contain an integer rowid used as
 15.3174 +** the key and passed in the nKey field.  The pKey field is zero.  
 15.3175 +** pData,nData hold the content of the new entry.  nZero extra zero bytes
 15.3176 +** are appended to the end of the content when constructing the entry.
 15.3177 +**
 15.3178 +** This object is used to pass information into sqlite3BtreeInsert().  The
 15.3179 +** same information used to be passed as five separate parameters.  But placing
 15.3180 +** the information into this object helps to keep the interface more 
 15.3181 +** organized and understandable, and it also helps the resulting code to
 15.3182 +** run a little faster by using fewer registers for parameter passing.
 15.3183 +*/
 15.3184 +struct BtreePayload {
 15.3185 +  const void *pKey;       /* Key content for indexes.  NULL for tables */
 15.3186 +  sqlite3_int64 nKey;     /* Size of pKey for indexes.  PRIMARY KEY for tabs */
 15.3187 +  const void *pData;      /* Data for tables.  NULL for indexes */
 15.3188 +  sqlite3_value *aMem;    /* First of nMem value in the unpacked pKey */
 15.3189 +  u16 nMem;               /* Number of aMem[] value.  Might be zero */
 15.3190 +  int nData;              /* Size of pData.  0 if none. */
 15.3191 +  int nZero;              /* Extra zero data appended after pData,nData */
 15.3192 +};
 15.3193 +
 15.3194 +SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
 15.3195 +                       int flags, int seekResult);
 15.3196  SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
 15.3197  SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
 15.3198  SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
 15.3199  SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
 15.3200  SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
 15.3201 -SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
 15.3202 -SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
 15.3203 -SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
 15.3204 -SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
 15.3205 -SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
 15.3206 -SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
 15.3207 +SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
 15.3208 +SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
 15.3209 +SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
 15.3210 +SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
 15.3211  
 15.3212  SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
 15.3213  SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
 15.3214 -
 15.3215 +SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
 15.3216 +
 15.3217 +#ifndef SQLITE_OMIT_INCRBLOB
 15.3218 +SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
 15.3219  SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
 15.3220  SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
 15.3221 +#endif
 15.3222  SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
 15.3223  SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
 15.3224  SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask);
 15.3225 @@ -12106,6 +12506,7 @@
 15.3226  #ifndef NDEBUG
 15.3227  SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
 15.3228  #endif
 15.3229 +SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor*);
 15.3230  
 15.3231  #ifndef SQLITE_OMIT_BTREECOUNT
 15.3232  SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *, i64 *);
 15.3233 @@ -12130,11 +12531,13 @@
 15.3234  SQLITE_PRIVATE   void sqlite3BtreeEnterAll(sqlite3*);
 15.3235  SQLITE_PRIVATE   int sqlite3BtreeSharable(Btree*);
 15.3236  SQLITE_PRIVATE   void sqlite3BtreeEnterCursor(BtCursor*);
 15.3237 +SQLITE_PRIVATE   int sqlite3BtreeConnectionCount(Btree*);
 15.3238  #else
 15.3239  # define sqlite3BtreeEnter(X) 
 15.3240  # define sqlite3BtreeEnterAll(X)
 15.3241  # define sqlite3BtreeSharable(X) 0
 15.3242  # define sqlite3BtreeEnterCursor(X)
 15.3243 +# define sqlite3BtreeConnectionCount(X) 1
 15.3244  #endif
 15.3245  
 15.3246  #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
 15.3247 @@ -12159,7 +12562,7 @@
 15.3248  #endif
 15.3249  
 15.3250  
 15.3251 -#endif /* _BTREE_H_ */
 15.3252 +#endif /* SQLITE_BTREE_H */
 15.3253  
 15.3254  /************** End of btree.h ***********************************************/
 15.3255  /************** Continuing where we left off in sqliteInt.h ******************/
 15.3256 @@ -12182,8 +12585,8 @@
 15.3257  ** or VDBE.  The VDBE implements an abstract machine that runs a
 15.3258  ** simple program to access and modify the underlying database.
 15.3259  */
 15.3260 -#ifndef _SQLITE_VDBE_H_
 15.3261 -#define _SQLITE_VDBE_H_
 15.3262 +#ifndef SQLITE_VDBE_H
 15.3263 +#define SQLITE_VDBE_H
 15.3264  /* #include <stdio.h> */
 15.3265  
 15.3266  /*
 15.3267 @@ -12197,7 +12600,7 @@
 15.3268  ** The names of the following types declared in vdbeInt.h are required
 15.3269  ** for the VdbeOp definition.
 15.3270  */
 15.3271 -typedef struct Mem Mem;
 15.3272 +typedef struct sqlite3_value Mem;
 15.3273  typedef struct SubProgram SubProgram;
 15.3274  
 15.3275  /*
 15.3276 @@ -12208,8 +12611,7 @@
 15.3277  struct VdbeOp {
 15.3278    u8 opcode;          /* What operation to perform */
 15.3279    signed char p4type; /* One of the P4_xxx constants for p4 */
 15.3280 -  u8 notUsed1;
 15.3281 -  u8 p5;              /* Fifth parameter is an unsigned character */
 15.3282 +  u16 p5;             /* Fifth parameter is an unsigned 16-bit integer */
 15.3283    int p1;             /* First operand */
 15.3284    int p2;             /* Second parameter (often the jump destination) */
 15.3285    int p3;             /* The third parameter */
 15.3286 @@ -12255,7 +12657,7 @@
 15.3287    int nOp;                      /* Elements in aOp[] */
 15.3288    int nMem;                     /* Number of memory cells required */
 15.3289    int nCsr;                     /* Number of cursors required */
 15.3290 -  int nOnce;                    /* Number of OP_Once instructions */
 15.3291 +  u8 *aOnce;                    /* Array of OP_Once flags */
 15.3292    void *token;                  /* id that may be used to recursive triggers */
 15.3293    SubProgram *pNext;            /* Next sub-program already visited */
 15.3294  };
 15.3295 @@ -12278,22 +12680,21 @@
 15.3296  #define P4_NOTUSED    0   /* The P4 parameter is not used */
 15.3297  #define P4_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
 15.3298  #define P4_STATIC   (-2)  /* Pointer to a static string */
 15.3299 -#define P4_COLLSEQ  (-4)  /* P4 is a pointer to a CollSeq structure */
 15.3300 -#define P4_FUNCDEF  (-5)  /* P4 is a pointer to a FuncDef structure */
 15.3301 -#define P4_KEYINFO  (-6)  /* P4 is a pointer to a KeyInfo structure */
 15.3302 -#define P4_EXPR     (-7)  /* P4 is a pointer to an Expr tree */
 15.3303 -#define P4_MEM      (-8)  /* P4 is a pointer to a Mem*    structure */
 15.3304 +#define P4_COLLSEQ  (-3)  /* P4 is a pointer to a CollSeq structure */
 15.3305 +#define P4_FUNCDEF  (-4)  /* P4 is a pointer to a FuncDef structure */
 15.3306 +#define P4_KEYINFO  (-5)  /* P4 is a pointer to a KeyInfo structure */
 15.3307 +#define P4_EXPR     (-6)  /* P4 is a pointer to an Expr tree */
 15.3308 +#define P4_MEM      (-7)  /* P4 is a pointer to a Mem*    structure */
 15.3309  #define P4_TRANSIENT  0   /* P4 is a pointer to a transient string */
 15.3310 -#define P4_VTAB     (-10) /* P4 is a pointer to an sqlite3_vtab structure */
 15.3311 -#define P4_MPRINTF  (-11) /* P4 is a string obtained from sqlite3_mprintf() */
 15.3312 -#define P4_REAL     (-12) /* P4 is a 64-bit floating point value */
 15.3313 -#define P4_INT64    (-13) /* P4 is a 64-bit signed integer */
 15.3314 -#define P4_INT32    (-14) /* P4 is a 32-bit signed integer */
 15.3315 -#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
 15.3316 -#define P4_SUBPROGRAM  (-18) /* P4 is a pointer to a SubProgram structure */
 15.3317 -#define P4_ADVANCE  (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */
 15.3318 -#define P4_TABLE    (-20) /* P4 is a pointer to a Table structure */
 15.3319 -#define P4_FUNCCTX  (-21) /* P4 is a pointer to an sqlite3_context object */
 15.3320 +#define P4_VTAB     (-8) /* P4 is a pointer to an sqlite3_vtab structure */
 15.3321 +#define P4_REAL     (-9) /* P4 is a 64-bit floating point value */
 15.3322 +#define P4_INT64    (-10) /* P4 is a 64-bit signed integer */
 15.3323 +#define P4_INT32    (-11) /* P4 is a 32-bit signed integer */
 15.3324 +#define P4_INTARRAY (-12) /* P4 is a vector of 32-bit integers */
 15.3325 +#define P4_SUBPROGRAM  (-13) /* P4 is a pointer to a SubProgram structure */
 15.3326 +#define P4_ADVANCE  (-14) /* P4 is a pointer to BtreeNext() or BtreePrev() */
 15.3327 +#define P4_TABLE    (-15) /* P4 is a pointer to a Table structure */
 15.3328 +#define P4_FUNCCTX  (-16) /* P4 is a pointer to an sqlite3_context object */
 15.3329  
 15.3330  /* Error message codes for OP_Halt */
 15.3331  #define P5_ConstraintNotNull 1
 15.3332 @@ -12359,144 +12760,149 @@
 15.3333  #define OP_Once           20
 15.3334  #define OP_If             21
 15.3335  #define OP_IfNot          22
 15.3336 -#define OP_SeekLT         23 /* synopsis: key=r[P3@P4]                     */
 15.3337 -#define OP_SeekLE         24 /* synopsis: key=r[P3@P4]                     */
 15.3338 -#define OP_SeekGE         25 /* synopsis: key=r[P3@P4]                     */
 15.3339 -#define OP_SeekGT         26 /* synopsis: key=r[P3@P4]                     */
 15.3340 -#define OP_Or             27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
 15.3341 -#define OP_And            28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
 15.3342 -#define OP_NoConflict     29 /* synopsis: key=r[P3@P4]                     */
 15.3343 -#define OP_NotFound       30 /* synopsis: key=r[P3@P4]                     */
 15.3344 -#define OP_Found          31 /* synopsis: key=r[P3@P4]                     */
 15.3345 +#define OP_IfNullRow      23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
 15.3346 +#define OP_SeekLT         24 /* synopsis: key=r[P3@P4]                     */
 15.3347 +#define OP_SeekLE         25 /* synopsis: key=r[P3@P4]                     */
 15.3348 +#define OP_SeekGE         26 /* synopsis: key=r[P3@P4]                     */
 15.3349 +#define OP_SeekGT         27 /* synopsis: key=r[P3@P4]                     */
 15.3350 +#define OP_NoConflict     28 /* synopsis: key=r[P3@P4]                     */
 15.3351 +#define OP_NotFound       29 /* synopsis: key=r[P3@P4]                     */
 15.3352 +#define OP_Found          30 /* synopsis: key=r[P3@P4]                     */
 15.3353 +#define OP_SeekRowid      31 /* synopsis: intkey=r[P3]                     */
 15.3354  #define OP_NotExists      32 /* synopsis: intkey=r[P3]                     */
 15.3355  #define OP_Last           33
 15.3356 -#define OP_IsNull         34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
 15.3357 -#define OP_NotNull        35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
 15.3358 -#define OP_Ne             36 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
 15.3359 -#define OP_Eq             37 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
 15.3360 -#define OP_Gt             38 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
 15.3361 -#define OP_Le             39 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
 15.3362 -#define OP_Lt             40 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
 15.3363 -#define OP_Ge             41 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
 15.3364 -#define OP_SorterSort     42
 15.3365 -#define OP_BitAnd         43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
 15.3366 -#define OP_BitOr          44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
 15.3367 -#define OP_ShiftLeft      45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
 15.3368 -#define OP_ShiftRight     46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
 15.3369 -#define OP_Add            47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
 15.3370 -#define OP_Subtract       48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
 15.3371 -#define OP_Multiply       49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
 15.3372 -#define OP_Divide         50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
 15.3373 -#define OP_Remainder      51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
 15.3374 -#define OP_Concat         52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
 15.3375 -#define OP_Sort           53
 15.3376 -#define OP_BitNot         54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
 15.3377 -#define OP_Rewind         55
 15.3378 -#define OP_IdxLE          56 /* synopsis: key=r[P3@P4]                     */
 15.3379 -#define OP_IdxGT          57 /* synopsis: key=r[P3@P4]                     */
 15.3380 -#define OP_IdxLT          58 /* synopsis: key=r[P3@P4]                     */
 15.3381 -#define OP_IdxGE          59 /* synopsis: key=r[P3@P4]                     */
 15.3382 -#define OP_RowSetRead     60 /* synopsis: r[P3]=rowset(P1)                 */
 15.3383 -#define OP_RowSetTest     61 /* synopsis: if r[P3] in rowset(P1) goto P2   */
 15.3384 -#define OP_Program        62
 15.3385 -#define OP_FkIfZero       63 /* synopsis: if fkctr[P1]==0 goto P2          */
 15.3386 -#define OP_IfPos          64 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
 15.3387 -#define OP_IfNotZero      65 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
 15.3388 -#define OP_DecrJumpZero   66 /* synopsis: if (--r[P1])==0 goto P2          */
 15.3389 -#define OP_IncrVacuum     67
 15.3390 -#define OP_VNext          68
 15.3391 -#define OP_Init           69 /* synopsis: Start at P2                      */
 15.3392 -#define OP_Return         70
 15.3393 -#define OP_EndCoroutine   71
 15.3394 -#define OP_HaltIfNull     72 /* synopsis: if r[P3]=null halt               */
 15.3395 -#define OP_Halt           73
 15.3396 -#define OP_Integer        74 /* synopsis: r[P2]=P1                         */
 15.3397 -#define OP_Int64          75 /* synopsis: r[P2]=P4                         */
 15.3398 -#define OP_String         76 /* synopsis: r[P2]='P4' (len=P1)              */
 15.3399 -#define OP_Null           77 /* synopsis: r[P2..P3]=NULL                   */
 15.3400 -#define OP_SoftNull       78 /* synopsis: r[P1]=NULL                       */
 15.3401 -#define OP_Blob           79 /* synopsis: r[P2]=P4 (len=P1)                */
 15.3402 -#define OP_Variable       80 /* synopsis: r[P2]=parameter(P1,P4)           */
 15.3403 -#define OP_Move           81 /* synopsis: r[P2@P3]=r[P1@P3]                */
 15.3404 -#define OP_Copy           82 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
 15.3405 -#define OP_SCopy          83 /* synopsis: r[P2]=r[P1]                      */
 15.3406 -#define OP_IntCopy        84 /* synopsis: r[P2]=r[P1]                      */
 15.3407 -#define OP_ResultRow      85 /* synopsis: output=r[P1@P2]                  */
 15.3408 -#define OP_CollSeq        86
 15.3409 -#define OP_Function0      87 /* synopsis: r[P3]=func(r[P2@P5])             */
 15.3410 -#define OP_Function       88 /* synopsis: r[P3]=func(r[P2@P5])             */
 15.3411 -#define OP_AddImm         89 /* synopsis: r[P1]=r[P1]+P2                   */
 15.3412 -#define OP_RealAffinity   90
 15.3413 -#define OP_Cast           91 /* synopsis: affinity(r[P1])                  */
 15.3414 -#define OP_Permutation    92
 15.3415 -#define OP_Compare        93 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
 15.3416 -#define OP_Column         94 /* synopsis: r[P3]=PX                         */
 15.3417 -#define OP_Affinity       95 /* synopsis: affinity(r[P1@P2])               */
 15.3418 -#define OP_MakeRecord     96 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
 15.3419 +#define OP_IfSmaller      34
 15.3420 +#define OP_SorterSort     35
 15.3421 +#define OP_Sort           36
 15.3422 +#define OP_Rewind         37
 15.3423 +#define OP_IdxLE          38 /* synopsis: key=r[P3@P4]                     */
 15.3424 +#define OP_IdxGT          39 /* synopsis: key=r[P3@P4]                     */
 15.3425 +#define OP_IdxLT          40 /* synopsis: key=r[P3@P4]                     */
 15.3426 +#define OP_IdxGE          41 /* synopsis: key=r[P3@P4]                     */
 15.3427 +#define OP_RowSetRead     42 /* synopsis: r[P3]=rowset(P1)                 */
 15.3428 +#define OP_RowSetTest     43 /* synopsis: if r[P3] in rowset(P1) goto P2   */
 15.3429 +#define OP_Program        44
 15.3430 +#define OP_FkIfZero       45 /* synopsis: if fkctr[P1]==0 goto P2          */
 15.3431 +#define OP_IfPos          46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
 15.3432 +#define OP_IfNotZero      47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
 15.3433 +#define OP_DecrJumpZero   48 /* synopsis: if (--r[P1])==0 goto P2          */
 15.3434 +#define OP_IncrVacuum     49
 15.3435 +#define OP_VNext          50
 15.3436 +#define OP_Init           51 /* synopsis: Start at P2                      */
 15.3437 +#define OP_Return         52
 15.3438 +#define OP_EndCoroutine   53
 15.3439 +#define OP_HaltIfNull     54 /* synopsis: if r[P3]=null halt               */
 15.3440 +#define OP_Halt           55
 15.3441 +#define OP_Integer        56 /* synopsis: r[P2]=P1                         */
 15.3442 +#define OP_Int64          57 /* synopsis: r[P2]=P4                         */
 15.3443 +#define OP_String         58 /* synopsis: r[P2]='P4' (len=P1)              */
 15.3444 +#define OP_Null           59 /* synopsis: r[P2..P3]=NULL                   */
 15.3445 +#define OP_SoftNull       60 /* synopsis: r[P1]=NULL                       */
 15.3446 +#define OP_Blob           61 /* synopsis: r[P2]=P4 (len=P1)                */
 15.3447 +#define OP_Variable       62 /* synopsis: r[P2]=parameter(P1,P4)           */
 15.3448 +#define OP_Move           63 /* synopsis: r[P2@P3]=r[P1@P3]                */
 15.3449 +#define OP_Copy           64 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
 15.3450 +#define OP_SCopy          65 /* synopsis: r[P2]=r[P1]                      */
 15.3451 +#define OP_IntCopy        66 /* synopsis: r[P2]=r[P1]                      */
 15.3452 +#define OP_ResultRow      67 /* synopsis: output=r[P1@P2]                  */
 15.3453 +#define OP_CollSeq        68
 15.3454 +#define OP_Function0      69 /* synopsis: r[P3]=func(r[P2@P5])             */
 15.3455 +#define OP_Or             70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
 15.3456 +#define OP_And            71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
 15.3457 +#define OP_Function       72 /* synopsis: r[P3]=func(r[P2@P5])             */
 15.3458 +#define OP_AddImm         73 /* synopsis: r[P1]=r[P1]+P2                   */
 15.3459 +#define OP_RealAffinity   74
 15.3460 +#define OP_IsNull         75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
 15.3461 +#define OP_NotNull        76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
 15.3462 +#define OP_Ne             77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1]   */
 15.3463 +#define OP_Eq             78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1]   */
 15.3464 +#define OP_Gt             79 /* same as TK_GT, synopsis: IF r[P3]>r[P1]    */
 15.3465 +#define OP_Le             80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1]   */
 15.3466 +#define OP_Lt             81 /* same as TK_LT, synopsis: IF r[P3]<r[P1]    */
 15.3467 +#define OP_Ge             82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1]   */
 15.3468 +#define OP_ElseNotEq      83 /* same as TK_ESCAPE                          */
 15.3469 +#define OP_BitAnd         84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
 15.3470 +#define OP_BitOr          85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
 15.3471 +#define OP_ShiftLeft      86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
 15.3472 +#define OP_ShiftRight     87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
 15.3473 +#define OP_Add            88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
 15.3474 +#define OP_Subtract       89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
 15.3475 +#define OP_Multiply       90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
 15.3476 +#define OP_Divide         91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
 15.3477 +#define OP_Remainder      92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
 15.3478 +#define OP_Concat         93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
 15.3479 +#define OP_Cast           94 /* synopsis: affinity(r[P1])                  */
 15.3480 +#define OP_BitNot         95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
 15.3481 +#define OP_Permutation    96
 15.3482  #define OP_String8        97 /* same as TK_STRING, synopsis: r[P2]='P4'    */
 15.3483 -#define OP_Count          98 /* synopsis: r[P2]=count()                    */
 15.3484 -#define OP_ReadCookie     99
 15.3485 -#define OP_SetCookie     100
 15.3486 -#define OP_ReopenIdx     101 /* synopsis: root=P2 iDb=P3                   */
 15.3487 -#define OP_OpenRead      102 /* synopsis: root=P2 iDb=P3                   */
 15.3488 -#define OP_OpenWrite     103 /* synopsis: root=P2 iDb=P3                   */
 15.3489 -#define OP_OpenAutoindex 104 /* synopsis: nColumn=P2                       */
 15.3490 -#define OP_OpenEphemeral 105 /* synopsis: nColumn=P2                       */
 15.3491 -#define OP_SorterOpen    106
 15.3492 -#define OP_SequenceTest  107 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
 15.3493 -#define OP_OpenPseudo    108 /* synopsis: P3 columns in r[P2]              */
 15.3494 -#define OP_Close         109
 15.3495 -#define OP_ColumnsUsed   110
 15.3496 -#define OP_Sequence      111 /* synopsis: r[P2]=cursor[P1].ctr++           */
 15.3497 -#define OP_NewRowid      112 /* synopsis: r[P2]=rowid                      */
 15.3498 -#define OP_Insert        113 /* synopsis: intkey=r[P3] data=r[P2]          */
 15.3499 -#define OP_InsertInt     114 /* synopsis: intkey=P3 data=r[P2]             */
 15.3500 -#define OP_Delete        115
 15.3501 -#define OP_ResetCount    116
 15.3502 -#define OP_SorterCompare 117 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
 15.3503 -#define OP_SorterData    118 /* synopsis: r[P2]=data                       */
 15.3504 -#define OP_RowKey        119 /* synopsis: r[P2]=key                        */
 15.3505 -#define OP_RowData       120 /* synopsis: r[P2]=data                       */
 15.3506 -#define OP_Rowid         121 /* synopsis: r[P2]=rowid                      */
 15.3507 -#define OP_NullRow       122
 15.3508 -#define OP_SorterInsert  123
 15.3509 -#define OP_IdxInsert     124 /* synopsis: key=r[P2]                        */
 15.3510 -#define OP_IdxDelete     125 /* synopsis: key=r[P2@P3]                     */
 15.3511 -#define OP_Seek          126 /* synopsis: Move P3 to P1.rowid              */
 15.3512 -#define OP_IdxRowid      127 /* synopsis: r[P2]=rowid                      */
 15.3513 -#define OP_Destroy       128
 15.3514 -#define OP_Clear         129
 15.3515 -#define OP_ResetSorter   130
 15.3516 -#define OP_CreateIndex   131 /* synopsis: r[P2]=root iDb=P1                */
 15.3517 -#define OP_CreateTable   132 /* synopsis: r[P2]=root iDb=P1                */
 15.3518 -#define OP_Real          133 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
 15.3519 -#define OP_ParseSchema   134
 15.3520 -#define OP_LoadAnalysis  135
 15.3521 -#define OP_DropTable     136
 15.3522 -#define OP_DropIndex     137
 15.3523 -#define OP_DropTrigger   138
 15.3524 -#define OP_IntegrityCk   139
 15.3525 -#define OP_RowSetAdd     140 /* synopsis: rowset(P1)=r[P2]                 */
 15.3526 -#define OP_Param         141
 15.3527 -#define OP_FkCounter     142 /* synopsis: fkctr[P1]+=P2                    */
 15.3528 -#define OP_MemMax        143 /* synopsis: r[P1]=max(r[P1],r[P2])           */
 15.3529 -#define OP_OffsetLimit   144 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
 15.3530 -#define OP_AggStep0      145 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 15.3531 -#define OP_AggStep       146 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 15.3532 -#define OP_AggFinal      147 /* synopsis: accum=r[P1] N=P2                 */
 15.3533 -#define OP_Expire        148
 15.3534 -#define OP_TableLock     149 /* synopsis: iDb=P1 root=P2 write=P3          */
 15.3535 -#define OP_VBegin        150
 15.3536 -#define OP_VCreate       151
 15.3537 -#define OP_VDestroy      152
 15.3538 -#define OP_VOpen         153
 15.3539 -#define OP_VColumn       154 /* synopsis: r[P3]=vcolumn(P2)                */
 15.3540 -#define OP_VRename       155
 15.3541 -#define OP_Pagecount     156
 15.3542 -#define OP_MaxPgcnt      157
 15.3543 -#define OP_CursorHint    158
 15.3544 -#define OP_Noop          159
 15.3545 -#define OP_Explain       160
 15.3546 +#define OP_Compare        98 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
 15.3547 +#define OP_Column         99 /* synopsis: r[P3]=PX                         */
 15.3548 +#define OP_Affinity      100 /* synopsis: affinity(r[P1@P2])               */
 15.3549 +#define OP_MakeRecord    101 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
 15.3550 +#define OP_Count         102 /* synopsis: r[P2]=count()                    */
 15.3551 +#define OP_ReadCookie    103
 15.3552 +#define OP_SetCookie     104
 15.3553 +#define OP_ReopenIdx     105 /* synopsis: root=P2 iDb=P3                   */
 15.3554 +#define OP_OpenRead      106 /* synopsis: root=P2 iDb=P3                   */
 15.3555 +#define OP_OpenWrite     107 /* synopsis: root=P2 iDb=P3                   */
 15.3556 +#define OP_OpenDup       108
 15.3557 +#define OP_OpenAutoindex 109 /* synopsis: nColumn=P2                       */
 15.3558 +#define OP_OpenEphemeral 110 /* synopsis: nColumn=P2                       */
 15.3559 +#define OP_SorterOpen    111
 15.3560 +#define OP_SequenceTest  112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
 15.3561 +#define OP_OpenPseudo    113 /* synopsis: P3 columns in r[P2]              */
 15.3562 +#define OP_Close         114
 15.3563 +#define OP_ColumnsUsed   115
 15.3564 +#define OP_Sequence      116 /* synopsis: r[P2]=cursor[P1].ctr++           */
 15.3565 +#define OP_NewRowid      117 /* synopsis: r[P2]=rowid                      */
 15.3566 +#define OP_Insert        118 /* synopsis: intkey=r[P3] data=r[P2]          */
 15.3567 +#define OP_InsertInt     119 /* synopsis: intkey=P3 data=r[P2]             */
 15.3568 +#define OP_Delete        120
 15.3569 +#define OP_ResetCount    121
 15.3570 +#define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
 15.3571 +#define OP_SorterData    123 /* synopsis: r[P2]=data                       */
 15.3572 +#define OP_RowData       124 /* synopsis: r[P2]=data                       */
 15.3573 +#define OP_Rowid         125 /* synopsis: r[P2]=rowid                      */
 15.3574 +#define OP_NullRow       126
 15.3575 +#define OP_SorterInsert  127 /* synopsis: key=r[P2]                        */
 15.3576 +#define OP_IdxInsert     128 /* synopsis: key=r[P2]                        */
 15.3577 +#define OP_IdxDelete     129 /* synopsis: key=r[P2@P3]                     */
 15.3578 +#define OP_Seek          130 /* synopsis: Move P3 to P1.rowid              */
 15.3579 +#define OP_IdxRowid      131 /* synopsis: r[P2]=rowid                      */
 15.3580 +#define OP_Real          132 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
 15.3581 +#define OP_Destroy       133
 15.3582 +#define OP_Clear         134
 15.3583 +#define OP_ResetSorter   135
 15.3584 +#define OP_CreateIndex   136 /* synopsis: r[P2]=root iDb=P1                */
 15.3585 +#define OP_CreateTable   137 /* synopsis: r[P2]=root iDb=P1                */
 15.3586 +#define OP_SqlExec       138
 15.3587 +#define OP_ParseSchema   139
 15.3588 +#define OP_LoadAnalysis  140
 15.3589 +#define OP_DropTable     141
 15.3590 +#define OP_DropIndex     142
 15.3591 +#define OP_DropTrigger   143
 15.3592 +#define OP_IntegrityCk   144
 15.3593 +#define OP_RowSetAdd     145 /* synopsis: rowset(P1)=r[P2]                 */
 15.3594 +#define OP_Param         146
 15.3595 +#define OP_FkCounter     147 /* synopsis: fkctr[P1]+=P2                    */
 15.3596 +#define OP_MemMax        148 /* synopsis: r[P1]=max(r[P1],r[P2])           */
 15.3597 +#define OP_OffsetLimit   149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
 15.3598 +#define OP_AggStep0      150 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 15.3599 +#define OP_AggStep       151 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 15.3600 +#define OP_AggFinal      152 /* synopsis: accum=r[P1] N=P2                 */
 15.3601 +#define OP_Expire        153
 15.3602 +#define OP_TableLock     154 /* synopsis: iDb=P1 root=P2 write=P3          */
 15.3603 +#define OP_VBegin        155
 15.3604 +#define OP_VCreate       156
 15.3605 +#define OP_VDestroy      157
 15.3606 +#define OP_VOpen         158
 15.3607 +#define OP_VColumn       159 /* synopsis: r[P3]=vcolumn(P2)                */
 15.3608 +#define OP_VRename       160
 15.3609 +#define OP_Pagecount     161
 15.3610 +#define OP_MaxPgcnt      162
 15.3611 +#define OP_CursorHint    163
 15.3612 +#define OP_Noop          164
 15.3613 +#define OP_Explain       165
 15.3614  
 15.3615  /* Properties such as "out2" or "jump" that are specified in
 15.3616  ** comments following the "case" for each opcode in the vdbe.c
 15.3617 @@ -12511,25 +12917,25 @@
 15.3618  #define OPFLG_INITIALIZER {\
 15.3619  /*   0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
 15.3620  /*   8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
 15.3621 -/*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
 15.3622 -/*  24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
 15.3623 -/*  32 */ 0x09, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
 15.3624 -/*  40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
 15.3625 -/*  48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
 15.3626 -/*  56 */ 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01,\
 15.3627 -/*  64 */ 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x02, 0x02,\
 15.3628 -/*  72 */ 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10,\
 15.3629 -/*  80 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
 15.3630 -/*  88 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
 15.3631 -/*  96 */ 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
 15.3632 -/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
 15.3633 -/* 112 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 15.3634 -/* 120 */ 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
 15.3635 -/* 128 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
 15.3636 -/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
 15.3637 -/* 144 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 15.3638 -/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
 15.3639 -/* 160 */ 0x00,}
 15.3640 +/*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
 15.3641 +/*  24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
 15.3642 +/*  32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
 15.3643 +/*  40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
 15.3644 +/*  48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
 15.3645 +/*  56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
 15.3646 +/*  64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
 15.3647 +/*  72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
 15.3648 +/*  80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
 15.3649 +/*  88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
 15.3650 +/*  96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
 15.3651 +/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 15.3652 +/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
 15.3653 +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
 15.3654 +/* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
 15.3655 +/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 15.3656 +/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
 15.3657 +/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 15.3658 +/* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,}
 15.3659  
 15.3660  /* The sqlite3P2Values() routine is able to run faster if it knows
 15.3661  ** the value of the largest JUMP opcode.  The smaller the maximum
 15.3662 @@ -12537,7 +12943,7 @@
 15.3663  ** generated this include file strives to group all JUMP opcodes
 15.3664  ** together near the beginning of the list.
 15.3665  */
 15.3666 -#define SQLITE_MX_JUMP_OPCODE  69  /* Maximum JUMP opcode */
 15.3667 +#define SQLITE_MX_JUMP_OPCODE  83  /* Maximum JUMP opcode */
 15.3668  
 15.3669  /************** End of opcodes.h *********************************************/
 15.3670  /************** Continuing where we left off in vdbe.h ***********************/
 15.3671 @@ -12560,8 +12966,10 @@
 15.3672  SQLITE_PRIVATE void sqlite3VdbeEndCoroutine(Vdbe*,int);
 15.3673  #if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
 15.3674  SQLITE_PRIVATE   void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N);
 15.3675 +SQLITE_PRIVATE   void sqlite3VdbeVerifyNoResultRow(Vdbe *p);
 15.3676  #else
 15.3677  # define sqlite3VdbeVerifyNoMallocRequired(A,B)
 15.3678 +# define sqlite3VdbeVerifyNoResultRow(A)
 15.3679  #endif
 15.3680  SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
 15.3681  SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
 15.3682 @@ -12569,11 +12977,12 @@
 15.3683  SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
 15.3684  SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
 15.3685  SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
 15.3686 -SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
 15.3687 +SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
 15.3688  SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
 15.3689  SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
 15.3690  SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
 15.3691  SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
 15.3692 +SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
 15.3693  SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
 15.3694  SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
 15.3695  SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
 15.3696 @@ -12609,7 +13018,7 @@
 15.3697  SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
 15.3698  SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
 15.3699  SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
 15.3700 -SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
 15.3701 +SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
 15.3702  
 15.3703  typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
 15.3704  SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
 15.3705 @@ -12684,7 +13093,7 @@
 15.3706  # define sqlite3VdbeScanStatus(a,b,c,d,e)
 15.3707  #endif
 15.3708  
 15.3709 -#endif
 15.3710 +#endif /* SQLITE_VDBE_H */
 15.3711  
 15.3712  /************** End of vdbe.h ************************************************/
 15.3713  /************** Continuing where we left off in sqliteInt.h ******************/
 15.3714 @@ -12706,8 +13115,8 @@
 15.3715  ** at a time and provides a journal for rollback.
 15.3716  */
 15.3717  
 15.3718 -#ifndef _PAGER_H_
 15.3719 -#define _PAGER_H_
 15.3720 +#ifndef SQLITE_PAGER_H
 15.3721 +#define SQLITE_PAGER_H
 15.3722  
 15.3723  /*
 15.3724  ** Default maximum size for persistent journal files. A negative 
 15.3725 @@ -12814,7 +13223,7 @@
 15.3726    int,
 15.3727    void(*)(DbPage*)
 15.3728  );
 15.3729 -SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager);
 15.3730 +SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3*);
 15.3731  SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
 15.3732  
 15.3733  /* Functions used to configure a Pager object. */
 15.3734 @@ -12865,15 +13274,21 @@
 15.3735  SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
 15.3736  
 15.3737  #ifndef SQLITE_OMIT_WAL
 15.3738 -SQLITE_PRIVATE   int sqlite3PagerCheckpoint(Pager *pPager, int, int*, int*);
 15.3739 +SQLITE_PRIVATE   int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*);
 15.3740  SQLITE_PRIVATE   int sqlite3PagerWalSupported(Pager *pPager);
 15.3741  SQLITE_PRIVATE   int sqlite3PagerWalCallback(Pager *pPager);
 15.3742  SQLITE_PRIVATE   int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
 15.3743 -SQLITE_PRIVATE   int sqlite3PagerCloseWal(Pager *pPager);
 15.3744 +SQLITE_PRIVATE   int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
 15.3745 +# ifdef SQLITE_DIRECT_OVERFLOW_READ
 15.3746 +SQLITE_PRIVATE   int sqlite3PagerUseWal(Pager *pPager, Pgno);
 15.3747 +# endif
 15.3748  # ifdef SQLITE_ENABLE_SNAPSHOT
 15.3749  SQLITE_PRIVATE   int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot);
 15.3750  SQLITE_PRIVATE   int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot);
 15.3751 +SQLITE_PRIVATE   int sqlite3PagerSnapshotRecover(Pager *pPager);
 15.3752  # endif
 15.3753 +#else
 15.3754 +# define sqlite3PagerUseWal(x,y) 0
 15.3755  #endif
 15.3756  
 15.3757  #ifdef SQLITE_ENABLE_ZIPVFS
 15.3758 @@ -12895,7 +13310,7 @@
 15.3759  SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
 15.3760  SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
 15.3761  SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
 15.3762 -SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *);
 15.3763 +SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*);
 15.3764  SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
 15.3765  
 15.3766  /* Functions used to truncate the database file. */
 15.3767 @@ -12922,7 +13337,7 @@
 15.3768  # define enable_simulated_io_errors()
 15.3769  #endif
 15.3770  
 15.3771 -#endif /* _PAGER_H_ */
 15.3772 +#endif /* SQLITE_PAGER_H */
 15.3773  
 15.3774  /************** End of pager.h ***********************************************/
 15.3775  /************** Continuing where we left off in sqliteInt.h ******************/
 15.3776 @@ -13160,8 +13575,8 @@
 15.3777  ** This file contains pre-processor directives related to operating system
 15.3778  ** detection and/or setup.
 15.3779  */
 15.3780 -#ifndef _OS_SETUP_H_
 15.3781 -#define _OS_SETUP_H_
 15.3782 +#ifndef SQLITE_OS_SETUP_H
 15.3783 +#define SQLITE_OS_SETUP_H
 15.3784  
 15.3785  /*
 15.3786  ** Figure out if we are dealing with Unix, Windows, or some other operating
 15.3787 @@ -13201,7 +13616,7 @@
 15.3788  #  endif
 15.3789  #endif
 15.3790  
 15.3791 -#endif /* _OS_SETUP_H_ */
 15.3792 +#endif /* SQLITE_OS_SETUP_H */
 15.3793  
 15.3794  /************** End of os_setup.h ********************************************/
 15.3795  /************** Continuing where we left off in os.h *************************/
 15.3796 @@ -13492,7 +13907,7 @@
 15.3797  ** and the one-based values are used internally.
 15.3798  */
 15.3799  #ifndef SQLITE_DEFAULT_SYNCHRONOUS
 15.3800 -# define SQLITE_DEFAULT_SYNCHRONOUS (PAGER_SYNCHRONOUS_FULL-1)
 15.3801 +# define SQLITE_DEFAULT_SYNCHRONOUS 2
 15.3802  #endif
 15.3803  #ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS
 15.3804  # define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS
 15.3805 @@ -13506,7 +13921,7 @@
 15.3806  ** databases may be attached.
 15.3807  */
 15.3808  struct Db {
 15.3809 -  char *zName;         /* Name of this database */
 15.3810 +  char *zDbSName;      /* Name of this database. (schema name, not filename) */
 15.3811    Btree *pBt;          /* The B*Tree structure for this database file */
 15.3812    u8 safety_level;     /* How aggressive at syncing data to disk */
 15.3813    u8 bSyncSet;         /* True if "PRAGMA synchronous=N" has been run */
 15.3814 @@ -13658,6 +14073,15 @@
 15.3815                                 const char*);
 15.3816  #endif
 15.3817  
 15.3818 +#ifndef SQLITE_OMIT_DEPRECATED
 15.3819 +/* This is an extra SQLITE_TRACE macro that indicates "legacy" tracing
 15.3820 +** in the style of sqlite3_trace()
 15.3821 +*/
 15.3822 +#define SQLITE_TRACE_LEGACY  0x80
 15.3823 +#else
 15.3824 +#define SQLITE_TRACE_LEGACY  0
 15.3825 +#endif /* SQLITE_OMIT_DEPRECATED */
 15.3826 +
 15.3827  
 15.3828  /*
 15.3829  ** Each database connection is an instance of the following structure.
 15.3830 @@ -13687,6 +14111,9 @@
 15.3831    u8 suppressErr;               /* Do not issue error messages if true */
 15.3832    u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */
 15.3833    u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */
 15.3834 +  u8 mTrace;                    /* zero or more SQLITE_TRACE flags */
 15.3835 +  u8 skipBtreeMutex;            /* True if no shared-cache backends */
 15.3836 +  u8 nSqlExec;                  /* Number of pending OP_SqlExec opcodes */
 15.3837    int nextPagesize;             /* Pagesize after VACUUM if >0 */
 15.3838    u32 magic;                    /* Magic number for detect library misuse */
 15.3839    int nChange;                  /* Value returned by sqlite3_changes() */
 15.3840 @@ -13707,7 +14134,7 @@
 15.3841    int nVDestroy;                /* Number of active OP_VDestroy operations */
 15.3842    int nExtension;               /* Number of loaded extensions */
 15.3843    void **aExtension;            /* Array of shared library handles */
 15.3844 -  void (*xTrace)(void*,const char*);        /* Trace function */
 15.3845 +  int (*xTrace)(u32,void*,void*,void*);     /* Trace function */
 15.3846    void *pTraceArg;                          /* Argument to the trace function */
 15.3847    void (*xProfile)(void*,const char*,u64);  /* Profiling function */
 15.3848    void *pProfileArg;                        /* Argument to profile function */
 15.3849 @@ -13834,6 +14261,7 @@
 15.3850  #define SQLITE_Vacuum         0x10000000  /* Currently in a VACUUM */
 15.3851  #define SQLITE_CellSizeCk     0x20000000  /* Check btree cell sizes on load */
 15.3852  #define SQLITE_Fts3Tokenizer  0x40000000  /* Enable fts3_tokenizer(2) */
 15.3853 +#define SQLITE_NoCkptOnClose  0x80000000  /* No checkpoint on close()/DETACH */
 15.3854  
 15.3855  
 15.3856  /*
 15.3857 @@ -13859,13 +14287,8 @@
 15.3858  /*
 15.3859  ** Macros for testing whether or not optimizations are enabled or disabled.
 15.3860  */
 15.3861 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.3862  #define OptimizationDisabled(db, mask)  (((db)->dbOptFlags&(mask))!=0)
 15.3863  #define OptimizationEnabled(db, mask)   (((db)->dbOptFlags&(mask))==0)
 15.3864 -#else
 15.3865 -#define OptimizationDisabled(db, mask)  0
 15.3866 -#define OptimizationEnabled(db, mask)   1
 15.3867 -#endif
 15.3868  
 15.3869  /*
 15.3870  ** Return true if it OK to factor constant expressions into the initialization
 15.3871 @@ -13956,6 +14379,7 @@
 15.3872  #define SQLITE_FUNC_MINMAX   0x1000 /* True for min() and max() aggregates */
 15.3873  #define SQLITE_FUNC_SLOCHNG  0x2000 /* "Slow Change". Value constant during a
 15.3874                                      ** single query - might change over time */
 15.3875 +#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
 15.3876  
 15.3877  /*
 15.3878  ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
 15.3879 @@ -14132,6 +14556,7 @@
 15.3880  ** operator is NULL.  It is added to certain comparison operators to
 15.3881  ** prove that the operands are always NOT NULL.
 15.3882  */
 15.3883 +#define SQLITE_KEEPNULL     0x08  /* Used by vector == or <> */
 15.3884  #define SQLITE_JUMPIFNULL   0x10  /* jumps if either operand is NULL */
 15.3885  #define SQLITE_STOREP2      0x20  /* Store result in reg[P2] rather than jump */
 15.3886  #define SQLITE_NULLEQ       0x80  /* NULL=NULL */
 15.3887 @@ -14203,15 +14628,15 @@
 15.3888    ExprList *pCheck;    /* All CHECK constraints */
 15.3889                         /*   ... also used as column name list in a VIEW */
 15.3890    int tnum;            /* Root BTree page for this table */
 15.3891 +  u32 nTabRef;         /* Number of pointers to this Table */
 15.3892 +  u32 tabFlags;        /* Mask of TF_* values */
 15.3893    i16 iPKey;           /* If not negative, use aCol[iPKey] as the rowid */
 15.3894    i16 nCol;            /* Number of columns in this table */
 15.3895 -  u16 nRef;            /* Number of pointers to this Table */
 15.3896    LogEst nRowLogEst;   /* Estimated rows in table - from sqlite_stat1 table */
 15.3897    LogEst szTabRow;     /* Estimated size of each table row in bytes */
 15.3898  #ifdef SQLITE_ENABLE_COSTMULT
 15.3899    LogEst costMult;     /* Cost multiplier for using this table */
 15.3900  #endif
 15.3901 -  u8 tabFlags;         /* Mask of TF_* values */
 15.3902    u8 keyConf;          /* What to do in case of uniqueness conflict on iPKey */
 15.3903  #ifndef SQLITE_OMIT_ALTERTABLE
 15.3904    int addColOffset;    /* Offset in CREATE TABLE stmt to add a new column */
 15.3905 @@ -14235,15 +14660,17 @@
 15.3906  ** the TF_OOOHidden attribute would apply in this case.  Such tables require
 15.3907  ** special handling during INSERT processing.
 15.3908  */
 15.3909 -#define TF_Readonly        0x01    /* Read-only system table */
 15.3910 -#define TF_Ephemeral       0x02    /* An ephemeral table */
 15.3911 -#define TF_HasPrimaryKey   0x04    /* Table has a primary key */
 15.3912 -#define TF_Autoincrement   0x08    /* Integer primary key is autoincrement */
 15.3913 -#define TF_Virtual         0x10    /* Is a virtual table */
 15.3914 -#define TF_WithoutRowid    0x20    /* No rowid.  PRIMARY KEY is the key */
 15.3915 -#define TF_NoVisibleRowid  0x40    /* No user-visible "rowid" column */
 15.3916 -#define TF_OOOHidden       0x80    /* Out-of-Order hidden columns */
 15.3917 -
 15.3918 +#define TF_Readonly        0x0001    /* Read-only system table */
 15.3919 +#define TF_Ephemeral       0x0002    /* An ephemeral table */
 15.3920 +#define TF_HasPrimaryKey   0x0004    /* Table has a primary key */
 15.3921 +#define TF_Autoincrement   0x0008    /* Integer primary key is autoincrement */
 15.3922 +#define TF_HasStat1        0x0010    /* nRowLogEst set from sqlite_stat1 */
 15.3923 +#define TF_WithoutRowid    0x0020    /* No rowid.  PRIMARY KEY is the key */
 15.3924 +#define TF_NoVisibleRowid  0x0040    /* No user-visible "rowid" column */
 15.3925 +#define TF_OOOHidden       0x0080    /* Out-of-Order hidden columns */
 15.3926 +#define TF_StatsUsed       0x0100    /* Query planner decisions affected by
 15.3927 +                                     ** Index.aiRowLogEst[] values */
 15.3928 +#define TF_HasNotNull      0x0200    /* Contains NOT NULL constraints */
 15.3929  
 15.3930  /*
 15.3931  ** Test to see whether or not a table is a virtual table.  This is
 15.3932 @@ -14251,7 +14678,7 @@
 15.3933  ** table support is omitted from the build.
 15.3934  */
 15.3935  #ifndef SQLITE_OMIT_VIRTUALTABLE
 15.3936 -#  define IsVirtual(X)      (((X)->tabFlags & TF_Virtual)!=0)
 15.3937 +#  define IsVirtual(X)      ((X)->nModuleArg)
 15.3938  #else
 15.3939  #  define IsVirtual(X)      0
 15.3940  #endif
 15.3941 @@ -14486,6 +14913,7 @@
 15.3942    unsigned isResized:1;    /* True if resizeIndexObject() has been called */
 15.3943    unsigned isCovering:1;   /* True if this is a covering index */
 15.3944    unsigned noSkipScan:1;   /* Do not try to use skip-scan if true */
 15.3945 +  unsigned hasStat1:1;     /* aiRowLogEst values come from sqlite_stat1 */
 15.3946  #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
 15.3947    int nSample;             /* Number of elements in aSample[] */
 15.3948    int nSampleCol;          /* Size of IndexSample.anEq[] and so on */
 15.3949 @@ -14696,9 +15124,11 @@
 15.3950    int iTable;            /* TK_COLUMN: cursor number of table holding column
 15.3951                           ** TK_REGISTER: register number
 15.3952                           ** TK_TRIGGER: 1 -> new, 0 -> old
 15.3953 -                         ** EP_Unlikely:  134217728 times likelihood */
 15.3954 +                         ** EP_Unlikely:  134217728 times likelihood
 15.3955 +                         ** TK_SELECT: 1st register of result vector */
 15.3956    ynVar iColumn;         /* TK_COLUMN: column index.  -1 for rowid.
 15.3957 -                         ** TK_VARIABLE: variable number (always >= 1). */
 15.3958 +                         ** TK_VARIABLE: variable number (always >= 1).
 15.3959 +                         ** TK_SELECT_COLUMN: column of the result vector */
 15.3960    i16 iAgg;              /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
 15.3961    i16 iRightJoinTable;   /* If EP_FromJoin, the right table of the join */
 15.3962    u8 op2;                /* TK_REGISTER: original value of Expr.op
 15.3963 @@ -14734,6 +15164,7 @@
 15.3964  #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
 15.3965  #define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
 15.3966  #define EP_Alias     0x400000 /* Is an alias for a result set column */
 15.3967 +#define EP_Leaf      0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
 15.3968  
 15.3969  /*
 15.3970  ** Combinations of two or more EP_* flags
 15.3971 @@ -14792,8 +15223,9 @@
 15.3972  */
 15.3973  struct ExprList {
 15.3974    int nExpr;             /* Number of expressions on the list */
 15.3975 +  int nAlloc;            /* Number of a[] slots allocated */
 15.3976    struct ExprList_item { /* For each expression in the list */
 15.3977 -    Expr *pExpr;            /* The list of expressions */
 15.3978 +    Expr *pExpr;            /* The parse tree for this expression */
 15.3979      char *zName;            /* Token associated with this expression */
 15.3980      char *zSpan;            /* Original text of the expression */
 15.3981      u8 sortOrder;           /* 1 for DESC or 0 for ASC */
 15.3982 @@ -14807,7 +15239,7 @@
 15.3983        } x;
 15.3984        int iConstExprReg;      /* Register in which Expr value is cached */
 15.3985      } u;
 15.3986 -  } *a;                  /* Alloc a power of two greater or equal to nExpr */
 15.3987 +  } a[1];                  /* One slot for each expression in the list */
 15.3988  };
 15.3989  
 15.3990  /*
 15.3991 @@ -14902,7 +15334,7 @@
 15.3992      int regReturn;    /* Register holding return address of addrFillSub */
 15.3993      int regResult;    /* Registers holding results of a co-routine */
 15.3994      struct {
 15.3995 -      u8 jointype;      /* Type of join between this able and the previous */
 15.3996 +      u8 jointype;      /* Type of join between this table and the previous */
 15.3997        unsigned notIndexed :1;    /* True if there is a NOT INDEXED clause */
 15.3998        unsigned isIndexedBy :1;   /* True if there is an INDEXED BY clause */
 15.3999        unsigned isTabFunc :1;     /* True if table-valued-function syntax */
 15.4000 @@ -14948,19 +15380,20 @@
 15.4001  #define WHERE_ORDERBY_MIN      0x0001 /* ORDER BY processing for min() func */
 15.4002  #define WHERE_ORDERBY_MAX      0x0002 /* ORDER BY processing for max() func */
 15.4003  #define WHERE_ONEPASS_DESIRED  0x0004 /* Want to do one-pass UPDATE/DELETE */
 15.4004 -#define WHERE_DUPLICATES_OK    0x0008 /* Ok to return a row more than once */
 15.4005 -#define WHERE_OMIT_OPEN_CLOSE  0x0010 /* Table cursors are already open */
 15.4006 -#define WHERE_FORCE_TABLE      0x0020 /* Do not use an index-only search */
 15.4007 -#define WHERE_ONETABLE_ONLY    0x0040 /* Only code the 1st table in pTabList */
 15.4008 -#define WHERE_NO_AUTOINDEX     0x0080 /* Disallow automatic indexes */
 15.4009 -#define WHERE_GROUPBY          0x0100 /* pOrderBy is really a GROUP BY */
 15.4010 -#define WHERE_DISTINCTBY       0x0200 /* pOrderby is really a DISTINCT clause */
 15.4011 -#define WHERE_WANT_DISTINCT    0x0400 /* All output needs to be distinct */
 15.4012 -#define WHERE_SORTBYGROUP      0x0800 /* Support sqlite3WhereIsSorted() */
 15.4013 -#define WHERE_REOPEN_IDX       0x1000 /* Try to use OP_ReopenIdx */
 15.4014 -#define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */
 15.4015 -#define WHERE_USE_LIMIT        0x4000 /* There is a constant LIMIT clause */
 15.4016 -#define WHERE_SEEK_TABLE       0x8000 /* Do not defer seeks on main table */
 15.4017 +#define WHERE_ONEPASS_MULTIROW 0x0008 /* ONEPASS is ok with multiple rows */
 15.4018 +#define WHERE_DUPLICATES_OK    0x0010 /* Ok to return a row more than once */
 15.4019 +#define WHERE_OR_SUBCLAUSE     0x0020 /* Processing a sub-WHERE as part of
 15.4020 +                                      ** the OR optimization  */
 15.4021 +#define WHERE_GROUPBY          0x0040 /* pOrderBy is really a GROUP BY */
 15.4022 +#define WHERE_DISTINCTBY       0x0080 /* pOrderby is really a DISTINCT clause */
 15.4023 +#define WHERE_WANT_DISTINCT    0x0100 /* All output needs to be distinct */
 15.4024 +#define WHERE_SORTBYGROUP      0x0200 /* Support sqlite3WhereIsSorted() */
 15.4025 +#define WHERE_SEEK_TABLE       0x0400 /* Do not defer seeks on main table */
 15.4026 +#define WHERE_ORDERBY_LIMIT    0x0800 /* ORDERBY+LIMIT on the inner loop */
 15.4027 +#define WHERE_SEEK_UNIQ_TABLE  0x1000 /* Do not defer seeks if unique */
 15.4028 +                        /*     0x2000    not currently used */
 15.4029 +#define WHERE_USE_LIMIT        0x4000 /* Use the LIMIT in cost estimates */
 15.4030 +                        /*     0x8000    not currently used */
 15.4031  
 15.4032  /* Allowed return values from sqlite3WhereIsDistinct()
 15.4033  */
 15.4034 @@ -15178,7 +15611,7 @@
 15.4035  */
 15.4036  struct SelectDest {
 15.4037    u8 eDest;            /* How to dispose of the results.  On of SRT_* above. */
 15.4038 -  char affSdst;        /* Affinity used when eDest==SRT_Set */
 15.4039 +  char *zAffSdst;      /* Affinity used when eDest==SRT_Set */
 15.4040    int iSDParm;         /* A parameter used by the eDest disposal method */
 15.4041    int iSdst;           /* Base register where results are written */
 15.4042    int nSdst;           /* Number of registers allocated */
 15.4043 @@ -15284,36 +15717,23 @@
 15.4044    u8 okConstFactor;    /* OK to factor out constants */
 15.4045    u8 disableLookaside; /* Number of times lookaside has been disabled */
 15.4046    u8 nColCache;        /* Number of entries in aColCache[] */
 15.4047 -  int aTempReg[8];     /* Holding area for temporary registers */
 15.4048    int nRangeReg;       /* Size of the temporary register block */
 15.4049    int iRangeReg;       /* First register in temporary register block */
 15.4050    int nErr;            /* Number of errors seen */
 15.4051    int nTab;            /* Number of previously allocated VDBE cursors */
 15.4052    int nMem;            /* Number of memory cells used so far */
 15.4053 -  int nSet;            /* Number of sets used so far */
 15.4054 -  int nOnce;           /* Number of OP_Once instructions so far */
 15.4055    int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */
 15.4056    int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
 15.4057 -  int iFixedOp;        /* Never back out opcodes iFixedOp-1 or earlier */
 15.4058    int ckBase;          /* Base register of data during check constraints */
 15.4059    int iSelfTab;        /* Table of an index whose exprs are being coded */
 15.4060    int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
 15.4061    int iCacheCnt;       /* Counter used to generate aColCache[].lru values */
 15.4062    int nLabel;          /* Number of labels used */
 15.4063    int *aLabel;         /* Space to hold the labels */
 15.4064 -  struct yColCache {
 15.4065 -    int iTable;           /* Table cursor number */
 15.4066 -    i16 iColumn;          /* Table column number */
 15.4067 -    u8 tempReg;           /* iReg is a temp register that needs to be freed */
 15.4068 -    int iLevel;           /* Nesting level */
 15.4069 -    int iReg;             /* Reg with value of this column. 0 means none. */
 15.4070 -    int lru;              /* Least recently used entry has the smallest value */
 15.4071 -  } aColCache[SQLITE_N_COLCACHE];  /* One for each column cache entry */
 15.4072    ExprList *pConstExpr;/* Constant expressions */
 15.4073    Token constraintName;/* Name of the constraint currently being parsed */
 15.4074    yDbMask writeMask;   /* Start a write transaction on these databases */
 15.4075    yDbMask cookieMask;  /* Bitmask of schema verified databases */
 15.4076 -  int cookieValue[SQLITE_MAX_ATTACHED+2];  /* Values of cookies to verify */
 15.4077    int regRowid;        /* Register holding rowid of CREATE TABLE entry */
 15.4078    int regRoot;         /* Register holding root page number for new objects */
 15.4079    int nMaxArg;         /* Max args passed to user function by sub-program */
 15.4080 @@ -15326,8 +15746,6 @@
 15.4081    TableLock *aTableLock; /* Required table locks for shared-cache mode */
 15.4082  #endif
 15.4083    AutoincInfo *pAinc;  /* Information about AUTOINCREMENT counters */
 15.4084 -
 15.4085 -  /* Information used while coding trigger programs. */
 15.4086    Parse *pToplevel;    /* Parse structure for main program (or NULL) */
 15.4087    Table *pTriggerTab;  /* Table triggers are being coded for */
 15.4088    int addrCrTab;       /* Address of OP_CreateTable opcode on CREATE TABLE */
 15.4089 @@ -15338,35 +15756,50 @@
 15.4090    u8 eOrconf;          /* Default ON CONFLICT policy for trigger steps */
 15.4091    u8 disableTriggers;  /* True to disable triggers */
 15.4092  
 15.4093 +  /**************************************************************************
 15.4094 +  ** Fields above must be initialized to zero.  The fields that follow,
 15.4095 +  ** down to the beginning of the recursive section, do not need to be
 15.4096 +  ** initialized as they will be set before being used.  The boundary is
 15.4097 +  ** determined by offsetof(Parse,aColCache).
 15.4098 +  **************************************************************************/
 15.4099 +
 15.4100 +  struct yColCache {
 15.4101 +    int iTable;           /* Table cursor number */
 15.4102 +    i16 iColumn;          /* Table column number */
 15.4103 +    u8 tempReg;           /* iReg is a temp register that needs to be freed */
 15.4104 +    int iLevel;           /* Nesting level */
 15.4105 +    int iReg;             /* Reg with value of this column. 0 means none. */
 15.4106 +    int lru;              /* Least recently used entry has the smallest value */
 15.4107 +  } aColCache[SQLITE_N_COLCACHE];  /* One for each column cache entry */
 15.4108 +  int aTempReg[8];        /* Holding area for temporary registers */
 15.4109 +  Token sNameToken;       /* Token with unqualified schema object name */
 15.4110 +
 15.4111    /************************************************************************
 15.4112    ** Above is constant between recursions.  Below is reset before and after
 15.4113    ** each recursion.  The boundary between these two regions is determined
 15.4114 -  ** using offsetof(Parse,nVar) so the nVar field must be the first field
 15.4115 -  ** in the recursive region.
 15.4116 +  ** using offsetof(Parse,sLastToken) so the sLastToken field must be the
 15.4117 +  ** first field in the recursive region.
 15.4118    ************************************************************************/
 15.4119  
 15.4120 +  Token sLastToken;       /* The last token parsed */
 15.4121    ynVar nVar;               /* Number of '?' variables seen in the SQL so far */
 15.4122 -  int nzVar;                /* Number of available slots in azVar[] */
 15.4123    u8 iPkSortOrder;          /* ASC or DESC for INTEGER PRIMARY KEY */
 15.4124    u8 explain;               /* True if the EXPLAIN flag is found on the query */
 15.4125  #ifndef SQLITE_OMIT_VIRTUALTABLE
 15.4126    u8 declareVtab;           /* True if inside sqlite3_declare_vtab() */
 15.4127    int nVtabLock;            /* Number of virtual tables to lock */
 15.4128  #endif
 15.4129 -  int nAlias;               /* Number of aliased result set columns */
 15.4130    int nHeight;              /* Expression tree height of current sub-select */
 15.4131  #ifndef SQLITE_OMIT_EXPLAIN
 15.4132    int iSelectId;            /* ID of current select for EXPLAIN output */
 15.4133    int iNextSelectId;        /* Next available select ID for EXPLAIN output */
 15.4134  #endif
 15.4135 -  char **azVar;             /* Pointers to names of parameters */
 15.4136 +  VList *pVList;            /* Mapping between variable names and numbers */
 15.4137    Vdbe *pReprepare;         /* VM being reprepared (sqlite3Reprepare()) */
 15.4138    const char *zTail;        /* All SQL text past the last semicolon parsed */
 15.4139    Table *pNewTable;         /* A table being constructed by CREATE TABLE */
 15.4140    Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */
 15.4141    const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
 15.4142 -  Token sNameToken;         /* Token with unqualified schema object name */
 15.4143 -  Token sLastToken;         /* The last token parsed */
 15.4144  #ifndef SQLITE_OMIT_VIRTUALTABLE
 15.4145    Token sArg;               /* Complete text of a module argument */
 15.4146    Table **apVtabLock;       /* Pointer to virtual tables needing locking */
 15.4147 @@ -15378,6 +15811,14 @@
 15.4148  };
 15.4149  
 15.4150  /*
 15.4151 +** Sizes and pointers of various parts of the Parse object.
 15.4152 +*/
 15.4153 +#define PARSE_HDR_SZ offsetof(Parse,aColCache) /* Recursive part w/o aColCache*/
 15.4154 +#define PARSE_RECURSE_SZ offsetof(Parse,sLastToken)    /* Recursive part */
 15.4155 +#define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
 15.4156 +#define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ)  /* Pointer to tail */
 15.4157 +
 15.4158 +/*
 15.4159  ** Return true if currently inside an sqlite3_declare_vtab() call.
 15.4160  */
 15.4161  #ifdef SQLITE_OMIT_VIRTUALTABLE
 15.4162 @@ -15410,13 +15851,11 @@
 15.4163  #define OPFLAG_NCHANGE       0x01    /* OP_Insert: Set to update db->nChange */
 15.4164                                       /* Also used in P2 (not P5) of OP_Delete */
 15.4165  #define OPFLAG_EPHEM         0x01    /* OP_Column: Ephemeral output is ok */
 15.4166 -#define OPFLAG_LASTROWID     0x02    /* Set to update db->lastRowid */
 15.4167 +#define OPFLAG_LASTROWID     0x20    /* Set to update db->lastRowid */
 15.4168  #define OPFLAG_ISUPDATE      0x04    /* This OP_Insert is an sql UPDATE */
 15.4169  #define OPFLAG_APPEND        0x08    /* This is likely to be an append */
 15.4170  #define OPFLAG_USESEEKRESULT 0x10    /* Try to avoid a seek in BtreeInsert() */
 15.4171 -#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
 15.4172  #define OPFLAG_ISNOOP        0x40    /* OP_Delete does pre-update-hook only */
 15.4173 -#endif
 15.4174  #define OPFLAG_LENGTHARG     0x40    /* OP_Column only used for length() */
 15.4175  #define OPFLAG_TYPEOFARG     0x80    /* OP_Column only used for typeof() */
 15.4176  #define OPFLAG_BULKCSR       0x01    /* OP_Open** used to open bulk cursor */
 15.4177 @@ -15424,7 +15863,7 @@
 15.4178  #define OPFLAG_FORDELETE     0x08    /* OP_Open should use BTREE_FORDELETE */
 15.4179  #define OPFLAG_P2ISREG       0x10    /* P2 to OP_Open** is a register number */
 15.4180  #define OPFLAG_PERMUTE       0x01    /* OP_Compare: use the permutation */
 15.4181 -#define OPFLAG_SAVEPOSITION  0x02    /* OP_Delete: keep cursor position */
 15.4182 +#define OPFLAG_SAVEPOSITION  0x02    /* OP_Delete/Insert: save cursor pos */
 15.4183  #define OPFLAG_AUXDELETE     0x04    /* OP_Delete: index in a DELETE op */
 15.4184  
 15.4185  /*
 15.4186 @@ -15621,10 +16060,11 @@
 15.4187    void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx);  /* Callback */
 15.4188    void *pVdbeBranchArg;                                     /* 1st argument */
 15.4189  #endif
 15.4190 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.4191 +#ifndef SQLITE_UNTESTABLE
 15.4192    int (*xTestCallback)(int);        /* Invoked by sqlite3FaultSim() */
 15.4193  #endif
 15.4194    int bLocaltimeFault;              /* True to fail localtime() calls */
 15.4195 +  int iOnceResetThreshold;          /* When to reset OP_Once counters */
 15.4196  };
 15.4197  
 15.4198  /*
 15.4199 @@ -15656,13 +16096,17 @@
 15.4200    int walkerDepth;                          /* Number of subqueries */
 15.4201    u8 eCode;                                 /* A small processing code */
 15.4202    union {                                   /* Extra data for callback */
 15.4203 -    NameContext *pNC;                          /* Naming context */
 15.4204 -    int n;                                     /* A counter */
 15.4205 -    int iCur;                                  /* A cursor number */
 15.4206 -    SrcList *pSrcList;                         /* FROM clause */
 15.4207 -    struct SrcCount *pSrcCount;                /* Counting column references */
 15.4208 -    struct CCurHint *pCCurHint;                /* Used by codeCursorHint() */
 15.4209 -    int *aiCol;                                /* array of column indexes */
 15.4210 +    NameContext *pNC;                         /* Naming context */
 15.4211 +    int n;                                    /* A counter */
 15.4212 +    int iCur;                                 /* A cursor number */
 15.4213 +    SrcList *pSrcList;                        /* FROM clause */
 15.4214 +    struct SrcCount *pSrcCount;               /* Counting column references */
 15.4215 +    struct CCurHint *pCCurHint;               /* Used by codeCursorHint() */
 15.4216 +    int *aiCol;                               /* array of column indexes */
 15.4217 +    struct IdxCover *pIdxCover;               /* Check for index coverage */
 15.4218 +    struct IdxExprTrans *pIdxTrans;           /* Convert indexed expr to column */
 15.4219 +    ExprList *pGroupBy;                       /* GROUP BY clause */
 15.4220 +    struct HavingToWhereCtx *pHavingCtx;      /* HAVING to WHERE clause ctx */
 15.4221    } u;
 15.4222  };
 15.4223  
 15.4224 @@ -15816,6 +16260,7 @@
 15.4225  SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
 15.4226  SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
 15.4227  SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
 15.4228 +SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
 15.4229  SQLITE_PRIVATE int sqlite3MallocSize(void*);
 15.4230  SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
 15.4231  SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
 15.4232 @@ -15823,7 +16268,7 @@
 15.4233  SQLITE_PRIVATE void *sqlite3PageMalloc(int);
 15.4234  SQLITE_PRIVATE void sqlite3PageFree(void*);
 15.4235  SQLITE_PRIVATE void sqlite3MemSetDefault(void);
 15.4236 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.4237 +#ifndef SQLITE_UNTESTABLE
 15.4238  SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
 15.4239  #endif
 15.4240  SQLITE_PRIVATE int sqlite3HeapNearlyFull(void);
 15.4241 @@ -15846,12 +16291,16 @@
 15.4242  # define sqlite3StackFree(D,P)       sqlite3DbFree(D,P)
 15.4243  #endif
 15.4244  
 15.4245 +/* Do not allow both MEMSYS5 and MEMSYS3 to be defined together.  If they
 15.4246 +** are, disable MEMSYS3
 15.4247 +*/
 15.4248 +#ifdef SQLITE_ENABLE_MEMSYS5
 15.4249 +SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
 15.4250 +#undef SQLITE_ENABLE_MEMSYS3
 15.4251 +#endif
 15.4252  #ifdef SQLITE_ENABLE_MEMSYS3
 15.4253  SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
 15.4254  #endif
 15.4255 -#ifdef SQLITE_ENABLE_MEMSYS5
 15.4256 -SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
 15.4257 -#endif
 15.4258  
 15.4259  
 15.4260  #ifndef SQLITE_MUTEX_OMIT
 15.4261 @@ -15905,6 +16354,7 @@
 15.4262  
 15.4263  #if defined(SQLITE_DEBUG)
 15.4264  SQLITE_PRIVATE   void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
 15.4265 +SQLITE_PRIVATE   void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
 15.4266  SQLITE_PRIVATE   void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
 15.4267  SQLITE_PRIVATE   void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
 15.4268  SQLITE_PRIVATE   void sqlite3TreeViewWith(TreeView*, const With*, u8);
 15.4269 @@ -15929,13 +16379,14 @@
 15.4270  SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
 15.4271  SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
 15.4272  SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
 15.4273 -SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
 15.4274 +SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
 15.4275  SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
 15.4276  SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
 15.4277  SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
 15.4278 -SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
 15.4279 +SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
 15.4280  SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
 15.4281  SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
 15.4282 +SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
 15.4283  SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
 15.4284  SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
 15.4285  SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
 15.4286 @@ -15944,6 +16395,9 @@
 15.4287  SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
 15.4288  SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
 15.4289  SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
 15.4290 +#ifndef SQLITE_OMIT_VIRTUALTABLE
 15.4291 +SQLITE_PRIVATE Module *sqlite3PragmaVtabRegister(sqlite3*,const char *zName);
 15.4292 +#endif
 15.4293  SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
 15.4294  SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
 15.4295  SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
 15.4296 @@ -15971,9 +16425,8 @@
 15.4297  SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
 15.4298                      sqlite3_vfs**,char**,char **);
 15.4299  SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
 15.4300 -SQLITE_PRIVATE int sqlite3CodeOnce(Parse *);
 15.4301 -
 15.4302 -#ifdef SQLITE_OMIT_BUILTIN_TEST
 15.4303 +
 15.4304 +#ifdef SQLITE_UNTESTABLE
 15.4305  # define sqlite3FaultSim(X) SQLITE_OK
 15.4306  #else
 15.4307  SQLITE_PRIVATE   int sqlite3FaultSim(int);
 15.4308 @@ -15986,7 +16439,7 @@
 15.4309  SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*);
 15.4310  SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*);
 15.4311  SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec*);
 15.4312 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.4313 +#ifndef SQLITE_UNTESTABLE
 15.4314  SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int,int*);
 15.4315  #endif
 15.4316  
 15.4317 @@ -16033,8 +16486,8 @@
 15.4318  SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
 15.4319  SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
 15.4320  SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**);
 15.4321 -SQLITE_PRIVATE Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
 15.4322 -                          Expr*, int, int);
 15.4323 +SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
 15.4324 +                          Expr*, int, int, u8);
 15.4325  SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
 15.4326  SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
 15.4327  SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
 15.4328 @@ -16053,6 +16506,7 @@
 15.4329  SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
 15.4330  SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
 15.4331  SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
 15.4332 +SQLITE_PRIVATE int sqlite3WhereOrderedInnerLoop(WhereInfo*);
 15.4333  SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
 15.4334  SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
 15.4335  SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
 15.4336 @@ -16074,7 +16528,7 @@
 15.4337  SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
 15.4338  SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
 15.4339  SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
 15.4340 -SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
 15.4341 +SQLITE_PRIVATE int sqlite3ExprCodeAtInit(Parse*, Expr*, int);
 15.4342  SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
 15.4343  SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
 15.4344  SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
 15.4345 @@ -16082,26 +16536,31 @@
 15.4346  #define SQLITE_ECEL_DUP      0x01  /* Deep, not shallow copies */
 15.4347  #define SQLITE_ECEL_FACTOR   0x02  /* Factor out constant terms */
 15.4348  #define SQLITE_ECEL_REF      0x04  /* Use ExprList.u.x.iOrderByCol */
 15.4349 +#define SQLITE_ECEL_OMITREF  0x08  /* Omit if ExprList.u.x.iOrderByCol */
 15.4350  SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
 15.4351  SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
 15.4352  SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
 15.4353  SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
 15.4354 -SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
 15.4355 -SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
 15.4356 +#define LOCATE_VIEW    0x01
 15.4357 +#define LOCATE_NOERR   0x02
 15.4358 +SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
 15.4359 +SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
 15.4360  SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
 15.4361  SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
 15.4362  SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
 15.4363 -SQLITE_PRIVATE void sqlite3Vacuum(Parse*);
 15.4364 -SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*);
 15.4365 +SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*);
 15.4366 +SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int);
 15.4367  SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
 15.4368  SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
 15.4369 +SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
 15.4370  SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
 15.4371  SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
 15.4372  SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
 15.4373  SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
 15.4374 +SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
 15.4375  SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
 15.4376  SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
 15.4377 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.4378 +#ifndef SQLITE_UNTESTABLE
 15.4379  SQLITE_PRIVATE void sqlite3PrngSaveState(void);
 15.4380  SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
 15.4381  #endif
 15.4382 @@ -16117,6 +16576,7 @@
 15.4383  SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
 15.4384  SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
 15.4385  SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
 15.4386 +SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
 15.4387  SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
 15.4388  #ifdef SQLITE_ENABLE_CURSOR_HINTS
 15.4389  SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
 15.4390 @@ -16132,6 +16592,11 @@
 15.4391  SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int);
 15.4392  SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
 15.4393                                       u8,u8,int,int*,int*);
 15.4394 +#ifdef SQLITE_ENABLE_NULL_TRIM
 15.4395 +SQLITE_PRIVATE   void sqlite3SetMakeRecordP5(Vdbe*,Table*);
 15.4396 +#else
 15.4397 +# define sqlite3SetMakeRecordP5(A,B)
 15.4398 +#endif
 15.4399  SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
 15.4400  SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*);
 15.4401  SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
 15.4402 @@ -16238,6 +16703,9 @@
 15.4403      defined(SQLITE_EXPLAIN_ESTIMATED_ROWS)
 15.4404  SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst);
 15.4405  #endif
 15.4406 +SQLITE_PRIVATE VList *sqlite3VListAdd(sqlite3*,VList*,const char*,int,int);
 15.4407 +SQLITE_PRIVATE const char *sqlite3VListNumToName(VList*,int);
 15.4408 +SQLITE_PRIVATE int sqlite3VListNameToNum(VList*,const char*,int);
 15.4409  
 15.4410  /*
 15.4411  ** Routines to read and write variable-length integers.  These used to
 15.4412 @@ -16267,6 +16735,7 @@
 15.4413  SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
 15.4414  SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
 15.4415  SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
 15.4416 +SQLITE_PRIVATE char sqlite3TableColumnAffinity(Table*,int);
 15.4417  SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
 15.4418  SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
 15.4419  SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
 15.4420 @@ -16332,7 +16801,7 @@
 15.4421  SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
 15.4422  SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
 15.4423  SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*);
 15.4424 -SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *, int, int);
 15.4425 +SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr *, int, int);
 15.4426  SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
 15.4427  SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
 15.4428  SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
 15.4429 @@ -16387,19 +16856,29 @@
 15.4430  SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *);
 15.4431  SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
 15.4432  
 15.4433 +#ifndef SQLITE_OMIT_SUBQUERY
 15.4434 +SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse*, Expr*);
 15.4435 +#else
 15.4436 +# define sqlite3ExprCheckIN(x,y) SQLITE_OK
 15.4437 +#endif
 15.4438 +
 15.4439  #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
 15.4440  SQLITE_PRIVATE void sqlite3AnalyzeFunctions(void);
 15.4441 -SQLITE_PRIVATE int sqlite3Stat4ProbeSetValue(Parse*,Index*,UnpackedRecord**,Expr*,u8,int,int*);
 15.4442 +SQLITE_PRIVATE int sqlite3Stat4ProbeSetValue(
 15.4443 +    Parse*,Index*,UnpackedRecord**,Expr*,int,int,int*);
 15.4444  SQLITE_PRIVATE int sqlite3Stat4ValueFromExpr(Parse*, Expr*, u8, sqlite3_value**);
 15.4445  SQLITE_PRIVATE void sqlite3Stat4ProbeFree(UnpackedRecord*);
 15.4446  SQLITE_PRIVATE int sqlite3Stat4Column(sqlite3*, const void*, int, int, sqlite3_value**);
 15.4447 +SQLITE_PRIVATE char sqlite3IndexColumnAffinity(sqlite3*, Index*, int);
 15.4448  #endif
 15.4449  
 15.4450  /*
 15.4451  ** The interface to the LEMON-generated parser
 15.4452  */
 15.4453 -SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64));
 15.4454 -SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
 15.4455 +#ifndef SQLITE_AMALGAMATION
 15.4456 +SQLITE_PRIVATE   void *sqlite3ParserAlloc(void*(*)(u64));
 15.4457 +SQLITE_PRIVATE   void sqlite3ParserFree(void*, void(*)(void*));
 15.4458 +#endif
 15.4459  SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
 15.4460  #ifdef YYTRACKMAXSTACKDEPTH
 15.4461  SQLITE_PRIVATE   int sqlite3ParserStackPeak(void*);
 15.4462 @@ -16445,6 +16924,13 @@
 15.4463  SQLITE_PRIVATE    int sqlite3VtabSavepoint(sqlite3 *, int, int);
 15.4464  SQLITE_PRIVATE    void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
 15.4465  SQLITE_PRIVATE    VTable *sqlite3GetVTable(sqlite3*, Table*);
 15.4466 +SQLITE_PRIVATE    Module *sqlite3VtabCreateModule(
 15.4467 +     sqlite3*,
 15.4468 +     const char*,
 15.4469 +     const sqlite3_module*,
 15.4470 +     void*,
 15.4471 +     void(*)(void*)
 15.4472 +   );
 15.4473  #  define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
 15.4474  #endif
 15.4475  SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
 15.4476 @@ -16502,6 +16988,7 @@
 15.4477    #define sqlite3FkDropTable(a,b,c)
 15.4478    #define sqlite3FkOldmask(a,b)         0
 15.4479    #define sqlite3FkRequired(a,b,c,d)    0
 15.4480 +  #define sqlite3FkReferences(a)        0
 15.4481  #endif
 15.4482  #ifndef SQLITE_OMIT_FOREIGN_KEY
 15.4483  SQLITE_PRIVATE   void sqlite3FkDelete(sqlite3 *, Table*);
 15.4484 @@ -16520,10 +17007,10 @@
 15.4485  
 15.4486  /*
 15.4487  ** The interface to the code in fault.c used for identifying "benign"
 15.4488 -** malloc failures. This is only present if SQLITE_OMIT_BUILTIN_TEST
 15.4489 +** malloc failures. This is only present if SQLITE_UNTESTABLE
 15.4490  ** is not defined.
 15.4491  */
 15.4492 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.4493 +#ifndef SQLITE_UNTESTABLE
 15.4494  SQLITE_PRIVATE   void sqlite3BeginBenignMalloc(void);
 15.4495  SQLITE_PRIVATE   void sqlite3EndBenignMalloc(void);
 15.4496  #else
 15.4497 @@ -16545,7 +17032,7 @@
 15.4498  #define IN_INDEX_NOOP_OK     0x0001  /* OK to return IN_INDEX_NOOP */
 15.4499  #define IN_INDEX_MEMBERSHIP  0x0002  /* IN operator used for membership test */
 15.4500  #define IN_INDEX_LOOP        0x0004  /* IN operator used as a loop */
 15.4501 -SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*);
 15.4502 +SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*);
 15.4503  
 15.4504  SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
 15.4505  SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
 15.4506 @@ -16650,7 +17137,13 @@
 15.4507  SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3*);
 15.4508  #endif
 15.4509  
 15.4510 -#endif /* _SQLITEINT_H_ */
 15.4511 +SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr);
 15.4512 +SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr);
 15.4513 +SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr*, int);
 15.4514 +SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int);
 15.4515 +SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*);
 15.4516 +
 15.4517 +#endif /* SQLITEINT_H */
 15.4518  
 15.4519  /************** End of sqliteInt.h *******************************************/
 15.4520  /************** Begin file global.c ******************************************/
 15.4521 @@ -16735,16 +17228,13 @@
 15.4522  **
 15.4523  **   (x & ~(map[x]&0x20))
 15.4524  **
 15.4525 -** Standard function tolower() is implemented using the sqlite3UpperToLower[]
 15.4526 +** The equivalent of tolower() is implemented using the sqlite3UpperToLower[]
 15.4527  ** array. tolower() is used more often than toupper() by SQLite.
 15.4528  **
 15.4529 -** Bit 0x40 is set if the character non-alphanumeric and can be used in an 
 15.4530 +** Bit 0x40 is set if the character is non-alphanumeric and can be used in an 
 15.4531  ** SQLite identifier.  Identifiers are alphanumerics, "_", "$", and any
 15.4532  ** non-ASCII UTF character. Hence the test for whether or not a character is
 15.4533  ** part of an identifier is 0x46.
 15.4534 -**
 15.4535 -** SQLite's versions are identical to the standard versions assuming a
 15.4536 -** locale of "C". They are implemented as macros in sqliteInt.h.
 15.4537  */
 15.4538  #ifdef SQLITE_ASCII
 15.4539  SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
 15.4540 @@ -16796,9 +17286,16 @@
 15.4541  ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
 15.4542  ** disabled. The default value may be changed by compiling with the
 15.4543  ** SQLITE_USE_URI symbol defined.
 15.4544 +**
 15.4545 +** URI filenames are enabled by default if SQLITE_HAS_CODEC is
 15.4546 +** enabled.
 15.4547  */
 15.4548  #ifndef SQLITE_USE_URI
 15.4549 -# define  SQLITE_USE_URI 0
 15.4550 +# ifdef SQLITE_HAS_CODEC
 15.4551 +#  define SQLITE_USE_URI 1
 15.4552 +# else
 15.4553 +#  define SQLITE_USE_URI 0
 15.4554 +# endif
 15.4555  #endif
 15.4556  
 15.4557  /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
 15.4558 @@ -16817,7 +17314,7 @@
 15.4559  #endif
 15.4560  
 15.4561  /* Statement journals spill to disk when their size exceeds the following
 15.4562 -** threashold (in bytes). 0 means that statement journals are created and
 15.4563 +** threshold (in bytes). 0 means that statement journals are created and
 15.4564  ** written to disk immediately (the default behavior for SQLite versions
 15.4565  ** before 3.12.0).  -1 means always keep the entire statement journal in
 15.4566  ** memory.  (The statement journal is also always held entirely in memory
 15.4567 @@ -16829,6 +17326,19 @@
 15.4568  #endif
 15.4569  
 15.4570  /*
 15.4571 +** The default lookaside-configuration, the format "SZ,N".  SZ is the
 15.4572 +** number of bytes in each lookaside slot (should be a multiple of 8)
 15.4573 +** and N is the number of slots.  The lookaside-configuration can be
 15.4574 +** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
 15.4575 +** or at run-time for an individual database connection using
 15.4576 +** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
 15.4577 +*/
 15.4578 +#ifndef SQLITE_DEFAULT_LOOKASIDE
 15.4579 +# define SQLITE_DEFAULT_LOOKASIDE 1200,100
 15.4580 +#endif
 15.4581 +
 15.4582 +
 15.4583 +/*
 15.4584  ** The following singleton contains the global configuration for
 15.4585  ** the SQLite library.
 15.4586  */
 15.4587 @@ -16840,8 +17350,7 @@
 15.4588     SQLITE_ALLOW_COVERING_INDEX_SCAN,   /* bUseCis */
 15.4589     0x7ffffffe,                /* mxStrlen */
 15.4590     0,                         /* neverCorrupt */
 15.4591 -   128,                       /* szLookaside */
 15.4592 -   500,                       /* nLookaside */
 15.4593 +   SQLITE_DEFAULT_LOOKASIDE,  /* szLookaside, nLookaside */
 15.4594     SQLITE_STMTJRNL_SPILL,     /* nStmtSpill */
 15.4595     {0,0,0,0,0,0,0,0},         /* m */
 15.4596     {0,0,0,0,0,0,0,0,0},       /* mutex */
 15.4597 @@ -16878,10 +17387,11 @@
 15.4598     0,                         /* xVdbeBranch */
 15.4599     0,                         /* pVbeBranchArg */
 15.4600  #endif
 15.4601 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.4602 +#ifndef SQLITE_UNTESTABLE
 15.4603     0,                         /* xTestCallback */
 15.4604  #endif
 15.4605 -   0                          /* bLocaltimeFault */
 15.4606 +   0,                         /* bLocaltimeFault */
 15.4607 +   0x7ffffffe                 /* iOnceResetThreshold */
 15.4608  };
 15.4609  
 15.4610  /*
 15.4611 @@ -16904,7 +17414,7 @@
 15.4612  ** The value of the "pending" byte must be 0x40000000 (1 byte past the
 15.4613  ** 1-gibabyte boundary) in a compatible database.  SQLite never uses
 15.4614  ** the database page that contains the pending byte.  It never attempts
 15.4615 -** to read or write that page.  The pending byte page is set assign
 15.4616 +** to read or write that page.  The pending byte page is set aside
 15.4617  ** for use by the VFS layers as space for managing file locks.
 15.4618  **
 15.4619  ** During testing, it is often desirable to move the pending byte to
 15.4620 @@ -16985,10 +17495,19 @@
 15.4621  #if SQLITE_CHECK_PAGES
 15.4622    "CHECK_PAGES",
 15.4623  #endif
 15.4624 +#if defined(__clang__) && defined(__clang_major__)
 15.4625 +  "COMPILER=clang-" CTIMEOPT_VAL(__clang_major__) "."
 15.4626 +                    CTIMEOPT_VAL(__clang_minor__) "."
 15.4627 +                    CTIMEOPT_VAL(__clang_patchlevel__),
 15.4628 +#elif defined(_MSC_VER)
 15.4629 +  "COMPILER=msvc-" CTIMEOPT_VAL(_MSC_VER),
 15.4630 +#elif defined(__GNUC__) && defined(__VERSION__)
 15.4631 +  "COMPILER=gcc-" __VERSION__,
 15.4632 +#endif
 15.4633  #if SQLITE_COVERAGE_TEST
 15.4634    "COVERAGE_TEST",
 15.4635  #endif
 15.4636 -#if SQLITE_DEBUG
 15.4637 +#ifdef SQLITE_DEBUG
 15.4638    "DEBUG",
 15.4639  #endif
 15.4640  #if SQLITE_DEFAULT_LOCKING_MODE
 15.4641 @@ -16997,6 +17516,15 @@
 15.4642  #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
 15.4643    "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
 15.4644  #endif
 15.4645 +#if SQLITE_DEFAULT_SYNCHRONOUS
 15.4646 +  "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS),
 15.4647 +#endif
 15.4648 +#if SQLITE_DEFAULT_WAL_SYNCHRONOUS
 15.4649 +  "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS),
 15.4650 +#endif
 15.4651 +#if SQLITE_DIRECT_OVERFLOW_READ
 15.4652 +  "DIRECT_OVERFLOW_READ",
 15.4653 +#endif
 15.4654  #if SQLITE_DISABLE_DIRSYNC
 15.4655    "DISABLE_DIRSYNC",
 15.4656  #endif
 15.4657 @@ -17004,7 +17532,7 @@
 15.4658    "DISABLE_LFS",
 15.4659  #endif
 15.4660  #if SQLITE_ENABLE_8_3_NAMES
 15.4661 -  "ENABLE_8_3_NAMES",
 15.4662 +  "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES),
 15.4663  #endif
 15.4664  #if SQLITE_ENABLE_API_ARMOR
 15.4665    "ENABLE_API_ARMOR",
 15.4666 @@ -17083,6 +17611,9 @@
 15.4667  #if SQLITE_ENABLE_UPDATE_DELETE_LIMIT
 15.4668    "ENABLE_UPDATE_DELETE_LIMIT",
 15.4669  #endif
 15.4670 +#if defined(SQLITE_ENABLE_URI_00_ERROR)
 15.4671 +  "ENABLE_URI_00_ERROR",
 15.4672 +#endif
 15.4673  #if SQLITE_HAS_CODEC
 15.4674    "HAS_CODEC",
 15.4675  #endif
 15.4676 @@ -17158,9 +17689,6 @@
 15.4677  #if SQLITE_OMIT_BTREECOUNT
 15.4678    "OMIT_BTREECOUNT",
 15.4679  #endif
 15.4680 -#if SQLITE_OMIT_BUILTIN_TEST
 15.4681 -  "OMIT_BUILTIN_TEST",
 15.4682 -#endif
 15.4683  #if SQLITE_OMIT_CAST
 15.4684    "OMIT_CAST",
 15.4685  #endif
 15.4686 @@ -17323,6 +17851,9 @@
 15.4687  #if defined(SQLITE_THREADSAFE)
 15.4688    "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
 15.4689  #endif
 15.4690 +#if SQLITE_UNTESTABLE
 15.4691 +  "UNTESTABLE"
 15.4692 +#endif
 15.4693  #if SQLITE_USE_ALLOCA
 15.4694    "USE_ALLOCA",
 15.4695  #endif
 15.4696 @@ -17344,7 +17875,7 @@
 15.4697  ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
 15.4698  ** is not required for a match.
 15.4699  */
 15.4700 -SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName){
 15.4701 +SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
 15.4702    int i, n;
 15.4703  
 15.4704  #if SQLITE_ENABLE_API_ARMOR
 15.4705 @@ -17372,7 +17903,7 @@
 15.4706  ** Return the N-th compile-time option string.  If N is out of range,
 15.4707  ** return a NULL pointer.
 15.4708  */
 15.4709 -SQLITE_API const char *SQLITE_STDCALL sqlite3_compileoption_get(int N){
 15.4710 +SQLITE_API const char *sqlite3_compileoption_get(int N){
 15.4711    if( N>=0 && N<ArraySize(azCompileOpt) ){
 15.4712      return azCompileOpt[N];
 15.4713    }
 15.4714 @@ -17418,8 +17949,8 @@
 15.4715  ** 6000 lines long) it was split up into several smaller files and
 15.4716  ** this header information was factored out.
 15.4717  */
 15.4718 -#ifndef _VDBEINT_H_
 15.4719 -#define _VDBEINT_H_
 15.4720 +#ifndef SQLITE_VDBEINT_H
 15.4721 +#define SQLITE_VDBEINT_H
 15.4722  
 15.4723  /*
 15.4724  ** The maximum number of times that a statement will try to reparse
 15.4725 @@ -17455,9 +17986,6 @@
 15.4726  /* Opaque type used by code in vdbesort.c */
 15.4727  typedef struct VdbeSorter VdbeSorter;
 15.4728  
 15.4729 -/* Opaque type used by the explainer */
 15.4730 -typedef struct Explain Explain;
 15.4731 -
 15.4732  /* Elements of the linked list at Vdbe.pAuxData */
 15.4733  typedef struct AuxData AuxData;
 15.4734  
 15.4735 @@ -17479,58 +18007,67 @@
 15.4736  */
 15.4737  typedef struct VdbeCursor VdbeCursor;
 15.4738  struct VdbeCursor {
 15.4739 -  u8 eCurType;          /* One of the CURTYPE_* values above */
 15.4740 -  i8 iDb;               /* Index of cursor database in db->aDb[] (or -1) */
 15.4741 -  u8 nullRow;           /* True if pointing to a row with no data */
 15.4742 -  u8 deferredMoveto;    /* A call to sqlite3BtreeMoveto() is needed */
 15.4743 -  u8 isTable;           /* True for rowid tables.  False for indexes */
 15.4744 +  u8 eCurType;            /* One of the CURTYPE_* values above */
 15.4745 +  i8 iDb;                 /* Index of cursor database in db->aDb[] (or -1) */
 15.4746 +  u8 nullRow;             /* True if pointing to a row with no data */
 15.4747 +  u8 deferredMoveto;      /* A call to sqlite3BtreeMoveto() is needed */
 15.4748 +  u8 isTable;             /* True for rowid tables.  False for indexes */
 15.4749  #ifdef SQLITE_DEBUG
 15.4750 -  u8 seekOp;            /* Most recent seek operation on this cursor */
 15.4751 -  u8 wrFlag;            /* The wrFlag argument to sqlite3BtreeCursor() */
 15.4752 -#endif
 15.4753 -  Bool isEphemeral:1;   /* True for an ephemeral table */
 15.4754 -  Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
 15.4755 -  Bool isOrdered:1;     /* True if the table is not BTREE_UNORDERED */
 15.4756 -  Pgno pgnoRoot;        /* Root page of the open btree cursor */
 15.4757 -  i16 nField;           /* Number of fields in the header */
 15.4758 -  u16 nHdrParsed;       /* Number of header fields parsed so far */
 15.4759 +  u8 seekOp;              /* Most recent seek operation on this cursor */
 15.4760 +  u8 wrFlag;              /* The wrFlag argument to sqlite3BtreeCursor() */
 15.4761 +#endif
 15.4762 +  Bool isEphemeral:1;     /* True for an ephemeral table */
 15.4763 +  Bool useRandomRowid:1;  /* Generate new record numbers semi-randomly */
 15.4764 +  Bool isOrdered:1;       /* True if the table is not BTREE_UNORDERED */
 15.4765 +  Btree *pBtx;            /* Separate file holding temporary table */
 15.4766 +  i64 seqCount;           /* Sequence counter */
 15.4767 +  int *aAltMap;           /* Mapping from table to index column numbers */
 15.4768 +
 15.4769 +  /* Cached OP_Column parse information is only valid if cacheStatus matches
 15.4770 +  ** Vdbe.cacheCtr.  Vdbe.cacheCtr will never take on the value of
 15.4771 +  ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
 15.4772 +  ** the cache is out of date. */
 15.4773 +  u32 cacheStatus;        /* Cache is valid if this matches Vdbe.cacheCtr */
 15.4774 +  int seekResult;         /* Result of previous sqlite3BtreeMoveto() or 0
 15.4775 +                          ** if there have been no prior seeks on the cursor. */
 15.4776 +  /* NB: seekResult does not distinguish between "no seeks have ever occurred
 15.4777 +  ** on this cursor" and "the most recent seek was an exact match". */
 15.4778 +
 15.4779 +  /* When a new VdbeCursor is allocated, only the fields above are zeroed.
 15.4780 +  ** The fields that follow are uninitialized, and must be individually
 15.4781 +  ** initialized prior to first use. */
 15.4782 +  VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
 15.4783    union {
 15.4784      BtCursor *pCursor;          /* CURTYPE_BTREE.  Btree cursor */
 15.4785      sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB.   Vtab cursor */
 15.4786      int pseudoTableReg;         /* CURTYPE_PSEUDO. Reg holding content. */
 15.4787      VdbeSorter *pSorter;        /* CURTYPE_SORTER. Sorter object */
 15.4788    } uc;
 15.4789 -  Btree *pBt;           /* Separate file holding temporary table */
 15.4790 -  KeyInfo *pKeyInfo;    /* Info about index keys needed by index cursors */
 15.4791 -  int seekResult;       /* Result of previous sqlite3BtreeMoveto() */
 15.4792 -  i64 seqCount;         /* Sequence counter */
 15.4793 -  i64 movetoTarget;     /* Argument to the deferred sqlite3BtreeMoveto() */
 15.4794 -  VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
 15.4795 -  int *aAltMap;           /* Mapping from table to index column numbers */
 15.4796 +  KeyInfo *pKeyInfo;      /* Info about index keys needed by index cursors */
 15.4797 +  u32 iHdrOffset;         /* Offset to next unparsed byte of the header */
 15.4798 +  Pgno pgnoRoot;          /* Root page of the open btree cursor */
 15.4799 +  i16 nField;             /* Number of fields in the header */
 15.4800 +  u16 nHdrParsed;         /* Number of header fields parsed so far */
 15.4801 +  i64 movetoTarget;       /* Argument to the deferred sqlite3BtreeMoveto() */
 15.4802 +  u32 *aOffset;           /* Pointer to aType[nField] */
 15.4803 +  const u8 *aRow;         /* Data for the current row, if all on one page */
 15.4804 +  u32 payloadSize;        /* Total number of bytes in the record */
 15.4805 +  u32 szRow;              /* Byte available in aRow */
 15.4806  #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
 15.4807 -  u64 maskUsed;         /* Mask of columns used by this cursor */
 15.4808 -#endif
 15.4809 -
 15.4810 -  /* Cached information about the header for the data record that the
 15.4811 -  ** cursor is currently pointing to.  Only valid if cacheStatus matches
 15.4812 -  ** Vdbe.cacheCtr.  Vdbe.cacheCtr will never take on the value of
 15.4813 -  ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
 15.4814 -  ** the cache is out of date.
 15.4815 -  **
 15.4816 -  ** aRow might point to (ephemeral) data for the current row, or it might
 15.4817 -  ** be NULL.
 15.4818 -  */
 15.4819 -  u32 cacheStatus;      /* Cache is valid if this matches Vdbe.cacheCtr */
 15.4820 -  u32 payloadSize;      /* Total number of bytes in the record */
 15.4821 -  u32 szRow;            /* Byte available in aRow */
 15.4822 -  u32 iHdrOffset;       /* Offset to next unparsed byte of the header */
 15.4823 -  const u8 *aRow;       /* Data for the current row, if all on one page */
 15.4824 -  u32 *aOffset;         /* Pointer to aType[nField] */
 15.4825 -  u32 aType[1];         /* Type values for all entries in the record */
 15.4826 +  u64 maskUsed;           /* Mask of columns used by this cursor */
 15.4827 +#endif
 15.4828 +
 15.4829    /* 2*nField extra array elements allocated for aType[], beyond the one
 15.4830    ** static element declared in the structure.  nField total array slots for
 15.4831    ** aType[] and nField+1 array slots for aOffset[] */
 15.4832 -};
 15.4833 +  u32 aType[1];           /* Type values record decode.  MUST BE LAST */
 15.4834 +};
 15.4835 +
 15.4836 +
 15.4837 +/*
 15.4838 +** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
 15.4839 +*/
 15.4840 +#define CACHE_STALE 0
 15.4841  
 15.4842  /*
 15.4843  ** When a sub-program is executed (OP_Program), a structure of this type
 15.4844 @@ -17560,8 +18097,8 @@
 15.4845    Op *aOp;                /* Program instructions for parent frame */
 15.4846    i64 *anExec;            /* Event counters from parent frame */
 15.4847    Mem *aMem;              /* Array of memory cells for parent frame */
 15.4848 -  u8 *aOnceFlag;          /* Array of OP_Once flags for parent frame */
 15.4849    VdbeCursor **apCsr;     /* Array of Vdbe cursors for parent frame */
 15.4850 +  u8 *aOnce;              /* Bitmask used by OP_Once */
 15.4851    void *token;            /* Copy of SubProgram.token */
 15.4852    i64 lastRowid;          /* Last insert rowid (sqlite3.lastRowid) */
 15.4853    AuxData *pAuxData;      /* Linked list of auxdata allocations */
 15.4854 @@ -17569,7 +18106,6 @@
 15.4855    int pc;                 /* Program Counter in parent (calling) frame */
 15.4856    int nOp;                /* Size of aOp array */
 15.4857    int nMem;               /* Number of entries in aMem */
 15.4858 -  int nOnceFlag;          /* Number of entries in aOnceFlag */
 15.4859    int nChildMem;          /* Number of memory cells for child frame */
 15.4860    int nChildCsr;          /* Number of cursors for child frame */
 15.4861    int nChange;            /* Statement changes (Vdbe.nChange)     */
 15.4862 @@ -17579,16 +18115,11 @@
 15.4863  #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
 15.4864  
 15.4865  /*
 15.4866 -** A value for VdbeCursor.cacheValid that means the cache is always invalid.
 15.4867 -*/
 15.4868 -#define CACHE_STALE 0
 15.4869 -
 15.4870 -/*
 15.4871  ** Internally, the vdbe manipulates nearly all SQL values as Mem
 15.4872  ** structures. Each Mem struct may cache multiple representations (string,
 15.4873  ** integer etc.) of the same value.
 15.4874  */
 15.4875 -struct Mem {
 15.4876 +struct sqlite3_value {
 15.4877    union MemValue {
 15.4878      double r;           /* Real value used when MEM_Real is set in flags */
 15.4879      i64 i;              /* Integer value used when MEM_Int is set in flags */
 15.4880 @@ -17690,11 +18221,11 @@
 15.4881  ** when the VM is halted (if not before).
 15.4882  */
 15.4883  struct AuxData {
 15.4884 -  int iOp;                        /* Instruction number of OP_Function opcode */
 15.4885 -  int iArg;                       /* Index of function argument. */
 15.4886 +  int iAuxOp;                     /* Instruction number of OP_Function opcode */
 15.4887 +  int iAuxArg;                    /* Index of function argument. */
 15.4888    void *pAux;                     /* Aux data pointer */
 15.4889 -  void (*xDelete)(void *);        /* Destructor for the aux data */
 15.4890 -  AuxData *pNext;                 /* Next element in list */
 15.4891 +  void (*xDeleteAux)(void*);      /* Destructor for the aux data */
 15.4892 +  AuxData *pNextAux;              /* Next element in list */
 15.4893  };
 15.4894  
 15.4895  /*
 15.4896 @@ -17723,18 +18254,6 @@
 15.4897    sqlite3_value *argv[1]; /* Argument set */
 15.4898  };
 15.4899  
 15.4900 -/*
 15.4901 -** An Explain object accumulates indented output which is helpful
 15.4902 -** in describing recursive data structures.
 15.4903 -*/
 15.4904 -struct Explain {
 15.4905 -  Vdbe *pVdbe;       /* Attach the explanation to this Vdbe */
 15.4906 -  StrAccum str;      /* The string being accumulated */
 15.4907 -  int nIndent;       /* Number of elements in aIndent */
 15.4908 -  u16 aIndent[100];  /* Levels of indentation */
 15.4909 -  char zBase[100];   /* Initial space */
 15.4910 -};
 15.4911 -
 15.4912  /* A bitfield type for use inside of structures.  Always follow with :N where
 15.4913  ** N is the number of bits.
 15.4914  */
 15.4915 @@ -17759,34 +18278,46 @@
 15.4916  */
 15.4917  struct Vdbe {
 15.4918    sqlite3 *db;            /* The database connection that owns this statement */
 15.4919 +  Vdbe *pPrev,*pNext;     /* Linked list of VDBEs with the same Vdbe.db */
 15.4920 +  Parse *pParse;          /* Parsing context used to create this Vdbe */
 15.4921 +  ynVar nVar;             /* Number of entries in aVar[] */
 15.4922 +  u32 magic;              /* Magic number for sanity checking */
 15.4923 +  int nMem;               /* Number of memory locations currently allocated */
 15.4924 +  int nCursor;            /* Number of slots in apCsr[] */
 15.4925 +  u32 cacheCtr;           /* VdbeCursor row cache generation counter */
 15.4926 +  int pc;                 /* The program counter */
 15.4927 +  int rc;                 /* Value to return */
 15.4928 +  int nChange;            /* Number of db changes made since last reset */
 15.4929 +  int iStatement;         /* Statement number (or 0 if has not opened stmt) */
 15.4930 +  i64 iCurrentTime;       /* Value of julianday('now') for this statement */
 15.4931 +  i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
 15.4932 +  i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
 15.4933 +  i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */
 15.4934 +
 15.4935 +  /* When allocating a new Vdbe object, all of the fields below should be
 15.4936 +  ** initialized to zero or NULL */
 15.4937 +
 15.4938    Op *aOp;                /* Space to hold the virtual machine's program */
 15.4939    Mem *aMem;              /* The memory locations */
 15.4940    Mem **apArg;            /* Arguments to currently executing user function */
 15.4941    Mem *aColName;          /* Column names to return */
 15.4942    Mem *pResultSet;        /* Pointer to an array of results */
 15.4943 -  Parse *pParse;          /* Parsing context used to create this Vdbe */
 15.4944 -  int nMem;               /* Number of memory locations currently allocated */
 15.4945 -  int nOp;                /* Number of instructions in the program */
 15.4946 -  int nCursor;            /* Number of slots in apCsr[] */
 15.4947 -  u32 magic;              /* Magic number for sanity checking */
 15.4948    char *zErrMsg;          /* Error message written here */
 15.4949 -  Vdbe *pPrev,*pNext;     /* Linked list of VDBEs with the same Vdbe.db */
 15.4950    VdbeCursor **apCsr;     /* One element of this array for each open cursor */
 15.4951    Mem *aVar;              /* Values for the OP_Variable opcode. */
 15.4952 -  char **azVar;           /* Name of variables */
 15.4953 -  ynVar nVar;             /* Number of entries in aVar[] */
 15.4954 -  ynVar nzVar;            /* Number of entries in azVar[] */
 15.4955 -  u32 cacheCtr;           /* VdbeCursor row cache generation counter */
 15.4956 -  int pc;                 /* The program counter */
 15.4957 -  int rc;                 /* Value to return */
 15.4958 +  VList *pVList;          /* Name of variables */
 15.4959 +#ifndef SQLITE_OMIT_TRACE
 15.4960 +  i64 startTime;          /* Time when query started - used for profiling */
 15.4961 +#endif
 15.4962 +  int nOp;                /* Number of instructions in the program */
 15.4963  #ifdef SQLITE_DEBUG
 15.4964    int rcApp;              /* errcode set by sqlite3_result_error_code() */
 15.4965  #endif
 15.4966    u16 nResColumn;         /* Number of columns in one row of the result set */
 15.4967    u8 errorAction;         /* Recovery action to do in case of an error */
 15.4968 +  u8 minWriteFileFormat;  /* Minimum file format for writable database files */
 15.4969    bft expired:1;          /* True if the VM needs to be recompiled */
 15.4970    bft doingRerun:1;       /* True if rerunning after an auto-reprepare */
 15.4971 -  u8 minWriteFileFormat;  /* Minimum file format for writable database files */
 15.4972    bft explain:2;          /* True if EXPLAIN present on SQL command */
 15.4973    bft changeCntOn:1;      /* True to update the change-counter */
 15.4974    bft runOnlyOnce:1;      /* Automatically expire on reset */
 15.4975 @@ -17794,18 +18325,9 @@
 15.4976    bft readOnly:1;         /* True for statements that do not write */
 15.4977    bft bIsReader:1;        /* True for statements that read */
 15.4978    bft isPrepareV2:1;      /* True if prepared with prepare_v2() */
 15.4979 -  int nChange;            /* Number of db changes made since last reset */
 15.4980    yDbMask btreeMask;      /* Bitmask of db->aDb[] entries referenced */
 15.4981    yDbMask lockMask;       /* Subset of btreeMask that requires a lock */
 15.4982 -  int iStatement;         /* Statement number (or 0 if has not opened stmt) */
 15.4983    u32 aCounter[5];        /* Counters used by sqlite3_stmt_status() */
 15.4984 -#ifndef SQLITE_OMIT_TRACE
 15.4985 -  i64 startTime;          /* Time when query started - used for profiling */
 15.4986 -#endif
 15.4987 -  i64 iCurrentTime;       /* Value of julianday('now') for this statement */
 15.4988 -  i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
 15.4989 -  i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
 15.4990 -  i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */
 15.4991    char *zSql;             /* Text of the SQL statement that generated this */
 15.4992    void *pFree;            /* Free this when deleting the vdbe */
 15.4993    VdbeFrame *pFrame;      /* Parent frame */
 15.4994 @@ -17813,8 +18335,6 @@
 15.4995    int nFrame;             /* Number of frames in pFrame list */
 15.4996    u32 expmask;            /* Binding to these vars invalidates VM */
 15.4997    SubProgram *pProgram;   /* Linked list of all sub-programs used by VM */
 15.4998 -  int nOnceFlag;          /* Size of array aOnceFlag[] */
 15.4999 -  u8 *aOnceFlag;          /* Flags for OP_Once */
 15.5000    AuxData *pAuxData;      /* Linked list of auxdata allocations */
 15.5001  #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
 15.5002    i64 *anExec;            /* Number of times each op has been executed */
 15.5003 @@ -17826,10 +18346,11 @@
 15.5004  /*
 15.5005  ** The following are allowed values for Vdbe.magic
 15.5006  */
 15.5007 -#define VDBE_MAGIC_INIT     0x26bceaa5    /* Building a VDBE program */
 15.5008 -#define VDBE_MAGIC_RUN      0xbdf20da3    /* VDBE is ready to execute */
 15.5009 -#define VDBE_MAGIC_HALT     0x519c2973    /* VDBE has completed execution */
 15.5010 -#define VDBE_MAGIC_DEAD     0xb606c3c8    /* The VDBE has been deallocated */
 15.5011 +#define VDBE_MAGIC_INIT     0x16bceaa5    /* Building a VDBE program */
 15.5012 +#define VDBE_MAGIC_RUN      0x2df20da3    /* VDBE is ready to execute */
 15.5013 +#define VDBE_MAGIC_HALT     0x319c2973    /* VDBE has completed execution */
 15.5014 +#define VDBE_MAGIC_RESET    0x48fa9f76    /* Reset and ready to run again */
 15.5015 +#define VDBE_MAGIC_DEAD     0x5606c3c8    /* The VDBE has been deallocated */
 15.5016  
 15.5017  /*
 15.5018  ** Structure used to store the context required by the 
 15.5019 @@ -17846,8 +18367,9 @@
 15.5020    int iNewReg;                    /* Register for new.* values */
 15.5021    i64 iKey1;                      /* First key value passed to hook */
 15.5022    i64 iKey2;                      /* Second key value passed to hook */
 15.5023 -  int iPKey;                      /* If not negative index of IPK column */
 15.5024    Mem *aNew;                      /* Array of new.* values */
 15.5025 +  Table *pTab;                    /* Schema object being upated */          
 15.5026 +  Index *pPk;                     /* PK index if pTab is WITHOUT ROWID */
 15.5027  };
 15.5028  
 15.5029  /*
 15.5030 @@ -17900,7 +18422,7 @@
 15.5031  SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
 15.5032  SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
 15.5033  SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
 15.5034 -SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
 15.5035 +SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
 15.5036  SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
 15.5037  SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
 15.5038  SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
 15.5039 @@ -17961,7 +18483,7 @@
 15.5040    #define ExpandBlob(P) SQLITE_OK
 15.5041  #endif
 15.5042  
 15.5043 -#endif /* !defined(_VDBEINT_H_) */
 15.5044 +#endif /* !defined(SQLITE_VDBEINT_H) */
 15.5045  
 15.5046  /************** End of vdbeInt.h *********************************************/
 15.5047  /************** Continuing where we left off in status.c *********************/
 15.5048 @@ -18082,7 +18604,7 @@
 15.5049  /*
 15.5050  ** Query status information.
 15.5051  */
 15.5052 -SQLITE_API int SQLITE_STDCALL sqlite3_status64(
 15.5053 +SQLITE_API int sqlite3_status64(
 15.5054    int op,
 15.5055    sqlite3_int64 *pCurrent,
 15.5056    sqlite3_int64 *pHighwater,
 15.5057 @@ -18107,8 +18629,8 @@
 15.5058    (void)pMutex;  /* Prevent warning when SQLITE_THREADSAFE=0 */
 15.5059    return SQLITE_OK;
 15.5060  }
 15.5061 -SQLITE_API int SQLITE_STDCALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
 15.5062 -  sqlite3_int64 iCur, iHwtr;
 15.5063 +SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
 15.5064 +  sqlite3_int64 iCur = 0, iHwtr = 0;
 15.5065    int rc;
 15.5066  #ifdef SQLITE_ENABLE_API_ARMOR
 15.5067    if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
 15.5068 @@ -18124,7 +18646,7 @@
 15.5069  /*
 15.5070  ** Query status information for a single database connection
 15.5071  */
 15.5072 -SQLITE_API int SQLITE_STDCALL sqlite3_db_status(
 15.5073 +SQLITE_API int sqlite3_db_status(
 15.5074    sqlite3 *db,          /* The database connection whose status is desired */
 15.5075    int op,               /* Status verb */
 15.5076    int *pCurrent,        /* Write current value here */
 15.5077 @@ -18169,6 +18691,7 @@
 15.5078      ** by all pagers associated with the given database connection.  The
 15.5079      ** highwater mark is meaningless and is returned as zero.
 15.5080      */
 15.5081 +    case SQLITE_DBSTATUS_CACHE_USED_SHARED:
 15.5082      case SQLITE_DBSTATUS_CACHE_USED: {
 15.5083        int totalUsed = 0;
 15.5084        int i;
 15.5085 @@ -18177,7 +18700,11 @@
 15.5086          Btree *pBt = db->aDb[i].pBt;
 15.5087          if( pBt ){
 15.5088            Pager *pPager = sqlite3BtreePager(pBt);
 15.5089 -          totalUsed += sqlite3PagerMemUsed(pPager);
 15.5090 +          int nByte = sqlite3PagerMemUsed(pPager);
 15.5091 +          if( op==SQLITE_DBSTATUS_CACHE_USED_SHARED ){
 15.5092 +            nByte = nByte / sqlite3BtreeConnectionCount(pBt);
 15.5093 +          }
 15.5094 +          totalUsed += nByte;
 15.5095          }
 15.5096        }
 15.5097        sqlite3BtreeLeaveAll(db);
 15.5098 @@ -18364,16 +18891,18 @@
 15.5099  */
 15.5100  typedef struct DateTime DateTime;
 15.5101  struct DateTime {
 15.5102 -  sqlite3_int64 iJD; /* The julian day number times 86400000 */
 15.5103 -  int Y, M, D;       /* Year, month, and day */
 15.5104 -  int h, m;          /* Hour and minutes */
 15.5105 -  int tz;            /* Timezone offset in minutes */
 15.5106 -  double s;          /* Seconds */
 15.5107 -  char validYMD;     /* True (1) if Y,M,D are valid */
 15.5108 -  char validHMS;     /* True (1) if h,m,s are valid */
 15.5109 -  char validJD;      /* True (1) if iJD is valid */
 15.5110 -  char validTZ;      /* True (1) if tz is valid */
 15.5111 -  char tzSet;        /* Timezone was set explicitly */
 15.5112 +  sqlite3_int64 iJD;  /* The julian day number times 86400000 */
 15.5113 +  int Y, M, D;        /* Year, month, and day */
 15.5114 +  int h, m;           /* Hour and minutes */
 15.5115 +  int tz;             /* Timezone offset in minutes */
 15.5116 +  double s;           /* Seconds */
 15.5117 +  char validJD;       /* True (1) if iJD is valid */
 15.5118 +  char rawS;          /* Raw numeric value stored in s */
 15.5119 +  char validYMD;      /* True (1) if Y,M,D are valid */
 15.5120 +  char validHMS;      /* True (1) if h,m,s are valid */
 15.5121 +  char validTZ;       /* True (1) if tz is valid */
 15.5122 +  char tzSet;         /* Timezone was set explicitly */
 15.5123 +  char isError;       /* An overflow has occurred */
 15.5124  };
 15.5125  
 15.5126  
 15.5127 @@ -18521,6 +19050,7 @@
 15.5128      s = 0;
 15.5129    }
 15.5130    p->validJD = 0;
 15.5131 +  p->rawS = 0;
 15.5132    p->validHMS = 1;
 15.5133    p->h = h;
 15.5134    p->m = m;
 15.5135 @@ -18531,6 +19061,14 @@
 15.5136  }
 15.5137  
 15.5138  /*
 15.5139 +** Put the DateTime object into its error state.
 15.5140 +*/
 15.5141 +static void datetimeError(DateTime *p){
 15.5142 +  memset(p, 0, sizeof(*p));
 15.5143 +  p->isError = 1;
 15.5144 +}
 15.5145 +
 15.5146 +/*
 15.5147  ** Convert from YYYY-MM-DD HH:MM:SS to julian day.  We always assume
 15.5148  ** that the YYYY-MM-DD is according to the Gregorian calendar.
 15.5149  **
 15.5150 @@ -18549,6 +19087,10 @@
 15.5151      M = 1;
 15.5152      D = 1;
 15.5153    }
 15.5154 +  if( Y<-4713 || Y>9999 || p->rawS ){
 15.5155 +    datetimeError(p);
 15.5156 +    return;
 15.5157 +  }
 15.5158    if( M<=2 ){
 15.5159      Y--;
 15.5160      M += 12;
 15.5161 @@ -18630,6 +19172,21 @@
 15.5162  }
 15.5163  
 15.5164  /*
 15.5165 +** Input "r" is a numeric quantity which might be a julian day number,
 15.5166 +** or the number of seconds since 1970.  If the value if r is within
 15.5167 +** range of a julian day number, install it as such and set validJD.
 15.5168 +** If the value is a valid unix timestamp, put it in p->s and set p->rawS.
 15.5169 +*/
 15.5170 +static void setRawDateNumber(DateTime *p, double r){
 15.5171 +  p->s = r;
 15.5172 +  p->rawS = 1;
 15.5173 +  if( r>=0.0 && r<5373484.5 ){
 15.5174 +    p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
 15.5175 +    p->validJD = 1;
 15.5176 +  }
 15.5177 +}
 15.5178 +
 15.5179 +/*
 15.5180  ** Attempt to parse the given string into a julian day number.  Return
 15.5181  ** the number of errors.
 15.5182  **
 15.5183 @@ -18658,13 +19215,30 @@
 15.5184    }else if( sqlite3StrICmp(zDate,"now")==0){
 15.5185      return setDateTimeToCurrent(context, p);
 15.5186    }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
 15.5187 -    p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
 15.5188 -    p->validJD = 1;
 15.5189 +    setRawDateNumber(p, r);
 15.5190      return 0;
 15.5191    }
 15.5192    return 1;
 15.5193  }
 15.5194  
 15.5195 +/* The julian day number for 9999-12-31 23:59:59.999 is 5373484.4999999.
 15.5196 +** Multiplying this by 86400000 gives 464269060799999 as the maximum value
 15.5197 +** for DateTime.iJD.
 15.5198 +**
 15.5199 +** But some older compilers (ex: gcc 4.2.1 on older Macs) cannot deal with 
 15.5200 +** such a large integer literal, so we have to encode it.
 15.5201 +*/
 15.5202 +#define INT_464269060799999  ((((i64)0x1a640)<<32)|0x1072fdff)
 15.5203 +
 15.5204 +/*
 15.5205 +** Return TRUE if the given julian day number is within range.
 15.5206 +**
 15.5207 +** The input is the JulianDay times 86400000.
 15.5208 +*/
 15.5209 +static int validJulianDay(sqlite3_int64 iJD){
 15.5210 +  return iJD>=0 && iJD<=INT_464269060799999;
 15.5211 +}
 15.5212 +
 15.5213  /*
 15.5214  ** Compute the Year, Month, and Day from the julian day number.
 15.5215  */
 15.5216 @@ -18675,6 +19249,9 @@
 15.5217      p->Y = 2000;
 15.5218      p->M = 1;
 15.5219      p->D = 1;
 15.5220 +  }else if( !validJulianDay(p->iJD) ){
 15.5221 +    datetimeError(p);
 15.5222 +    return;
 15.5223    }else{
 15.5224      Z = (int)((p->iJD + 43200000)/86400000);
 15.5225      A = (int)((Z - 1867216.25)/36524.25);
 15.5226 @@ -18706,6 +19283,7 @@
 15.5227    s -= p->h*3600;
 15.5228    p->m = s/60;
 15.5229    p->s += s - p->m*60;
 15.5230 +  p->rawS = 0;
 15.5231    p->validHMS = 1;
 15.5232  }
 15.5233  
 15.5234 @@ -18767,14 +19345,14 @@
 15.5235  #endif
 15.5236    sqlite3_mutex_enter(mutex);
 15.5237    pX = localtime(t);
 15.5238 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.5239 +#ifndef SQLITE_UNTESTABLE
 15.5240    if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
 15.5241  #endif
 15.5242    if( pX ) *pTm = *pX;
 15.5243    sqlite3_mutex_leave(mutex);
 15.5244    rc = pX==0;
 15.5245  #else
 15.5246 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.5247 +#ifndef SQLITE_UNTESTABLE
 15.5248    if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
 15.5249  #endif
 15.5250  #if HAVE_LOCALTIME_R
 15.5251 @@ -18845,7 +19423,9 @@
 15.5252    y.validYMD = 1;
 15.5253    y.validHMS = 1;
 15.5254    y.validJD = 0;
 15.5255 +  y.rawS = 0;
 15.5256    y.validTZ = 0;
 15.5257 +  y.isError = 0;
 15.5258    computeJD(&y);
 15.5259    *pRc = SQLITE_OK;
 15.5260    return y.iJD - x.iJD;
 15.5261 @@ -18853,6 +19433,29 @@
 15.5262  #endif /* SQLITE_OMIT_LOCALTIME */
 15.5263  
 15.5264  /*
 15.5265 +** The following table defines various date transformations of the form
 15.5266 +**
 15.5267 +**            'NNN days'
 15.5268 +**
 15.5269 +** Where NNN is an arbitrary floating-point number and "days" can be one
 15.5270 +** of several units of time.
 15.5271 +*/
 15.5272 +static const struct {
 15.5273 +  u8 eType;           /* Transformation type code */
 15.5274 +  u8 nName;           /* Length of th name */
 15.5275 +  char *zName;        /* Name of the transformation */
 15.5276 +  double rLimit;      /* Maximum NNN value for this transform */
 15.5277 +  double rXform;      /* Constant used for this transform */
 15.5278 +} aXformType[] = {
 15.5279 +  { 0, 6, "second", 464269060800.0, 86400000.0/(24.0*60.0*60.0) },
 15.5280 +  { 0, 6, "minute", 7737817680.0,   86400000.0/(24.0*60.0)      },
 15.5281 +  { 0, 4, "hour",   128963628.0,    86400000.0/24.0             },
 15.5282 +  { 0, 3, "day",    5373485.0,      86400000.0                  },
 15.5283 +  { 1, 5, "month",  176546.0,       30.0*86400000.0             },
 15.5284 +  { 2, 4, "year",   14713.0,        365.0*86400000.0            },
 15.5285 +};
 15.5286 +
 15.5287 +/*
 15.5288  ** Process a modifier to a date-time stamp.  The modifiers are
 15.5289  ** as follows:
 15.5290  **
 15.5291 @@ -18876,17 +19479,15 @@
 15.5292  ** to context pCtx. If the error is an unrecognized modifier, no error is
 15.5293  ** written to pCtx.
 15.5294  */
 15.5295 -static int parseModifier(sqlite3_context *pCtx, const char *zMod, DateTime *p){
 15.5296 +static int parseModifier(
 15.5297 +  sqlite3_context *pCtx,      /* Function context */
 15.5298 +  const char *z,              /* The text of the modifier */
 15.5299 +  int n,                      /* Length of zMod in bytes */
 15.5300 +  DateTime *p                 /* The date/time value to be modified */
 15.5301 +){
 15.5302    int rc = 1;
 15.5303 -  int n;
 15.5304    double r;
 15.5305 -  char *z, zBuf[30];
 15.5306 -  z = zBuf;
 15.5307 -  for(n=0; n<ArraySize(zBuf)-1 && zMod[n]; n++){
 15.5308 -    z[n] = (char)sqlite3UpperToLower[(u8)zMod[n]];
 15.5309 -  }
 15.5310 -  z[n] = 0;
 15.5311 -  switch( z[0] ){
 15.5312 +  switch(sqlite3UpperToLower[(u8)z[0]] ){
 15.5313  #ifndef SQLITE_OMIT_LOCALTIME
 15.5314      case 'l': {
 15.5315        /*    localtime
 15.5316 @@ -18894,7 +19495,7 @@
 15.5317        ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
 15.5318        ** show local time.
 15.5319        */
 15.5320 -      if( strcmp(z, "localtime")==0 ){
 15.5321 +      if( sqlite3_stricmp(z, "localtime")==0 ){
 15.5322          computeJD(p);
 15.5323          p->iJD += localtimeOffset(p, pCtx, &rc);
 15.5324          clearYMD_HMS_TZ(p);
 15.5325 @@ -18906,16 +19507,21 @@
 15.5326        /*
 15.5327        **    unixepoch
 15.5328        **
 15.5329 -      ** Treat the current value of p->iJD as the number of
 15.5330 +      ** Treat the current value of p->s as the number of
 15.5331        ** seconds since 1970.  Convert to a real julian day number.
 15.5332        */
 15.5333 -      if( strcmp(z, "unixepoch")==0 && p->validJD ){
 15.5334 -        p->iJD = (p->iJD + 43200)/86400 + 21086676*(i64)10000000;
 15.5335 -        clearYMD_HMS_TZ(p);
 15.5336 -        rc = 0;
 15.5337 +      if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
 15.5338 +        r = p->s*1000.0 + 210866760000000.0;
 15.5339 +        if( r>=0.0 && r<464269060800000.0 ){
 15.5340 +          clearYMD_HMS_TZ(p);
 15.5341 +          p->iJD = (sqlite3_int64)r;
 15.5342 +          p->validJD = 1;
 15.5343 +          p->rawS = 0;
 15.5344 +          rc = 0;
 15.5345 +        }
 15.5346        }
 15.5347  #ifndef SQLITE_OMIT_LOCALTIME
 15.5348 -      else if( strcmp(z, "utc")==0 ){
 15.5349 +      else if( sqlite3_stricmp(z, "utc")==0 ){
 15.5350          if( p->tzSet==0 ){
 15.5351            sqlite3_int64 c1;
 15.5352            computeJD(p);
 15.5353 @@ -18941,7 +19547,7 @@
 15.5354        ** weekday N where 0==Sunday, 1==Monday, and so forth.  If the
 15.5355        ** date is already on the appropriate weekday, this is a no-op.
 15.5356        */
 15.5357 -      if( strncmp(z, "weekday ", 8)==0
 15.5358 +      if( sqlite3_strnicmp(z, "weekday ", 8)==0
 15.5359                 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)
 15.5360                 && (n=(int)r)==r && n>=0 && r<7 ){
 15.5361          sqlite3_int64 Z;
 15.5362 @@ -18964,23 +19570,24 @@
 15.5363        ** Move the date backwards to the beginning of the current day,
 15.5364        ** or month or year.
 15.5365        */
 15.5366 -      if( strncmp(z, "start of ", 9)!=0 ) break;
 15.5367 +      if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break;
 15.5368 +      if( !p->validJD && !p->validYMD && !p->validHMS ) break;
 15.5369        z += 9;
 15.5370        computeYMD(p);
 15.5371        p->validHMS = 1;
 15.5372        p->h = p->m = 0;
 15.5373        p->s = 0.0;
 15.5374 +      p->rawS = 0;
 15.5375        p->validTZ = 0;
 15.5376        p->validJD = 0;
 15.5377 -      if( strcmp(z,"month")==0 ){
 15.5378 +      if( sqlite3_stricmp(z,"month")==0 ){
 15.5379          p->D = 1;
 15.5380          rc = 0;
 15.5381 -      }else if( strcmp(z,"year")==0 ){
 15.5382 -        computeYMD(p);
 15.5383 +      }else if( sqlite3_stricmp(z,"year")==0 ){
 15.5384          p->M = 1;
 15.5385          p->D = 1;
 15.5386          rc = 0;
 15.5387 -      }else if( strcmp(z,"day")==0 ){
 15.5388 +      }else if( sqlite3_stricmp(z,"day")==0 ){
 15.5389          rc = 0;
 15.5390        }
 15.5391        break;
 15.5392 @@ -18998,6 +19605,7 @@
 15.5393      case '8':
 15.5394      case '9': {
 15.5395        double rRounder;
 15.5396 +      int i;
 15.5397        for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
 15.5398        if( !sqlite3AtoF(z, &r, n, SQLITE_UTF8) ){
 15.5399          rc = 1;
 15.5400 @@ -19026,46 +19634,48 @@
 15.5401          rc = 0;
 15.5402          break;
 15.5403        }
 15.5404 +
 15.5405 +      /* If control reaches this point, it means the transformation is
 15.5406 +      ** one of the forms like "+NNN days".  */
 15.5407        z += n;
 15.5408        while( sqlite3Isspace(*z) ) z++;
 15.5409        n = sqlite3Strlen30(z);
 15.5410        if( n>10 || n<3 ) break;
 15.5411 -      if( z[n-1]=='s' ){ z[n-1] = 0; n--; }
 15.5412 +      if( sqlite3UpperToLower[(u8)z[n-1]]=='s' ) n--;
 15.5413        computeJD(p);
 15.5414 -      rc = 0;
 15.5415 +      rc = 1;
 15.5416        rRounder = r<0 ? -0.5 : +0.5;
 15.5417 -      if( n==3 && strcmp(z,"day")==0 ){
 15.5418 -        p->iJD += (sqlite3_int64)(r*86400000.0 + rRounder);
 15.5419 -      }else if( n==4 && strcmp(z,"hour")==0 ){
 15.5420 -        p->iJD += (sqlite3_int64)(r*(86400000.0/24.0) + rRounder);
 15.5421 -      }else if( n==6 && strcmp(z,"minute")==0 ){
 15.5422 -        p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0)) + rRounder);
 15.5423 -      }else if( n==6 && strcmp(z,"second")==0 ){
 15.5424 -        p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0*60.0)) + rRounder);
 15.5425 -      }else if( n==5 && strcmp(z,"month")==0 ){
 15.5426 -        int x, y;
 15.5427 -        computeYMD_HMS(p);
 15.5428 -        p->M += (int)r;
 15.5429 -        x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
 15.5430 -        p->Y += x;
 15.5431 -        p->M -= x*12;
 15.5432 -        p->validJD = 0;
 15.5433 -        computeJD(p);
 15.5434 -        y = (int)r;
 15.5435 -        if( y!=r ){
 15.5436 -          p->iJD += (sqlite3_int64)((r - y)*30.0*86400000.0 + rRounder);
 15.5437 -        }
 15.5438 -      }else if( n==4 && strcmp(z,"year")==0 ){
 15.5439 -        int y = (int)r;
 15.5440 -        computeYMD_HMS(p);
 15.5441 -        p->Y += y;
 15.5442 -        p->validJD = 0;
 15.5443 -        computeJD(p);
 15.5444 -        if( y!=r ){
 15.5445 -          p->iJD += (sqlite3_int64)((r - y)*365.0*86400000.0 + rRounder);
 15.5446 -        }
 15.5447 -      }else{
 15.5448 -        rc = 1;
 15.5449 +      for(i=0; i<ArraySize(aXformType); i++){
 15.5450 +        if( aXformType[i].nName==n
 15.5451 +         && sqlite3_strnicmp(aXformType[i].zName, z, n)==0
 15.5452 +         && r>-aXformType[i].rLimit && r<aXformType[i].rLimit
 15.5453 +        ){
 15.5454 +          switch( aXformType[i].eType ){
 15.5455 +            case 1: { /* Special processing to add months */
 15.5456 +              int x;
 15.5457 +              computeYMD_HMS(p);
 15.5458 +              p->M += (int)r;
 15.5459 +              x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
 15.5460 +              p->Y += x;
 15.5461 +              p->M -= x*12;
 15.5462 +              p->validJD = 0;
 15.5463 +              r -= (int)r;
 15.5464 +              break;
 15.5465 +            }
 15.5466 +            case 2: { /* Special processing to add years */
 15.5467 +              int y = (int)r;
 15.5468 +              computeYMD_HMS(p);
 15.5469 +              p->Y += y;
 15.5470 +              p->validJD = 0;
 15.5471 +              r -= (int)r;
 15.5472 +              break;
 15.5473 +            }
 15.5474 +          }
 15.5475 +          computeJD(p);
 15.5476 +          p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder);
 15.5477 +          rc = 0;
 15.5478 +          break;
 15.5479 +        }
 15.5480        }
 15.5481        clearYMD_HMS_TZ(p);
 15.5482        break;
 15.5483 @@ -19092,7 +19702,7 @@
 15.5484    sqlite3_value **argv, 
 15.5485    DateTime *p
 15.5486  ){
 15.5487 -  int i;
 15.5488 +  int i, n;
 15.5489    const unsigned char *z;
 15.5490    int eType;
 15.5491    memset(p, 0, sizeof(*p));
 15.5492 @@ -19101,8 +19711,7 @@
 15.5493    }
 15.5494    if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
 15.5495                     || eType==SQLITE_INTEGER ){
 15.5496 -    p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
 15.5497 -    p->validJD = 1;
 15.5498 +    setRawDateNumber(p, sqlite3_value_double(argv[0]));
 15.5499    }else{
 15.5500      z = sqlite3_value_text(argv[0]);
 15.5501      if( !z || parseDateOrTime(context, (char*)z, p) ){
 15.5502 @@ -19111,8 +19720,11 @@
 15.5503    }
 15.5504    for(i=1; i<argc; i++){
 15.5505      z = sqlite3_value_text(argv[i]);
 15.5506 -    if( z==0 || parseModifier(context, (char*)z, p) ) return 1;
 15.5507 -  }
 15.5508 +    n = sqlite3_value_bytes(argv[i]);
 15.5509 +    if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1;
 15.5510 +  }
 15.5511 +  computeJD(p);
 15.5512 +  if( p->isError || !validJulianDay(p->iJD) ) return 1;
 15.5513    return 0;
 15.5514  }
 15.5515  
 15.5516 @@ -19411,7 +20023,6 @@
 15.5517  ){
 15.5518    time_t t;
 15.5519    char *zFormat = (char *)sqlite3_user_data(context);
 15.5520 -  sqlite3 *db;
 15.5521    sqlite3_int64 iT;
 15.5522    struct tm *pTm;
 15.5523    struct tm sNow;
 15.5524 @@ -19480,9 +20091,7 @@
 15.5525  ** This file contains OS interface code that is common to all
 15.5526  ** architectures.
 15.5527  */
 15.5528 -#define _SQLITE_OS_C_ 1
 15.5529  /* #include "sqliteInt.h" */
 15.5530 -#undef _SQLITE_OS_C_
 15.5531  
 15.5532  /*
 15.5533  ** If we compile with the SQLITE_TEST macro set, then the following block
 15.5534 @@ -19799,7 +20408,7 @@
 15.5535  ** Locate a VFS by name.  If no name is given, simply return the
 15.5536  ** first VFS on the list.
 15.5537  */
 15.5538 -SQLITE_API sqlite3_vfs *SQLITE_STDCALL sqlite3_vfs_find(const char *zVfs){
 15.5539 +SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfs){
 15.5540    sqlite3_vfs *pVfs = 0;
 15.5541  #if SQLITE_THREADSAFE
 15.5542    sqlite3_mutex *mutex;
 15.5543 @@ -19845,7 +20454,7 @@
 15.5544  ** VFS multiple times.  The new VFS becomes the default if makeDflt is
 15.5545  ** true.
 15.5546  */
 15.5547 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
 15.5548 +SQLITE_API int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
 15.5549    MUTEX_LOGIC(sqlite3_mutex *mutex;)
 15.5550  #ifndef SQLITE_OMIT_AUTOINIT
 15.5551    int rc = sqlite3_initialize();
 15.5552 @@ -19873,7 +20482,7 @@
 15.5553  /*
 15.5554  ** Unregister a VFS so that it is no longer accessible.
 15.5555  */
 15.5556 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
 15.5557 +SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
 15.5558  #if SQLITE_THREADSAFE
 15.5559    sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 15.5560  #endif
 15.5561 @@ -19913,7 +20522,7 @@
 15.5562  
 15.5563  /* #include "sqliteInt.h" */
 15.5564  
 15.5565 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.5566 +#ifndef SQLITE_UNTESTABLE
 15.5567  
 15.5568  /*
 15.5569  ** Global variables.
 15.5570 @@ -19971,7 +20580,7 @@
 15.5571    }
 15.5572  }
 15.5573  
 15.5574 -#endif   /* #ifndef SQLITE_OMIT_BUILTIN_TEST */
 15.5575 +#endif   /* #ifndef SQLITE_UNTESTABLE */
 15.5576  
 15.5577  /************** End of fault.c ***********************************************/
 15.5578  /************** Begin file mem0.c ********************************************/
 15.5579 @@ -20096,7 +20705,9 @@
 15.5580  */
 15.5581  #include <sys/sysctl.h>
 15.5582  #include <malloc/malloc.h>
 15.5583 +#ifdef SQLITE_MIGHT_BE_SINGLE_CORE
 15.5584  #include <libkern/OSAtomic.h>
 15.5585 +#endif /* SQLITE_MIGHT_BE_SINGLE_CORE */
 15.5586  static malloc_zone_t* _sqliteZone_;
 15.5587  #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x))
 15.5588  #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x));
 15.5589 @@ -20164,7 +20775,9 @@
 15.5590  */
 15.5591  static void *sqlite3MemMalloc(int nByte){
 15.5592  #ifdef SQLITE_MALLOCSIZE
 15.5593 -  void *p = SQLITE_MALLOC( nByte );
 15.5594 +  void *p;
 15.5595 +  testcase( ROUND8(nByte)==nByte );
 15.5596 +  p = SQLITE_MALLOC( nByte );
 15.5597    if( p==0 ){
 15.5598      testcase( sqlite3GlobalConfig.xLog!=0 );
 15.5599      sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes of memory", nByte);
 15.5600 @@ -20173,7 +20786,7 @@
 15.5601  #else
 15.5602    sqlite3_int64 *p;
 15.5603    assert( nByte>0 );
 15.5604 -  nByte = ROUND8(nByte);
 15.5605 +  testcase( ROUND8(nByte)!=nByte );
 15.5606    p = SQLITE_MALLOC( nByte+8 );
 15.5607    if( p ){
 15.5608      p[0] = nByte;
 15.5609 @@ -20287,19 +20900,10 @@
 15.5610    }else{
 15.5611      /* only 1 core, use our own zone to contention over global locks, 
 15.5612      ** e.g. we have our own dedicated locks */
 15.5613 -    bool success;
 15.5614 -    malloc_zone_t* newzone = malloc_create_zone(4096, 0);
 15.5615 -    malloc_set_zone_name(newzone, "Sqlite_Heap");
 15.5616 -    do{
 15.5617 -      success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, 
 15.5618 -                                 (void * volatile *)&_sqliteZone_);
 15.5619 -    }while(!_sqliteZone_);
 15.5620 -    if( !success ){
 15.5621 -      /* somebody registered a zone first */
 15.5622 -      malloc_destroy_zone(newzone);
 15.5623 -    }
 15.5624 -  }
 15.5625 -#endif
 15.5626 +    _sqliteZone_ = malloc_create_zone(4096, 0);
 15.5627 +    malloc_set_zone_name(_sqliteZone_, "Sqlite_Heap");
 15.5628 +  }
 15.5629 +#endif /*  defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) */
 15.5630    UNUSED_PARAMETER(NotUsed);
 15.5631    return SQLITE_OK;
 15.5632  }
 15.5633 @@ -22224,7 +22828,7 @@
 15.5634  /*
 15.5635  ** Retrieve a pointer to a static mutex or allocate a new dynamic one.
 15.5636  */
 15.5637 -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int id){
 15.5638 +SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
 15.5639  #ifndef SQLITE_OMIT_AUTOINIT
 15.5640    if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
 15.5641    if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0;
 15.5642 @@ -22245,7 +22849,7 @@
 15.5643  /*
 15.5644  ** Free a dynamic mutex.
 15.5645  */
 15.5646 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex *p){
 15.5647 +SQLITE_API void sqlite3_mutex_free(sqlite3_mutex *p){
 15.5648    if( p ){
 15.5649      assert( sqlite3GlobalConfig.mutex.xMutexFree );
 15.5650      sqlite3GlobalConfig.mutex.xMutexFree(p);
 15.5651 @@ -22256,7 +22860,7 @@
 15.5652  ** Obtain the mutex p. If some other thread already has the mutex, block
 15.5653  ** until it can be obtained.
 15.5654  */
 15.5655 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex *p){
 15.5656 +SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex *p){
 15.5657    if( p ){
 15.5658      assert( sqlite3GlobalConfig.mutex.xMutexEnter );
 15.5659      sqlite3GlobalConfig.mutex.xMutexEnter(p);
 15.5660 @@ -22267,7 +22871,7 @@
 15.5661  ** Obtain the mutex p. If successful, return SQLITE_OK. Otherwise, if another
 15.5662  ** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY.
 15.5663  */
 15.5664 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex *p){
 15.5665 +SQLITE_API int sqlite3_mutex_try(sqlite3_mutex *p){
 15.5666    int rc = SQLITE_OK;
 15.5667    if( p ){
 15.5668      assert( sqlite3GlobalConfig.mutex.xMutexTry );
 15.5669 @@ -22282,7 +22886,7 @@
 15.5670  ** is not currently entered. If a NULL pointer is passed as an argument
 15.5671  ** this function is a no-op.
 15.5672  */
 15.5673 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex *p){
 15.5674 +SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex *p){
 15.5675    if( p ){
 15.5676      assert( sqlite3GlobalConfig.mutex.xMutexLeave );
 15.5677      sqlite3GlobalConfig.mutex.xMutexLeave(p);
 15.5678 @@ -22294,11 +22898,11 @@
 15.5679  ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
 15.5680  ** intended for use inside assert() statements.
 15.5681  */
 15.5682 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex *p){
 15.5683 +SQLITE_API int sqlite3_mutex_held(sqlite3_mutex *p){
 15.5684    assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld );
 15.5685    return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p);
 15.5686  }
 15.5687 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex *p){
 15.5688 +SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex *p){
 15.5689    assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld );
 15.5690    return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
 15.5691  }
 15.5692 @@ -22995,8 +23599,8 @@
 15.5693  ** This file contains inline asm code for retrieving "high-performance"
 15.5694  ** counters for x86 class CPUs.
 15.5695  */
 15.5696 -#ifndef _HWTIME_H_
 15.5697 -#define _HWTIME_H_
 15.5698 +#ifndef SQLITE_HWTIME_H
 15.5699 +#define SQLITE_HWTIME_H
 15.5700  
 15.5701  /*
 15.5702  ** The following routine only works on pentium-class (or newer) processors.
 15.5703 @@ -23064,7 +23668,7 @@
 15.5704  
 15.5705  #endif
 15.5706  
 15.5707 -#endif /* !defined(_HWTIME_H_) */
 15.5708 +#endif /* !defined(SQLITE_HWTIME_H) */
 15.5709  
 15.5710  /************** End of hwtime.h **********************************************/
 15.5711  /************** Continuing where we left off in os_common.h ******************/
 15.5712 @@ -23154,8 +23758,8 @@
 15.5713  **
 15.5714  ** This file contains code that is specific to Windows.
 15.5715  */
 15.5716 -#ifndef _OS_WIN_H_
 15.5717 -#define _OS_WIN_H_
 15.5718 +#ifndef SQLITE_OS_WIN_H
 15.5719 +#define SQLITE_OS_WIN_H
 15.5720  
 15.5721  /*
 15.5722  ** Include the primary Windows SDK header file.
 15.5723 @@ -23227,7 +23831,7 @@
 15.5724  # define SQLITE_OS_WIN_THREADS 0
 15.5725  #endif
 15.5726  
 15.5727 -#endif /* _OS_WIN_H_ */
 15.5728 +#endif /* SQLITE_OS_WIN_H */
 15.5729  
 15.5730  /************** End of os_win.h **********************************************/
 15.5731  /************** Continuing where we left off in mutex_w32.c ******************/
 15.5732 @@ -23295,8 +23899,7 @@
 15.5733    SQLITE_MEMORY_BARRIER;
 15.5734  #elif defined(__GNUC__)
 15.5735    __sync_synchronize();
 15.5736 -#elif !defined(SQLITE_DISABLE_INTRINSIC) && \
 15.5737 -      defined(_MSC_VER) && _MSC_VER>=1300
 15.5738 +#elif MSVC_VERSION>=1300
 15.5739    _ReadWriteBarrier();
 15.5740  #elif defined(MemoryBarrier)
 15.5741    MemoryBarrier();
 15.5742 @@ -23330,8 +23933,8 @@
 15.5743  */
 15.5744  static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0;
 15.5745  
 15.5746 -SQLITE_API int SQLITE_STDCALL sqlite3_win32_is_nt(void); /* os_win.c */
 15.5747 -SQLITE_API void SQLITE_STDCALL sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
 15.5748 +SQLITE_API int sqlite3_win32_is_nt(void); /* os_win.c */
 15.5749 +SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
 15.5750  
 15.5751  static int winMutexInit(void){
 15.5752    /* The first to increment to 1 does actual initialization */
 15.5753 @@ -23507,8 +24110,8 @@
 15.5754    p->owner = tid;
 15.5755    p->nRef++;
 15.5756    if( p->trace ){
 15.5757 -    OSTRACE(("ENTER-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
 15.5758 -             tid, p, p->trace, p->nRef));
 15.5759 +    OSTRACE(("ENTER-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
 15.5760 +             tid, p->id, p, p->trace, p->nRef));
 15.5761    }
 15.5762  #endif
 15.5763  }
 15.5764 @@ -23550,8 +24153,8 @@
 15.5765  #endif
 15.5766  #ifdef SQLITE_DEBUG
 15.5767    if( p->trace ){
 15.5768 -    OSTRACE(("TRY-MUTEX tid=%lu, mutex=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
 15.5769 -             tid, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
 15.5770 +    OSTRACE(("TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
 15.5771 +             tid, p->id, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
 15.5772    }
 15.5773  #endif
 15.5774    return rc;
 15.5775 @@ -23579,8 +24182,8 @@
 15.5776    LeaveCriticalSection(&p->mutex);
 15.5777  #ifdef SQLITE_DEBUG
 15.5778    if( p->trace ){
 15.5779 -    OSTRACE(("LEAVE-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
 15.5780 -             tid, p, p->trace, p->nRef));
 15.5781 +    OSTRACE(("LEAVE-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
 15.5782 +             tid, p->id, p, p->trace, p->nRef));
 15.5783    }
 15.5784  #endif
 15.5785  }
 15.5786 @@ -23631,7 +24234,7 @@
 15.5787  ** held by SQLite. An example of non-essential memory is memory used to
 15.5788  ** cache database pages that are not currently in use.
 15.5789  */
 15.5790 -SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int n){
 15.5791 +SQLITE_API int sqlite3_release_memory(int n){
 15.5792  #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
 15.5793    return sqlite3PcacheReleaseMemory(n);
 15.5794  #else
 15.5795 @@ -23690,7 +24293,7 @@
 15.5796  ** that was invoked when memory usage grew too large.  Now it is a
 15.5797  ** no-op.
 15.5798  */
 15.5799 -SQLITE_API int SQLITE_STDCALL sqlite3_memory_alarm(
 15.5800 +SQLITE_API int sqlite3_memory_alarm(
 15.5801    void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
 15.5802    void *pArg,
 15.5803    sqlite3_int64 iThreshold
 15.5804 @@ -23706,7 +24309,7 @@
 15.5805  ** Set the soft heap-size limit for the library. Passing a zero or 
 15.5806  ** negative value indicates no limit.
 15.5807  */
 15.5808 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 n){
 15.5809 +SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){
 15.5810    sqlite3_int64 priorLimit;
 15.5811    sqlite3_int64 excess;
 15.5812    sqlite3_int64 nUsed;
 15.5813 @@ -23728,7 +24331,7 @@
 15.5814    if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
 15.5815    return priorLimit;
 15.5816  }
 15.5817 -SQLITE_API void SQLITE_STDCALL sqlite3_soft_heap_limit(int n){
 15.5818 +SQLITE_API void sqlite3_soft_heap_limit(int n){
 15.5819    if( n<0 ) n = 0;
 15.5820    sqlite3_soft_heap_limit64(n);
 15.5821  }
 15.5822 @@ -23797,7 +24400,7 @@
 15.5823  /*
 15.5824  ** Return the amount of memory currently checked out.
 15.5825  */
 15.5826 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void){
 15.5827 +SQLITE_API sqlite3_int64 sqlite3_memory_used(void){
 15.5828    sqlite3_int64 res, mx;
 15.5829    sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, 0);
 15.5830    return res;
 15.5831 @@ -23808,7 +24411,7 @@
 15.5832  ** checked out since either the beginning of this process
 15.5833  ** or since the most recent reset.
 15.5834  */
 15.5835 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag){
 15.5836 +SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag){
 15.5837    sqlite3_int64 res, mx;
 15.5838    sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, resetFlag);
 15.5839    return mx;
 15.5840 @@ -23828,11 +24431,26 @@
 15.5841  ** Do a memory allocation with statistics and alarms.  Assume the
 15.5842  ** lock is already held.
 15.5843  */
 15.5844 -static int mallocWithAlarm(int n, void **pp){
 15.5845 -  int nFull;
 15.5846 +static void mallocWithAlarm(int n, void **pp){
 15.5847    void *p;
 15.5848 +  int nFull;
 15.5849    assert( sqlite3_mutex_held(mem0.mutex) );
 15.5850 +  assert( n>0 );
 15.5851 +
 15.5852 +  /* In Firefox (circa 2017-02-08), xRoundup() is remapped to an internal
 15.5853 +  ** implementation of malloc_good_size(), which must be called in debug
 15.5854 +  ** mode and specifically when the DMD "Dark Matter Detector" is enabled
 15.5855 +  ** or else a crash results.  Hence, do not attempt to optimize out the
 15.5856 +  ** following xRoundup() call. */
 15.5857    nFull = sqlite3GlobalConfig.m.xRoundup(n);
 15.5858 +
 15.5859 +#ifdef SQLITE_MAX_MEMORY
 15.5860 +  if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nFull>SQLITE_MAX_MEMORY ){
 15.5861 +    *pp = 0;
 15.5862 +    return;
 15.5863 +  }
 15.5864 +#endif
 15.5865 +
 15.5866    sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
 15.5867    if( mem0.alarmThreshold>0 ){
 15.5868      sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
 15.5869 @@ -23856,7 +24474,6 @@
 15.5870      sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
 15.5871    }
 15.5872    *pp = p;
 15.5873 -  return nFull;
 15.5874  }
 15.5875  
 15.5876  /*
 15.5877 @@ -23888,13 +24505,13 @@
 15.5878  ** First make sure the memory subsystem is initialized, then do the
 15.5879  ** allocation.
 15.5880  */
 15.5881 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc(int n){
 15.5882 +SQLITE_API void *sqlite3_malloc(int n){
 15.5883  #ifndef SQLITE_OMIT_AUTOINIT
 15.5884    if( sqlite3_initialize() ) return 0;
 15.5885  #endif
 15.5886    return n<=0 ? 0 : sqlite3Malloc(n);
 15.5887  }
 15.5888 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64 n){
 15.5889 +SQLITE_API void *sqlite3_malloc64(sqlite3_uint64 n){
 15.5890  #ifndef SQLITE_OMIT_AUTOINIT
 15.5891    if( sqlite3_initialize() ) return 0;
 15.5892  #endif
 15.5893 @@ -24022,7 +24639,7 @@
 15.5894  SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
 15.5895    assert( p!=0 );
 15.5896    if( db==0 || !isLookaside(db,p) ){
 15.5897 -#if SQLITE_DEBUG
 15.5898 +#ifdef SQLITE_DEBUG
 15.5899      if( db==0 ){
 15.5900        assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
 15.5901        assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 15.5902 @@ -24037,7 +24654,7 @@
 15.5903      return db->lookaside.sz;
 15.5904    }
 15.5905  }
 15.5906 -SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void *p){
 15.5907 +SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
 15.5908    assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
 15.5909    assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 15.5910    return p ? sqlite3GlobalConfig.m.xSize(p) : 0;
 15.5911 @@ -24046,7 +24663,7 @@
 15.5912  /*
 15.5913  ** Free memory previously obtained from sqlite3Malloc().
 15.5914  */
 15.5915 -SQLITE_API void SQLITE_STDCALL sqlite3_free(void *p){
 15.5916 +SQLITE_API void sqlite3_free(void *p){
 15.5917    if( p==0 ) return;  /* IMP: R-49053-54554 */
 15.5918    assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 15.5919    assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
 15.5920 @@ -24071,11 +24688,12 @@
 15.5921  
 15.5922  /*
 15.5923  ** Free memory that might be associated with a particular database
 15.5924 -** connection.
 15.5925 -*/
 15.5926 -SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
 15.5927 +** connection.  Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
 15.5928 +** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
 15.5929 +*/
 15.5930 +SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
 15.5931    assert( db==0 || sqlite3_mutex_held(db->mutex) );
 15.5932 -  if( p==0 ) return;
 15.5933 +  assert( p!=0 );
 15.5934    if( db ){
 15.5935      if( db->pnBytesFreed ){
 15.5936        measureAllocationSize(db, p);
 15.5937 @@ -24083,7 +24701,7 @@
 15.5938      }
 15.5939      if( isLookaside(db, p) ){
 15.5940        LookasideSlot *pBuf = (LookasideSlot*)p;
 15.5941 -#if SQLITE_DEBUG
 15.5942 +#ifdef SQLITE_DEBUG
 15.5943        /* Trash all content in the buffer being freed */
 15.5944        memset(p, 0xaa, db->lookaside.sz);
 15.5945  #endif
 15.5946 @@ -24099,6 +24717,10 @@
 15.5947    sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
 15.5948    sqlite3_free(p);
 15.5949  }
 15.5950 +SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
 15.5951 +  assert( db==0 || sqlite3_mutex_held(db->mutex) );
 15.5952 +  if( p ) sqlite3DbFreeNN(db, p);
 15.5953 +}
 15.5954  
 15.5955  /*
 15.5956  ** Change the size of an existing memory allocation
 15.5957 @@ -24130,7 +24752,7 @@
 15.5958      sqlite3_mutex_enter(mem0.mutex);
 15.5959      sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
 15.5960      nDiff = nNew - nOld;
 15.5961 -    if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 
 15.5962 +    if( nDiff>0 && sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 
 15.5963            mem0.alarmThreshold-nDiff ){
 15.5964        sqlite3MallocAlarm(nDiff);
 15.5965      }
 15.5966 @@ -24155,14 +24777,14 @@
 15.5967  ** The public interface to sqlite3Realloc.  Make sure that the memory
 15.5968  ** subsystem is initialized prior to invoking sqliteRealloc.
 15.5969  */
 15.5970 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void *pOld, int n){
 15.5971 +SQLITE_API void *sqlite3_realloc(void *pOld, int n){
 15.5972  #ifndef SQLITE_OMIT_AUTOINIT
 15.5973    if( sqlite3_initialize() ) return 0;
 15.5974  #endif
 15.5975    if( n<0 ) n = 0;  /* IMP: R-26507-47431 */
 15.5976    return sqlite3Realloc(pOld, n);
 15.5977  }
 15.5978 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
 15.5979 +SQLITE_API void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
 15.5980  #ifndef SQLITE_OMIT_AUTOINIT
 15.5981    if( sqlite3_initialize() ) return 0;
 15.5982  #endif
 15.5983 @@ -24337,9 +24959,8 @@
 15.5984    if( z==0 ){
 15.5985      return 0;
 15.5986    }
 15.5987 -  n = sqlite3Strlen30(z) + 1;
 15.5988 -  assert( (n&0x7fffffff)==n );
 15.5989 -  zNew = sqlite3DbMallocRaw(db, (int)n);
 15.5990 +  n = strlen(z) + 1;
 15.5991 +  zNew = sqlite3DbMallocRaw(db, n);
 15.5992    if( zNew ){
 15.5993      memcpy(zNew, z, n);
 15.5994    }
 15.5995 @@ -24453,7 +25074,7 @@
 15.5996  ** Conversion types fall into various categories as defined by the
 15.5997  ** following enumeration.
 15.5998  */
 15.5999 -#define etRADIX       0 /* Integer types.  %d, %x, %o, and so forth */
 15.6000 +#define etRADIX       0 /* non-decimal integer types.  %x %o */
 15.6001  #define etFLOAT       1 /* Floating point.  %f */
 15.6002  #define etEXP         2 /* Exponentional notation. %e and %E */
 15.6003  #define etGENERIC     3 /* Floating or exponential, depending on exponent. %g */
 15.6004 @@ -24471,8 +25092,9 @@
 15.6005  #define etPOINTER    13 /* The %p conversion */
 15.6006  #define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
 15.6007  #define etORDINAL    15 /* %r -> 1st, 2nd, 3rd, 4th, etc.  English only */
 15.6008 -
 15.6009 -#define etINVALID    16 /* Any unrecognized conversion type */
 15.6010 +#define etDECIMAL    16 /* %d or %u, but not %x, %o */
 15.6011 +
 15.6012 +#define etINVALID    17 /* Any unrecognized conversion type */
 15.6013  
 15.6014  
 15.6015  /*
 15.6016 @@ -24496,9 +25118,8 @@
 15.6017  /*
 15.6018  ** Allowed values for et_info.flags
 15.6019  */
 15.6020 -#define FLAG_SIGNED  1     /* True if the value to convert is signed */
 15.6021 -#define FLAG_INTERN  2     /* True if for internal use only */
 15.6022 -#define FLAG_STRING  4     /* Allow infinity precision */
 15.6023 +#define FLAG_SIGNED    1     /* True if the value to convert is signed */
 15.6024 +#define FLAG_STRING    4     /* Allow infinite precision */
 15.6025  
 15.6026  
 15.6027  /*
 15.6028 @@ -24508,7 +25129,7 @@
 15.6029  static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
 15.6030  static const char aPrefix[] = "-x0\000X0";
 15.6031  static const et_info fmtinfo[] = {
 15.6032 -  {  'd', 10, 1, etRADIX,      0,  0 },
 15.6033 +  {  'd', 10, 1, etDECIMAL,    0,  0 },
 15.6034    {  's',  0, 4, etSTRING,     0,  0 },
 15.6035    {  'g',  0, 1, etGENERIC,    30, 0 },
 15.6036    {  'z',  0, 4, etDYNSTRING,  0,  0 },
 15.6037 @@ -24517,7 +25138,7 @@
 15.6038    {  'w',  0, 4, etSQLESCAPE3, 0,  0 },
 15.6039    {  'c',  0, 0, etCHARX,      0,  0 },
 15.6040    {  'o',  8, 0, etRADIX,      0,  2 },
 15.6041 -  {  'u', 10, 0, etRADIX,      0,  0 },
 15.6042 +  {  'u', 10, 0, etDECIMAL,    0,  0 },
 15.6043    {  'x', 16, 0, etRADIX,      16, 1 },
 15.6044    {  'X', 16, 0, etRADIX,      0,  4 },
 15.6045  #ifndef SQLITE_OMIT_FLOATING_POINT
 15.6046 @@ -24526,16 +25147,15 @@
 15.6047    {  'E',  0, 1, etEXP,        14, 0 },
 15.6048    {  'G',  0, 1, etGENERIC,    14, 0 },
 15.6049  #endif
 15.6050 -  {  'i', 10, 1, etRADIX,      0,  0 },
 15.6051 +  {  'i', 10, 1, etDECIMAL,    0,  0 },
 15.6052    {  'n',  0, 0, etSIZE,       0,  0 },
 15.6053    {  '%',  0, 0, etPERCENT,    0,  0 },
 15.6054    {  'p', 16, 0, etPOINTER,    0,  1 },
 15.6055  
 15.6056 -/* All the rest have the FLAG_INTERN bit set and are thus for internal
 15.6057 -** use only */
 15.6058 -  {  'T',  0, 2, etTOKEN,      0,  0 },
 15.6059 -  {  'S',  0, 2, etSRCLIST,    0,  0 },
 15.6060 -  {  'r', 10, 3, etORDINAL,    0,  0 },
 15.6061 +  /* All the rest are undocumented and are for internal use only */
 15.6062 +  {  'T',  0, 0, etTOKEN,      0,  0 },
 15.6063 +  {  'S',  0, 0, etSRCLIST,    0,  0 },
 15.6064 +  {  'r', 10, 1, etORDINAL,    0,  0 },
 15.6065  };
 15.6066  
 15.6067  /*
 15.6068 @@ -24619,17 +25239,15 @@
 15.6069    int idx;                   /* A general purpose loop counter */
 15.6070    int width;                 /* Width of the current field */
 15.6071    etByte flag_leftjustify;   /* True if "-" flag is present */
 15.6072 -  etByte flag_plussign;      /* True if "+" flag is present */
 15.6073 -  etByte flag_blanksign;     /* True if " " flag is present */
 15.6074 +  etByte flag_prefix;        /* '+' or ' ' or 0 for prefix */
 15.6075    etByte flag_alternateform; /* True if "#" flag is present */
 15.6076    etByte flag_altform2;      /* True if "!" flag is present */
 15.6077    etByte flag_zeropad;       /* True if field width constant starts with zero */
 15.6078 -  etByte flag_long;          /* True if "l" flag is present */
 15.6079 -  etByte flag_longlong;      /* True if the "ll" flag is present */
 15.6080 +  etByte flag_long;          /* 1 for the "l" flag, 2 for "ll", 0 by default */
 15.6081    etByte done;               /* Loop termination flag */
 15.6082 +  etByte cThousand;          /* Thousands separator for %d and %u */
 15.6083    etByte xtype = etINVALID;  /* Conversion paradigm */
 15.6084    u8 bArgList;               /* True for SQLITE_PRINTF_SQLFUNC */
 15.6085 -  u8 useIntern;              /* Ok to use internal conversions (ex: %T) */
 15.6086    char prefix;               /* Prefix character.  "+" or "-" or " " or '\0'. */
 15.6087    sqlite_uint64 longvalue;   /* Value for integer types */
 15.6088    LONGDOUBLE_TYPE realvalue; /* Value for real types */
 15.6089 @@ -24648,13 +25266,11 @@
 15.6090    char buf[etBUFSIZE];       /* Conversion buffer */
 15.6091  
 15.6092    bufpt = 0;
 15.6093 -  if( pAccum->printfFlags ){
 15.6094 -    if( (bArgList = (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
 15.6095 -      pArgList = va_arg(ap, PrintfArguments*);
 15.6096 -    }
 15.6097 -    useIntern = pAccum->printfFlags & SQLITE_PRINTF_INTERNAL;
 15.6098 -  }else{
 15.6099 -    bArgList = useIntern = 0;
 15.6100 +  if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){
 15.6101 +    pArgList = va_arg(ap, PrintfArguments*);
 15.6102 +    bArgList = 1;
 15.6103 +  }else{
 15.6104 +    bArgList = 0;
 15.6105    }
 15.6106    for(; (c=(*fmt))!=0; ++fmt){
 15.6107      if( c!='%' ){
 15.6108 @@ -24672,17 +25288,18 @@
 15.6109        break;
 15.6110      }
 15.6111      /* Find out what flags are present */
 15.6112 -    flag_leftjustify = flag_plussign = flag_blanksign = 
 15.6113 +    flag_leftjustify = flag_prefix = cThousand =
 15.6114       flag_alternateform = flag_altform2 = flag_zeropad = 0;
 15.6115      done = 0;
 15.6116      do{
 15.6117        switch( c ){
 15.6118          case '-':   flag_leftjustify = 1;     break;
 15.6119 -        case '+':   flag_plussign = 1;        break;
 15.6120 -        case ' ':   flag_blanksign = 1;       break;
 15.6121 +        case '+':   flag_prefix = '+';        break;
 15.6122 +        case ' ':   flag_prefix = ' ';        break;
 15.6123          case '#':   flag_alternateform = 1;   break;
 15.6124          case '!':   flag_altform2 = 1;        break;
 15.6125          case '0':   flag_zeropad = 1;         break;
 15.6126 +        case ',':   cThousand = ',';          break;
 15.6127          default:    done = 1;                 break;
 15.6128        }
 15.6129      }while( !done && (c=(*++fmt))!=0 );
 15.6130 @@ -24752,13 +25369,11 @@
 15.6131        flag_long = 1;
 15.6132        c = *++fmt;
 15.6133        if( c=='l' ){
 15.6134 -        flag_longlong = 1;
 15.6135 +        flag_long = 2;
 15.6136          c = *++fmt;
 15.6137 -      }else{
 15.6138 -        flag_longlong = 0;
 15.6139 -      }
 15.6140 -    }else{
 15.6141 -      flag_long = flag_longlong = 0;
 15.6142 +      }
 15.6143 +    }else{
 15.6144 +      flag_long = 0;
 15.6145      }
 15.6146      /* Fetch the info entry for the field */
 15.6147      infop = &fmtinfo[0];
 15.6148 @@ -24766,11 +25381,7 @@
 15.6149      for(idx=0; idx<ArraySize(fmtinfo); idx++){
 15.6150        if( c==fmtinfo[idx].fmttype ){
 15.6151          infop = &fmtinfo[idx];
 15.6152 -        if( useIntern || (infop->flags & FLAG_INTERN)==0 ){
 15.6153 -          xtype = infop->type;
 15.6154 -        }else{
 15.6155 -          return;
 15.6156 -        }
 15.6157 +        xtype = infop->type;
 15.6158          break;
 15.6159        }
 15.6160      }
 15.6161 @@ -24780,15 +25391,11 @@
 15.6162      **
 15.6163      **   flag_alternateform          TRUE if a '#' is present.
 15.6164      **   flag_altform2               TRUE if a '!' is present.
 15.6165 -    **   flag_plussign               TRUE if a '+' is present.
 15.6166 +    **   flag_prefix                 '+' or ' ' or zero
 15.6167      **   flag_leftjustify            TRUE if a '-' is present or if the
 15.6168      **                               field width was negative.
 15.6169      **   flag_zeropad                TRUE if the width began with 0.
 15.6170 -    **   flag_long                   TRUE if the letter 'l' (ell) prefixed
 15.6171 -    **                               the conversion character.
 15.6172 -    **   flag_longlong               TRUE if the letter 'll' (ell ell) prefixed
 15.6173 -    **                               the conversion character.
 15.6174 -    **   flag_blanksign              TRUE if a ' ' is present.
 15.6175 +    **   flag_long                   1 for "l", 2 for "ll"
 15.6176      **   width                       The specified field width.  This is
 15.6177      **                               always non-negative.  Zero is the default.
 15.6178      **   precision                   The specified precision.  The default
 15.6179 @@ -24798,19 +25405,24 @@
 15.6180      */
 15.6181      switch( xtype ){
 15.6182        case etPOINTER:
 15.6183 -        flag_longlong = sizeof(char*)==sizeof(i64);
 15.6184 -        flag_long = sizeof(char*)==sizeof(long int);
 15.6185 +        flag_long = sizeof(char*)==sizeof(i64) ? 2 :
 15.6186 +                     sizeof(char*)==sizeof(long int) ? 1 : 0;
 15.6187          /* Fall through into the next case */
 15.6188        case etORDINAL:
 15.6189 -      case etRADIX:
 15.6190 +      case etRADIX:      
 15.6191 +        cThousand = 0;
 15.6192 +        /* Fall through into the next case */
 15.6193 +      case etDECIMAL:
 15.6194          if( infop->flags & FLAG_SIGNED ){
 15.6195            i64 v;
 15.6196            if( bArgList ){
 15.6197              v = getIntArg(pArgList);
 15.6198 -          }else if( flag_longlong ){
 15.6199 -            v = va_arg(ap,i64);
 15.6200            }else if( flag_long ){
 15.6201 -            v = va_arg(ap,long int);
 15.6202 +            if( flag_long==2 ){
 15.6203 +              v = va_arg(ap,i64) ;
 15.6204 +            }else{
 15.6205 +              v = va_arg(ap,long int);
 15.6206 +            }
 15.6207            }else{
 15.6208              v = va_arg(ap,int);
 15.6209            }
 15.6210 @@ -24823,17 +25435,17 @@
 15.6211              prefix = '-';
 15.6212            }else{
 15.6213              longvalue = v;
 15.6214 -            if( flag_plussign )        prefix = '+';
 15.6215 -            else if( flag_blanksign )  prefix = ' ';
 15.6216 -            else                       prefix = 0;
 15.6217 +            prefix = flag_prefix;
 15.6218            }
 15.6219          }else{
 15.6220            if( bArgList ){
 15.6221              longvalue = (u64)getIntArg(pArgList);
 15.6222 -          }else if( flag_longlong ){
 15.6223 -            longvalue = va_arg(ap,u64);
 15.6224            }else if( flag_long ){
 15.6225 -            longvalue = va_arg(ap,unsigned long int);
 15.6226 +            if( flag_long==2 ){
 15.6227 +              longvalue = va_arg(ap,u64);
 15.6228 +            }else{
 15.6229 +              longvalue = va_arg(ap,unsigned long int);
 15.6230 +            }
 15.6231            }else{
 15.6232              longvalue = va_arg(ap,unsigned int);
 15.6233            }
 15.6234 @@ -24843,16 +25455,17 @@
 15.6235          if( flag_zeropad && precision<width-(prefix!=0) ){
 15.6236            precision = width-(prefix!=0);
 15.6237          }
 15.6238 -        if( precision<etBUFSIZE-10 ){
 15.6239 +        if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
 15.6240            nOut = etBUFSIZE;
 15.6241            zOut = buf;
 15.6242          }else{
 15.6243 -          nOut = precision + 10;
 15.6244 -          zOut = zExtra = sqlite3Malloc( nOut );
 15.6245 +          u64 n = (u64)precision + 10 + precision/3;
 15.6246 +          zOut = zExtra = sqlite3Malloc( n );
 15.6247            if( zOut==0 ){
 15.6248              setStrAccumError(pAccum, STRACCUM_NOMEM);
 15.6249              return;
 15.6250            }
 15.6251 +          nOut = (int)n;
 15.6252          }
 15.6253          bufpt = &zOut[nOut-1];
 15.6254          if( xtype==etORDINAL ){
 15.6255 @@ -24873,8 +25486,23 @@
 15.6256            }while( longvalue>0 );
 15.6257          }
 15.6258          length = (int)(&zOut[nOut-1]-bufpt);
 15.6259 -        for(idx=precision-length; idx>0; idx--){
 15.6260 +        while( precision>length ){
 15.6261            *(--bufpt) = '0';                             /* Zero pad */
 15.6262 +          length++;
 15.6263 +        }
 15.6264 +        if( cThousand ){
 15.6265 +          int nn = (length - 1)/3;  /* Number of "," to insert */
 15.6266 +          int ix = (length - 1)%3 + 1;
 15.6267 +          bufpt -= nn;
 15.6268 +          for(idx=0; nn>0; idx++){
 15.6269 +            bufpt[idx] = bufpt[idx+nn];
 15.6270 +            ix--;
 15.6271 +            if( ix==0 ){
 15.6272 +              bufpt[++idx] = cThousand;
 15.6273 +              nn--;
 15.6274 +              ix = 3;
 15.6275 +            }
 15.6276 +          }
 15.6277          }
 15.6278          if( prefix ) *(--bufpt) = prefix;               /* Add sign */
 15.6279          if( flag_alternateform && infop->prefix ){      /* Add "0" or "0x" */
 15.6280 @@ -24901,9 +25529,7 @@
 15.6281            realvalue = -realvalue;
 15.6282            prefix = '-';
 15.6283          }else{
 15.6284 -          if( flag_plussign )          prefix = '+';
 15.6285 -          else if( flag_blanksign )    prefix = ' ';
 15.6286 -          else                         prefix = 0;
 15.6287 +          prefix = flag_prefix;
 15.6288          }
 15.6289          if( xtype==etGENERIC && precision>0 ) precision--;
 15.6290          testcase( precision>0xfff );
 15.6291 @@ -25139,7 +25765,9 @@
 15.6292          break;
 15.6293        }
 15.6294        case etTOKEN: {
 15.6295 -        Token *pToken = va_arg(ap, Token*);
 15.6296 +        Token *pToken;
 15.6297 +        if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
 15.6298 +        pToken = va_arg(ap, Token*);
 15.6299          assert( bArgList==0 );
 15.6300          if( pToken && pToken->n ){
 15.6301            sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
 15.6302 @@ -25148,9 +25776,13 @@
 15.6303          break;
 15.6304        }
 15.6305        case etSRCLIST: {
 15.6306 -        SrcList *pSrc = va_arg(ap, SrcList*);
 15.6307 -        int k = va_arg(ap, int);
 15.6308 -        struct SrcList_item *pItem = &pSrc->a[k];
 15.6309 +        SrcList *pSrc;
 15.6310 +        int k;
 15.6311 +        struct SrcList_item *pItem;
 15.6312 +        if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
 15.6313 +        pSrc = va_arg(ap, SrcList*);
 15.6314 +        k = va_arg(ap, int);
 15.6315 +        pItem = &pSrc->a[k];
 15.6316          assert( bArgList==0 );
 15.6317          assert( k>=0 && k<pSrc->nSrc );
 15.6318          if( pItem->zDatabase ){
 15.6319 @@ -25172,9 +25804,13 @@
 15.6320      ** the output.
 15.6321      */
 15.6322      width -= length;
 15.6323 -    if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
 15.6324 -    sqlite3StrAccumAppend(pAccum, bufpt, length);
 15.6325 -    if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
 15.6326 +    if( width>0 ){
 15.6327 +      if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
 15.6328 +      sqlite3StrAccumAppend(pAccum, bufpt, length);
 15.6329 +      if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
 15.6330 +    }else{
 15.6331 +      sqlite3StrAccumAppend(pAccum, bufpt, length);
 15.6332 +    }
 15.6333  
 15.6334      if( zExtra ){
 15.6335        sqlite3DbFree(pAccum->db, zExtra);
 15.6336 @@ -25279,7 +25915,7 @@
 15.6337    assert( p->accError==0 || p->nAlloc==0 );
 15.6338    if( p->nChar+N >= p->nAlloc ){
 15.6339      enlargeAndAppend(p,z,N);
 15.6340 -  }else{
 15.6341 +  }else if( N ){
 15.6342      assert( p->zText );
 15.6343      p->nChar += N;
 15.6344      memcpy(&p->zText[p->nChar-N], z, N);
 15.6345 @@ -25299,18 +25935,23 @@
 15.6346  ** Return a pointer to the resulting string.  Return a NULL
 15.6347  ** pointer if any kind of error was encountered.
 15.6348  */
 15.6349 +static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
 15.6350 +  assert( p->mxAlloc>0 && !isMalloced(p) );
 15.6351 +  p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
 15.6352 +  if( p->zText ){
 15.6353 +    memcpy(p->zText, p->zBase, p->nChar+1);
 15.6354 +    p->printfFlags |= SQLITE_PRINTF_MALLOCED;
 15.6355 +  }else{
 15.6356 +    setStrAccumError(p, STRACCUM_NOMEM);
 15.6357 +  }
 15.6358 +  return p->zText;
 15.6359 +}
 15.6360  SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
 15.6361    if( p->zText ){
 15.6362      assert( (p->zText==p->zBase)==!isMalloced(p) );
 15.6363      p->zText[p->nChar] = 0;
 15.6364      if( p->mxAlloc>0 && !isMalloced(p) ){
 15.6365 -      p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
 15.6366 -      if( p->zText ){
 15.6367 -        memcpy(p->zText, p->zBase, p->nChar+1);
 15.6368 -        p->printfFlags |= SQLITE_PRINTF_MALLOCED;
 15.6369 -      }else{
 15.6370 -        setStrAccumError(p, STRACCUM_NOMEM);
 15.6371 -      }
 15.6372 +      return strAccumFinishRealloc(p);
 15.6373      }
 15.6374    }
 15.6375    return p->zText;
 15.6376 @@ -25389,7 +26030,7 @@
 15.6377  ** Print into memory obtained from sqlite3_malloc().  Omit the internal
 15.6378  ** %-conversion extensions.
 15.6379  */
 15.6380 -SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char *zFormat, va_list ap){
 15.6381 +SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){
 15.6382    char *z;
 15.6383    char zBase[SQLITE_PRINT_BUF_SIZE];
 15.6384    StrAccum acc;
 15.6385 @@ -25413,7 +26054,7 @@
 15.6386  ** Print into memory obtained from sqlite3_malloc()().  Omit the internal
 15.6387  ** %-conversion extensions.
 15.6388  */
 15.6389 -SQLITE_API char *SQLITE_CDECL sqlite3_mprintf(const char *zFormat, ...){
 15.6390 +SQLITE_API char *sqlite3_mprintf(const char *zFormat, ...){
 15.6391    va_list ap;
 15.6392    char *z;
 15.6393  #ifndef SQLITE_OMIT_AUTOINIT
 15.6394 @@ -25438,7 +26079,7 @@
 15.6395  **
 15.6396  ** sqlite3_vsnprintf() is the varargs version.
 15.6397  */
 15.6398 -SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
 15.6399 +SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
 15.6400    StrAccum acc;
 15.6401    if( n<=0 ) return zBuf;
 15.6402  #ifdef SQLITE_ENABLE_API_ARMOR
 15.6403 @@ -25450,9 +26091,10 @@
 15.6404  #endif
 15.6405    sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
 15.6406    sqlite3VXPrintf(&acc, zFormat, ap);
 15.6407 -  return sqlite3StrAccumFinish(&acc);
 15.6408 -}
 15.6409 -SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
 15.6410 +  zBuf[acc.nChar] = 0;
 15.6411 +  return zBuf;
 15.6412 +}
 15.6413 +SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
 15.6414    char *z;
 15.6415    va_list ap;
 15.6416    va_start(ap,zFormat);
 15.6417 @@ -25488,7 +26130,7 @@
 15.6418  /*
 15.6419  ** Format and write a message to the log if logging is enabled.
 15.6420  */
 15.6421 -SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...){
 15.6422 +SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...){
 15.6423    va_list ap;                             /* Vararg list */
 15.6424    if( sqlite3GlobalConfig.xLog ){
 15.6425      va_start(ap, zFormat);
 15.6426 @@ -25598,6 +26240,7 @@
 15.6427    va_start(ap, zFormat);
 15.6428    sqlite3VXPrintf(&acc, zFormat, ap);
 15.6429    va_end(ap);
 15.6430 +  assert( acc.nChar>0 );
 15.6431    if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1);
 15.6432    sqlite3StrAccumFinish(&acc);
 15.6433    fprintf(stdout,"%s", zBuf);
 15.6434 @@ -25653,11 +26296,15 @@
 15.6435  
 15.6436  
 15.6437  /*
 15.6438 -** Generate a human-readable description of a the Select object.
 15.6439 +** Generate a human-readable description of a Select object.
 15.6440  */
 15.6441  SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
 15.6442    int n = 0;
 15.6443    int cnt = 0;
 15.6444 +  if( p==0 ){
 15.6445 +    sqlite3TreeViewLine(pView, "nil-SELECT");
 15.6446 +    return;
 15.6447 +  } 
 15.6448    pView = sqlite3TreeViewPush(pView, moreToFollow);
 15.6449    if( p->pWith ){
 15.6450      sqlite3TreeViewWith(pView, p->pWith, 1);
 15.6451 @@ -25766,7 +26413,7 @@
 15.6452  SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
 15.6453    const char *zBinOp = 0;   /* Binary operator */
 15.6454    const char *zUniOp = 0;   /* Unary operator */
 15.6455 -  char zFlgs[30];
 15.6456 +  char zFlgs[60];
 15.6457    pView = sqlite3TreeViewPush(pView, moreToFollow);
 15.6458    if( pExpr==0 ){
 15.6459      sqlite3TreeViewLine(pView, "nil");
 15.6460 @@ -25774,7 +26421,12 @@
 15.6461      return;
 15.6462    }
 15.6463    if( pExpr->flags ){
 15.6464 -    sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x",pExpr->flags);
 15.6465 +    if( ExprHasProperty(pExpr, EP_FromJoin) ){
 15.6466 +      sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x iRJT=%d",
 15.6467 +                       pExpr->flags, pExpr->iRightJoinTable);
 15.6468 +    }else{
 15.6469 +      sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x",pExpr->flags);
 15.6470 +    }
 15.6471    }else{
 15.6472      zFlgs[0] = 0;
 15.6473    }
 15.6474 @@ -25978,6 +26630,26 @@
 15.6475        break;
 15.6476      }
 15.6477  #endif
 15.6478 +    case TK_MATCH: {
 15.6479 +      sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s",
 15.6480 +                          pExpr->iTable, pExpr->iColumn, zFlgs);
 15.6481 +      sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
 15.6482 +      break;
 15.6483 +    }
 15.6484 +    case TK_VECTOR: {
 15.6485 +      sqlite3TreeViewBareExprList(pView, pExpr->x.pList, "VECTOR");
 15.6486 +      break;
 15.6487 +    }
 15.6488 +    case TK_SELECT_COLUMN: {
 15.6489 +      sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
 15.6490 +      sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
 15.6491 +      break;
 15.6492 +    }
 15.6493 +    case TK_IF_NULL_ROW: {
 15.6494 +      sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
 15.6495 +      sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
 15.6496 +      break;
 15.6497 +    }
 15.6498      default: {
 15.6499        sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
 15.6500        break;
 15.6501 @@ -25994,21 +26666,20 @@
 15.6502    sqlite3TreeViewPop(pView);
 15.6503  }
 15.6504  
 15.6505 +
 15.6506  /*
 15.6507  ** Generate a human-readable explanation of an expression list.
 15.6508  */
 15.6509 -SQLITE_PRIVATE void sqlite3TreeViewExprList(
 15.6510 +SQLITE_PRIVATE void sqlite3TreeViewBareExprList(
 15.6511    TreeView *pView,
 15.6512    const ExprList *pList,
 15.6513 -  u8 moreToFollow,
 15.6514    const char *zLabel
 15.6515  ){
 15.6516 -  int i;
 15.6517 -  pView = sqlite3TreeViewPush(pView, moreToFollow);
 15.6518    if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
 15.6519    if( pList==0 ){
 15.6520      sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
 15.6521    }else{
 15.6522 +    int i;
 15.6523      sqlite3TreeViewLine(pView, "%s", zLabel);
 15.6524      for(i=0; i<pList->nExpr; i++){
 15.6525        int j = pList->a[i].u.x.iOrderByCol;
 15.6526 @@ -26020,6 +26691,15 @@
 15.6527        if( j ) sqlite3TreeViewPop(pView);
 15.6528      }
 15.6529    }
 15.6530 +}
 15.6531 +SQLITE_PRIVATE void sqlite3TreeViewExprList(
 15.6532 +  TreeView *pView,
 15.6533 +  const ExprList *pList,
 15.6534 +  u8 moreToFollow,
 15.6535 +  const char *zLabel
 15.6536 +){
 15.6537 +  pView = sqlite3TreeViewPush(pView, moreToFollow);
 15.6538 +  sqlite3TreeViewBareExprList(pView, pList, zLabel);
 15.6539    sqlite3TreeViewPop(pView);
 15.6540  }
 15.6541  
 15.6542 @@ -26059,7 +26739,7 @@
 15.6543  /*
 15.6544  ** Return N random bytes.
 15.6545  */
 15.6546 -SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *pBuf){
 15.6547 +SQLITE_API void sqlite3_randomness(int N, void *pBuf){
 15.6548    unsigned char t;
 15.6549    unsigned char *zBuf = pBuf;
 15.6550  
 15.6551 @@ -26135,7 +26815,7 @@
 15.6552    sqlite3_mutex_leave(mutex);
 15.6553  }
 15.6554  
 15.6555 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.6556 +#ifndef SQLITE_UNTESTABLE
 15.6557  /*
 15.6558  ** For testing purposes, we sometimes want to preserve the state of
 15.6559  ** PRNG and restore the PRNG to its saved state at a later time, or
 15.6560 @@ -26160,7 +26840,7 @@
 15.6561      sizeof(sqlite3Prng)
 15.6562    );
 15.6563  }
 15.6564 -#endif /* SQLITE_OMIT_BUILTIN_TEST */
 15.6565 +#endif /* SQLITE_UNTESTABLE */
 15.6566  
 15.6567  /************** End of random.c **********************************************/
 15.6568  /************** Begin file threads.c *****************************************/
 15.6569 @@ -27018,7 +27698,7 @@
 15.6570  ** Return whatever integer value the test callback returns, or return
 15.6571  ** SQLITE_OK if no test callback is installed.
 15.6572  */
 15.6573 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 15.6574 +#ifndef SQLITE_UNTESTABLE
 15.6575  SQLITE_PRIVATE int sqlite3FaultSim(int iTest){
 15.6576    int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback;
 15.6577    return xCallback ? xCallback(iTest) : SQLITE_OK;
 15.6578 @@ -27262,7 +27942,7 @@
 15.6579  ** case-independent fashion, using the same definition of "case
 15.6580  ** independence" that SQLite uses internally when comparing identifiers.
 15.6581  */
 15.6582 -SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *zLeft, const char *zRight){
 15.6583 +SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){
 15.6584    if( zLeft==0 ){
 15.6585      return zRight ? -1 : 0;
 15.6586    }else if( zRight==0 ){
 15.6587 @@ -27283,7 +27963,7 @@
 15.6588    }
 15.6589    return c;
 15.6590  }
 15.6591 -SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
 15.6592 +SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
 15.6593    register unsigned char *a, *b;
 15.6594    if( zLeft==0 ){
 15.6595      return zRight ? -1 : 0;
 15.6596 @@ -27689,6 +28369,7 @@
 15.6597      }
 15.6598    }
 15.6599  #endif
 15.6600 +  if( !sqlite3Isdigit(zNum[0]) ) return 0;
 15.6601    while( zNum[0]=='0' ) zNum++;
 15.6602    for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
 15.6603      v = v*10 + c;
 15.6604 @@ -28116,13 +28797,11 @@
 15.6605    u32 x;
 15.6606    memcpy(&x,p,4);
 15.6607    return x;
 15.6608 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
 15.6609 -    && defined(__GNUC__) && GCC_VERSION>=4003000
 15.6610 +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
 15.6611    u32 x;
 15.6612    memcpy(&x,p,4);
 15.6613    return __builtin_bswap32(x);
 15.6614 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
 15.6615 -    && defined(_MSC_VER) && _MSC_VER>=1300
 15.6616 +#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
 15.6617    u32 x;
 15.6618    memcpy(&x,p,4);
 15.6619    return _byteswap_ulong(x);
 15.6620 @@ -28134,12 +28813,10 @@
 15.6621  SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){
 15.6622  #if SQLITE_BYTEORDER==4321
 15.6623    memcpy(p,&v,4);
 15.6624 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
 15.6625 -    && defined(__GNUC__) && GCC_VERSION>=4003000
 15.6626 +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
 15.6627    u32 x = __builtin_bswap32(v);
 15.6628    memcpy(p,&x,4);
 15.6629 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
 15.6630 -    && defined(_MSC_VER) && _MSC_VER>=1300
 15.6631 +#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
 15.6632    u32 x = _byteswap_ulong(v);
 15.6633    memcpy(p,&x,4);
 15.6634  #else
 15.6635 @@ -28255,6 +28932,9 @@
 15.6636  ** overflow, leave *pA unchanged and return 1.
 15.6637  */
 15.6638  SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
 15.6639 +#if GCC_VERSION>=5004000
 15.6640 +  return __builtin_add_overflow(*pA, iB, pA);
 15.6641 +#else
 15.6642    i64 iA = *pA;
 15.6643    testcase( iA==0 ); testcase( iA==1 );
 15.6644    testcase( iB==-1 ); testcase( iB==0 );
 15.6645 @@ -28269,8 +28949,12 @@
 15.6646    }
 15.6647    *pA += iB;
 15.6648    return 0; 
 15.6649 +#endif
 15.6650  }
 15.6651  SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
 15.6652 +#if GCC_VERSION>=5004000
 15.6653 +  return __builtin_sub_overflow(*pA, iB, pA);
 15.6654 +#else
 15.6655    testcase( iB==SMALLEST_INT64+1 );
 15.6656    if( iB==SMALLEST_INT64 ){
 15.6657      testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
 15.6658 @@ -28280,38 +28964,28 @@
 15.6659    }else{
 15.6660      return sqlite3AddInt64(pA, -iB);
 15.6661    }
 15.6662 -}
 15.6663 -#define TWOPOWER32 (((i64)1)<<32)
 15.6664 -#define TWOPOWER31 (((i64)1)<<31)
 15.6665 +#endif
 15.6666 +}
 15.6667  SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){
 15.6668 +#if GCC_VERSION>=5004000
 15.6669 +  return __builtin_mul_overflow(*pA, iB, pA);
 15.6670 +#else
 15.6671    i64 iA = *pA;
 15.6672 -  i64 iA1, iA0, iB1, iB0, r;
 15.6673 -
 15.6674 -  iA1 = iA/TWOPOWER32;
 15.6675 -  iA0 = iA % TWOPOWER32;
 15.6676 -  iB1 = iB/TWOPOWER32;
 15.6677 -  iB0 = iB % TWOPOWER32;
 15.6678 -  if( iA1==0 ){
 15.6679 -    if( iB1==0 ){
 15.6680 -      *pA *= iB;
 15.6681 -      return 0;
 15.6682 -    }
 15.6683 -    r = iA0*iB1;
 15.6684 -  }else if( iB1==0 ){
 15.6685 -    r = iA1*iB0;
 15.6686 -  }else{
 15.6687 -    /* If both iA1 and iB1 are non-zero, overflow will result */
 15.6688 -    return 1;
 15.6689 -  }
 15.6690 -  testcase( r==(-TWOPOWER31)-1 );
 15.6691 -  testcase( r==(-TWOPOWER31) );
 15.6692 -  testcase( r==TWOPOWER31 );
 15.6693 -  testcase( r==TWOPOWER31-1 );
 15.6694 -  if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
 15.6695 -  r *= TWOPOWER32;
 15.6696 -  if( sqlite3AddInt64(&r, iA0*iB0) ) return 1;
 15.6697 -  *pA = r;
 15.6698 +  if( iB>0 ){
 15.6699 +    if( iA>LARGEST_INT64/iB ) return 1;
 15.6700 +    if( iA<SMALLEST_INT64/iB ) return 1;
 15.6701 +  }else if( iB<0 ){
 15.6702 +    if( iA>0 ){
 15.6703 +      if( iB<SMALLEST_INT64/iA ) return 1;
 15.6704 +    }else if( iA<0 ){
 15.6705 +      if( iB==SMALLEST_INT64 ) return 1;
 15.6706 +      if( iA==SMALLEST_INT64 ) return 1;
 15.6707 +      if( -iA>LARGEST_INT64/-iB ) return 1;
 15.6708 +    }
 15.6709 +  }
 15.6710 +  *pA = iA*iB;
 15.6711    return 0;
 15.6712 +#endif
 15.6713  }
 15.6714  
 15.6715  /*
 15.6716 @@ -28445,6 +29119,109 @@
 15.6717  }
 15.6718  #endif /* defined SCANSTAT or STAT4 or ESTIMATED_ROWS */
 15.6719  
 15.6720 +/*
 15.6721 +** Add a new name/number pair to a VList.  This might require that the
 15.6722 +** VList object be reallocated, so return the new VList.  If an OOM
 15.6723 +** error occurs, the original VList returned and the
 15.6724 +** db->mallocFailed flag is set.
 15.6725 +**
 15.6726 +** A VList is really just an array of integers.  To destroy a VList,
 15.6727 +** simply pass it to sqlite3DbFree().
 15.6728 +**
 15.6729 +** The first integer is the number of integers allocated for the whole
 15.6730 +** VList.  The second integer is the number of integers actually used.
 15.6731 +** Each name/number pair is encoded by subsequent groups of 3 or more
 15.6732 +** integers.
 15.6733 +**
 15.6734 +** Each name/number pair starts with two integers which are the numeric
 15.6735 +** value for the pair and the size of the name/number pair, respectively.
 15.6736 +** The text name overlays one or more following integers.  The text name
 15.6737 +** is always zero-terminated.
 15.6738 +**
 15.6739 +** Conceptually:
 15.6740 +**
 15.6741 +**    struct VList {
 15.6742 +**      int nAlloc;   // Number of allocated slots 
 15.6743 +**      int nUsed;    // Number of used slots 
 15.6744 +**      struct VListEntry {
 15.6745 +**        int iValue;    // Value for this entry
 15.6746 +**        int nSlot;     // Slots used by this entry
 15.6747 +**        // ... variable name goes here
 15.6748 +**      } a[0];
 15.6749 +**    }
 15.6750 +**
 15.6751 +** During code generation, pointers to the variable names within the
 15.6752 +** VList are taken.  When that happens, nAlloc is set to zero as an 
 15.6753 +** indication that the VList may never again be enlarged, since the
 15.6754 +** accompanying realloc() would invalidate the pointers.
 15.6755 +*/
 15.6756 +SQLITE_PRIVATE VList *sqlite3VListAdd(
 15.6757 +  sqlite3 *db,           /* The database connection used for malloc() */
 15.6758 +  VList *pIn,            /* The input VList.  Might be NULL */
 15.6759 +  const char *zName,     /* Name of symbol to add */
 15.6760 +  int nName,             /* Bytes of text in zName */
 15.6761 +  int iVal               /* Value to associate with zName */
 15.6762 +){
 15.6763 +  int nInt;              /* number of sizeof(int) objects needed for zName */
 15.6764 +  char *z;               /* Pointer to where zName will be stored */
 15.6765 +  int i;                 /* Index in pIn[] where zName is stored */
 15.6766 +
 15.6767 +  nInt = nName/4 + 3;
 15.6768 +  assert( pIn==0 || pIn[0]>=3 );  /* Verify ok to add new elements */
 15.6769 +  if( pIn==0 || pIn[1]+nInt > pIn[0] ){
 15.6770 +    /* Enlarge the allocation */
 15.6771 +    int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt;
 15.6772 +    VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
 15.6773 +    if( pOut==0 ) return pIn;
 15.6774 +    if( pIn==0 ) pOut[1] = 2;
 15.6775 +    pIn = pOut;
 15.6776 +    pIn[0] = nAlloc;
 15.6777 +  }
 15.6778 +  i = pIn[1];
 15.6779 +  pIn[i] = iVal;
 15.6780 +  pIn[i+1] = nInt;
 15.6781 +  z = (char*)&pIn[i+2];
 15.6782 +  pIn[1] = i+nInt;
 15.6783 +  assert( pIn[1]<=pIn[0] );
 15.6784 +  memcpy(z, zName, nName);
 15.6785 +  z[nName] = 0;
 15.6786 +  return pIn;
 15.6787 +}
 15.6788 +
 15.6789 +/*
 15.6790 +** Return a pointer to the name of a variable in the given VList that
 15.6791 +** has the value iVal.  Or return a NULL if there is no such variable in
 15.6792 +** the list
 15.6793 +*/
 15.6794 +SQLITE_PRIVATE const char *sqlite3VListNumToName(VList *pIn, int iVal){
 15.6795 +  int i, mx;
 15.6796 +  if( pIn==0 ) return 0;
 15.6797 +  mx = pIn[1];
 15.6798 +  i = 2;
 15.6799 +  do{
 15.6800 +    if( pIn[i]==iVal ) return (char*)&pIn[i+2];
 15.6801 +    i += pIn[i+1];
 15.6802 +  }while( i<mx );
 15.6803 +  return 0;
 15.6804 +}
 15.6805 +
 15.6806 +/*
 15.6807 +** Return the number of the variable named zName, if it is in VList.
 15.6808 +** or return 0 if there is no such variable.
 15.6809 +*/
 15.6810 +SQLITE_PRIVATE int sqlite3VListNameToNum(VList *pIn, const char *zName, int nName){
 15.6811 +  int i, mx;
 15.6812 +  if( pIn==0 ) return 0;
 15.6813 +  mx = pIn[1];
 15.6814 +  i = 2;
 15.6815 +  do{
 15.6816 +    const char *z = (const char*)&pIn[i+2];
 15.6817 +    if( strncmp(z,zName,nName)==0 && z[nName]==0 ) return pIn[i];
 15.6818 +    i += pIn[i+1];
 15.6819 +  }while( i<mx );
 15.6820 +  return 0;
 15.6821 +}
 15.6822 +
 15.6823  /************** End of util.c ************************************************/
 15.6824  /************** Begin file hash.c ********************************************/
 15.6825  /*
 15.6826 @@ -28505,7 +29282,11 @@
 15.6827    unsigned int h = 0;
 15.6828    unsigned char c;
 15.6829    while( (c = (unsigned char)*z++)!=0 ){     /*OPTIMIZATION-IF-TRUE*/
 15.6830 -    h = (h<<3) ^ h ^ sqlite3UpperToLower[c];
 15.6831 +    /* Knuth multiplicative hashing.  (Sorting & Searching, p. 510).
 15.6832 +    ** 0x9e3779b1 is 2654435761 which is the closest prime number to
 15.6833 +    ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2. */
 15.6834 +    h += sqlite3UpperToLower[c];
 15.6835 +    h *= 0x9e3779b1;
 15.6836    }
 15.6837    return h;
 15.6838  }
 15.6839 @@ -28752,144 +29533,149 @@
 15.6840      /*  20 */ "Once"             OpHelp(""),
 15.6841      /*  21 */ "If"               OpHelp(""),
 15.6842      /*  22 */ "IfNot"            OpHelp(""),
 15.6843 -    /*  23 */ "SeekLT"           OpHelp("key=r[P3@P4]"),
 15.6844 -    /*  24 */ "SeekLE"           OpHelp("key=r[P3@P4]"),
 15.6845 -    /*  25 */ "SeekGE"           OpHelp("key=r[P3@P4]"),
 15.6846 -    /*  26 */ "SeekGT"           OpHelp("key=r[P3@P4]"),
 15.6847 -    /*  27 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
 15.6848 -    /*  28 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
 15.6849 -    /*  29 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
 15.6850 -    /*  30 */ "NotFound"         OpHelp("key=r[P3@P4]"),
 15.6851 -    /*  31 */ "Found"            OpHelp("key=r[P3@P4]"),
 15.6852 +    /*  23 */ "IfNullRow"        OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
 15.6853 +    /*  24 */ "SeekLT"           OpHelp("key=r[P3@P4]"),
 15.6854 +    /*  25 */ "SeekLE"           OpHelp("key=r[P3@P4]"),
 15.6855 +    /*  26 */ "SeekGE"           OpHelp("key=r[P3@P4]"),
 15.6856 +    /*  27 */ "SeekGT"           OpHelp("key=r[P3@P4]"),
 15.6857 +    /*  28 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
 15.6858 +    /*  29 */ "NotFound"         OpHelp("key=r[P3@P4]"),
 15.6859 +    /*  30 */ "Found"            OpHelp("key=r[P3@P4]"),
 15.6860 +    /*  31 */ "SeekRowid"        OpHelp("intkey=r[P3]"),
 15.6861      /*  32 */ "NotExists"        OpHelp("intkey=r[P3]"),
 15.6862      /*  33 */ "Last"             OpHelp(""),
 15.6863 -    /*  34 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
 15.6864 -    /*  35 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
 15.6865 -    /*  36 */ "Ne"               OpHelp("if r[P1]!=r[P3] goto P2"),
 15.6866 -    /*  37 */ "Eq"               OpHelp("if r[P1]==r[P3] goto P2"),
 15.6867 -    /*  38 */ "Gt"               OpHelp("if r[P1]>r[P3] goto P2"),
 15.6868 -    /*  39 */ "Le"               OpHelp("if r[P1]<=r[P3] goto P2"),
 15.6869 -    /*  40 */ "Lt"               OpHelp("if r[P1]<r[P3] goto P2"),
 15.6870 -    /*  41 */ "Ge"               OpHelp("if r[P1]>=r[P3] goto P2"),
 15.6871 -    /*  42 */ "SorterSort"       OpHelp(""),
 15.6872 -    /*  43 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
 15.6873 -    /*  44 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
 15.6874 -    /*  45 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
 15.6875 -    /*  46 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
 15.6876 -    /*  47 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
 15.6877 -    /*  48 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
 15.6878 -    /*  49 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
 15.6879 -    /*  50 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
 15.6880 -    /*  51 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
 15.6881 -    /*  52 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
 15.6882 -    /*  53 */ "Sort"             OpHelp(""),
 15.6883 -    /*  54 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
 15.6884 -    /*  55 */ "Rewind"           OpHelp(""),
 15.6885 -    /*  56 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
 15.6886 -    /*  57 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
 15.6887 -    /*  58 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
 15.6888 -    /*  59 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
 15.6889 -    /*  60 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
 15.6890 -    /*  61 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
 15.6891 -    /*  62 */ "Program"          OpHelp(""),
 15.6892 -    /*  63 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
 15.6893 -    /*  64 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
 15.6894 -    /*  65 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
 15.6895 -    /*  66 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
 15.6896 -    /*  67 */ "IncrVacuum"       OpHelp(""),
 15.6897 -    /*  68 */ "VNext"            OpHelp(""),
 15.6898 -    /*  69 */ "Init"             OpHelp("Start at P2"),
 15.6899 -    /*  70 */ "Return"           OpHelp(""),
 15.6900 -    /*  71 */ "EndCoroutine"     OpHelp(""),
 15.6901 -    /*  72 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
 15.6902 -    /*  73 */ "Halt"             OpHelp(""),
 15.6903 -    /*  74 */ "Integer"          OpHelp("r[P2]=P1"),
 15.6904 -    /*  75 */ "Int64"            OpHelp("r[P2]=P4"),
 15.6905 -    /*  76 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
 15.6906 -    /*  77 */ "Null"             OpHelp("r[P2..P3]=NULL"),
 15.6907 -    /*  78 */ "SoftNull"         OpHelp("r[P1]=NULL"),
 15.6908 -    /*  79 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
 15.6909 -    /*  80 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
 15.6910 -    /*  81 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
 15.6911 -    /*  82 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
 15.6912 -    /*  83 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
 15.6913 -    /*  84 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
 15.6914 -    /*  85 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
 15.6915 -    /*  86 */ "CollSeq"          OpHelp(""),
 15.6916 -    /*  87 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
 15.6917 -    /*  88 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
 15.6918 -    /*  89 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
 15.6919 -    /*  90 */ "RealAffinity"     OpHelp(""),
 15.6920 -    /*  91 */ "Cast"             OpHelp("affinity(r[P1])"),
 15.6921 -    /*  92 */ "Permutation"      OpHelp(""),
 15.6922 -    /*  93 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
 15.6923 -    /*  94 */ "Column"           OpHelp("r[P3]=PX"),
 15.6924 -    /*  95 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
 15.6925 -    /*  96 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
 15.6926 +    /*  34 */ "IfSmaller"        OpHelp(""),
 15.6927 +    /*  35 */ "SorterSort"       OpHelp(""),
 15.6928 +    /*  36 */ "Sort"             OpHelp(""),
 15.6929 +    /*  37 */ "Rewind"           OpHelp(""),
 15.6930 +    /*  38 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
 15.6931 +    /*  39 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
 15.6932 +    /*  40 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
 15.6933 +    /*  41 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
 15.6934 +    /*  42 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
 15.6935 +    /*  43 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
 15.6936 +    /*  44 */ "Program"          OpHelp(""),
 15.6937 +    /*  45 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
 15.6938 +    /*  46 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
 15.6939 +    /*  47 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
 15.6940 +    /*  48 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
 15.6941 +    /*  49 */ "IncrVacuum"       OpHelp(""),
 15.6942 +    /*  50 */ "VNext"            OpHelp(""),
 15.6943 +    /*  51 */ "Init"             OpHelp("Start at P2"),
 15.6944 +    /*  52 */ "Return"           OpHelp(""),
 15.6945 +    /*  53 */ "EndCoroutine"     OpHelp(""),
 15.6946 +    /*  54 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
 15.6947 +    /*  55 */ "Halt"             OpHelp(""),
 15.6948 +    /*  56 */ "Integer"          OpHelp("r[P2]=P1"),
 15.6949 +    /*  57 */ "Int64"            OpHelp("r[P2]=P4"),
 15.6950 +    /*  58 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
 15.6951 +    /*  59 */ "Null"             OpHelp("r[P2..P3]=NULL"),
 15.6952 +    /*  60 */ "SoftNull"         OpHelp("r[P1]=NULL"),
 15.6953 +    /*  61 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
 15.6954 +    /*  62 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
 15.6955 +    /*  63 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
 15.6956 +    /*  64 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
 15.6957 +    /*  65 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
 15.6958 +    /*  66 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
 15.6959 +    /*  67 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
 15.6960 +    /*  68 */ "CollSeq"          OpHelp(""),
 15.6961 +    /*  69 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
 15.6962 +    /*  70 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
 15.6963 +    /*  71 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
 15.6964 +    /*  72 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
 15.6965 +    /*  73 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
 15.6966 +    /*  74 */ "RealAffinity"     OpHelp(""),
 15.6967 +    /*  75 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
 15.6968 +    /*  76 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
 15.6969 +    /*  77 */ "Ne"               OpHelp("IF r[P3]!=r[P1]"),
 15.6970 +    /*  78 */ "Eq"               OpHelp("IF r[P3]==r[P1]"),
 15.6971 +    /*  79 */ "Gt"               OpHelp("IF r[P3]>r[P1]"),
 15.6972 +    /*  80 */ "Le"               OpHelp("IF r[P3]<=r[P1]"),
 15.6973 +    /*  81 */ "Lt"               OpHelp("IF r[P3]<r[P1]"),
 15.6974 +    /*  82 */ "Ge"               OpHelp("IF r[P3]>=r[P1]"),
 15.6975 +    /*  83 */ "ElseNotEq"        OpHelp(""),
 15.6976 +    /*  84 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
 15.6977 +    /*  85 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
 15.6978 +    /*  86 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
 15.6979 +    /*  87 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
 15.6980 +    /*  88 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
 15.6981 +    /*  89 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
 15.6982 +    /*  90 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
 15.6983 +    /*  91 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
 15.6984 +    /*  92 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
 15.6985 +    /*  93 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
 15.6986 +    /*  94 */ "Cast"             OpHelp("affinity(r[P1])"),
 15.6987 +    /*  95 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
 15.6988 +    /*  96 */ "Permutation"      OpHelp(""),
 15.6989      /*  97 */ "String8"          OpHelp("r[P2]='P4'"),
 15.6990 -    /*  98 */ "Count"            OpHelp("r[P2]=count()"),
 15.6991 -    /*  99 */ "ReadCookie"       OpHelp(""),
 15.6992 -    /* 100 */ "SetCookie"        OpHelp(""),
 15.6993 -    /* 101 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
 15.6994 -    /* 102 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
 15.6995 -    /* 103 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
 15.6996 -    /* 104 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
 15.6997 -    /* 105 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
 15.6998 -    /* 106 */ "SorterOpen"       OpHelp(""),
 15.6999 -    /* 107 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
 15.7000 -    /* 108 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
 15.7001 -    /* 109 */ "Close"            OpHelp(""),
 15.7002 -    /* 110 */ "ColumnsUsed"      OpHelp(""),
 15.7003 -    /* 111 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
 15.7004 -    /* 112 */ "NewRowid"         OpHelp("r[P2]=rowid"),
 15.7005 -    /* 113 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
 15.7006 -    /* 114 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
 15.7007 -    /* 115 */ "Delete"           OpHelp(""),
 15.7008 -    /* 116 */ "ResetCount"       OpHelp(""),
 15.7009 -    /* 117 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
 15.7010 -    /* 118 */ "SorterData"       OpHelp("r[P2]=data"),
 15.7011 -    /* 119 */ "RowKey"           OpHelp("r[P2]=key"),
 15.7012 -    /* 120 */ "RowData"          OpHelp("r[P2]=data"),
 15.7013 -    /* 121 */ "Rowid"            OpHelp("r[P2]=rowid"),
 15.7014 -    /* 122 */ "NullRow"          OpHelp(""),
 15.7015 -    /* 123 */ "SorterInsert"     OpHelp(""),
 15.7016 -    /* 124 */ "IdxInsert"        OpHelp("key=r[P2]"),
 15.7017 -    /* 125 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
 15.7018 -    /* 126 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
 15.7019 -    /* 127 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
 15.7020 -    /* 128 */ "Destroy"          OpHelp(""),
 15.7021 -    /* 129 */ "Clear"            OpHelp(""),
 15.7022 -    /* 130 */ "ResetSorter"      OpHelp(""),
 15.7023 -    /* 131 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
 15.7024 -    /* 132 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
 15.7025 -    /* 133 */ "Real"             OpHelp("r[P2]=P4"),
 15.7026 -    /* 134 */ "ParseSchema"      OpHelp(""),
 15.7027 -    /* 135 */ "LoadAnalysis"     OpHelp(""),
 15.7028 -    /* 136 */ "DropTable"        OpHelp(""),
 15.7029 -    /* 137 */ "DropIndex"        OpHelp(""),
 15.7030 -    /* 138 */ "DropTrigger"      OpHelp(""),
 15.7031 -    /* 139 */ "IntegrityCk"      OpHelp(""),
 15.7032 -    /* 140 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
 15.7033 -    /* 141 */ "Param"            OpHelp(""),
 15.7034 -    /* 142 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
 15.7035 -    /* 143 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
 15.7036 -    /* 144 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
 15.7037 -    /* 145 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
 15.7038 -    /* 146 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
 15.7039 -    /* 147 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
 15.7040 -    /* 148 */ "Expire"           OpHelp(""),
 15.7041 -    /* 149 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
 15.7042 -    /* 150 */ "VBegin"           OpHelp(""),
 15.7043 -    /* 151 */ "VCreate"          OpHelp(""),
 15.7044 -    /* 152 */ "VDestroy"         OpHelp(""),
 15.7045 -    /* 153 */ "VOpen"            OpHelp(""),
 15.7046 -    /* 154 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
 15.7047 -    /* 155 */ "VRename"          OpHelp(""),
 15.7048 -    /* 156 */ "Pagecount"        OpHelp(""),
 15.7049 -    /* 157 */ "MaxPgcnt"         OpHelp(""),
 15.7050 -    /* 158 */ "CursorHint"       OpHelp(""),
 15.7051 -    /* 159 */ "Noop"             OpHelp(""),
 15.7052 -    /* 160 */ "Explain"          OpHelp(""),
 15.7053 +    /*  98 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
 15.7054 +    /*  99 */ "Column"           OpHelp("r[P3]=PX"),
 15.7055 +    /* 100 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
 15.7056 +    /* 101 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
 15.7057 +    /* 102 */ "Count"            OpHelp("r[P2]=count()"),
 15.7058 +    /* 103 */ "ReadCookie"       OpHelp(""),
 15.7059 +    /* 104 */ "SetCookie"        OpHelp(""),
 15.7060 +    /* 105 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
 15.7061 +    /* 106 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
 15.7062 +    /* 107 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
 15.7063 +    /* 108 */ "OpenDup"          OpHelp(""),
 15.7064 +    /* 109 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
 15.7065 +    /* 110 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
 15.7066 +    /* 111 */ "SorterOpen"       OpHelp(""),
 15.7067 +    /* 112 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
 15.7068 +    /* 113 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
 15.7069 +    /* 114 */ "Close"            OpHelp(""),
 15.7070 +    /* 115 */ "ColumnsUsed"      OpHelp(""),
 15.7071 +    /* 116 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
 15.7072 +    /* 117 */ "NewRowid"         OpHelp("r[P2]=rowid"),
 15.7073 +    /* 118 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
 15.7074 +    /* 119 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
 15.7075 +    /* 120 */ "Delete"           OpHelp(""),
 15.7076 +    /* 121 */ "ResetCount"       OpHelp(""),
 15.7077 +    /* 122 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
 15.7078 +    /* 123 */ "SorterData"       OpHelp("r[P2]=data"),
 15.7079 +    /* 124 */ "RowData"          OpHelp("r[P2]=data"),
 15.7080 +    /* 125 */ "Rowid"            OpHelp("r[P2]=rowid"),
 15.7081 +    /* 126 */ "NullRow"          OpHelp(""),
 15.7082 +    /* 127 */ "SorterInsert"     OpHelp("key=r[P2]"),
 15.7083 +    /* 128 */ "IdxInsert"        OpHelp("key=r[P2]"),
 15.7084 +    /* 129 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
 15.7085 +    /* 130 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
 15.7086 +    /* 131 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
 15.7087 +    /* 132 */ "Real"             OpHelp("r[P2]=P4"),
 15.7088 +    /* 133 */ "Destroy"          OpHelp(""),
 15.7089 +    /* 134 */ "Clear"            OpHelp(""),
 15.7090 +    /* 135 */ "ResetSorter"      OpHelp(""),
 15.7091 +    /* 136 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
 15.7092 +    /* 137 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
 15.7093 +    /* 138 */ "SqlExec"          OpHelp(""),
 15.7094 +    /* 139 */ "ParseSchema"      OpHelp(""),
 15.7095 +    /* 140 */ "LoadAnalysis"     OpHelp(""),
 15.7096 +    /* 141 */ "DropTable"        OpHelp(""),
 15.7097 +    /* 142 */ "DropIndex"        OpHelp(""),
 15.7098 +    /* 143 */ "DropTrigger"      OpHelp(""),
 15.7099 +    /* 144 */ "IntegrityCk"      OpHelp(""),
 15.7100 +    /* 145 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
 15.7101 +    /* 146 */ "Param"            OpHelp(""),
 15.7102 +    /* 147 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
 15.7103 +    /* 148 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
 15.7104 +    /* 149 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
 15.7105 +    /* 150 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
 15.7106 +    /* 151 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
 15.7107 +    /* 152 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
 15.7108 +    /* 153 */ "Expire"           OpHelp(""),
 15.7109 +    /* 154 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
 15.7110 +    /* 155 */ "VBegin"           OpHelp(""),
 15.7111 +    /* 156 */ "VCreate"          OpHelp(""),
 15.7112 +    /* 157 */ "VDestroy"         OpHelp(""),
 15.7113 +    /* 158 */ "VOpen"            OpHelp(""),
 15.7114 +    /* 159 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
 15.7115 +    /* 160 */ "VRename"          OpHelp(""),
 15.7116 +    /* 161 */ "Pagecount"        OpHelp(""),
 15.7117 +    /* 162 */ "MaxPgcnt"         OpHelp(""),
 15.7118 +    /* 163 */ "CursorHint"       OpHelp(""),
 15.7119 +    /* 164 */ "Noop"             OpHelp(""),
 15.7120 +    /* 165 */ "Explain"          OpHelp(""),
 15.7121    };
 15.7122    return azName[i];
 15.7123  }
 15.7124 @@ -29239,8 +30025,8 @@
 15.7125  ** This file contains inline asm code for retrieving "high-performance"
 15.7126  ** counters for x86 class CPUs.
 15.7127  */
 15.7128 -#ifndef _HWTIME_H_
 15.7129 -#define _HWTIME_H_
 15.7130 +#ifndef SQLITE_HWTIME_H
 15.7131 +#define SQLITE_HWTIME_H
 15.7132  
 15.7133  /*
 15.7134  ** The following routine only works on pentium-class (or newer) processors.
 15.7135 @@ -29308,7 +30094,7 @@
 15.7136  
 15.7137  #endif
 15.7138  
 15.7139 -#endif /* !defined(_HWTIME_H_) */
 15.7140 +#endif /* !defined(SQLITE_HWTIME_H) */
 15.7141  
 15.7142  /************** End of hwtime.h **********************************************/
 15.7143  /************** Continuing where we left off in os_common.h ******************/
 15.7144 @@ -30158,7 +30944,14 @@
 15.7145  #if OS_VXWORKS
 15.7146    struct vxworksFileId *pId;  /* Unique file ID for vxworks. */
 15.7147  #else
 15.7148 -  ino_t ino;                  /* Inode number */