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" />
     6.1 --- a/src/etpan_mime.c	Fri Jun 30 16:33:08 2017 +0200
     6.2 +++ b/src/etpan_mime.c	Wed Jul 19 10:22:13 2017 +0200
     6.3 @@ -183,7 +183,7 @@
     6.4  }
     6.5  
     6.6  struct mailmime * get_text_part(
     6.7 -        const char * filename,
     6.8 +        pEp_rid_list_t* resource,
     6.9          const char * mime_type,
    6.10          const char * text,
    6.11          size_t length,
    6.12 @@ -197,33 +197,45 @@
    6.13  	struct mailmime_parameter * param = NULL;
    6.14  	struct mailmime_disposition * disposition = NULL;
    6.15  	struct mailmime_mechanism * encoding = NULL;
    6.16 +    char* content_id = NULL;
    6.17      int r;
    6.18 +                
    6.19 +    if (resource != NULL && resource->rid != NULL) {
    6.20 +        switch (resource->rid_type) {
    6.21 +            case PEP_RID_CID:
    6.22 +                content_id = strdup(resource->rid);
    6.23 +                break;
    6.24 +            case PEP_RID_FILENAME:
    6.25 +            default:
    6.26 +                disposition_name = strdup(resource->rid);
    6.27 +                if (disposition_name == NULL)
    6.28 +                    goto enomem;
    6.29 +                    
    6.30 +                disposition =
    6.31 +                        mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_INLINE,
    6.32 +                                disposition_name, NULL, NULL, NULL, (size_t) -1);
    6.33 +
    6.34 +                if (disposition == NULL)
    6.35 +                    goto enomem;
    6.36 +
    6.37 +                disposition_name = NULL;                
    6.38 +                break;
    6.39 +        }    
    6.40 +    }
    6.41      
    6.42 -    if (filename != NULL) {
    6.43 -        disposition_name = strdup(filename);
    6.44 -        if (disposition_name == NULL)
    6.45 -            goto enomem;
    6.46 -    }
    6.47 -
    6.48      if (encoding_type) {
    6.49          encoding = mailmime_mechanism_new(encoding_type, NULL);
    6.50          if (encoding == NULL)
    6.51              goto enomem;
    6.52      }
    6.53  
    6.54 -    disposition =
    6.55 -            mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_INLINE,
    6.56 -                    disposition_name, NULL, NULL, NULL, (size_t) -1);
    6.57 -    if (disposition == NULL)
    6.58 -        goto enomem;
    6.59 -    disposition_name = NULL;
    6.60 -
    6.61 -    mime_fields = mailmime_fields_new_with_data(encoding, NULL, NULL,
    6.62 +    mime_fields = mailmime_fields_new_with_data(encoding, content_id, NULL,
    6.63              disposition, NULL);
    6.64      if (mime_fields == NULL)
    6.65          goto enomem;
    6.66      encoding = NULL;
    6.67      disposition = NULL;
    6.68 +    content_id = NULL;
    6.69  
    6.70  	content = mailmime_content_new_with_str(mime_type);
    6.71      if (content == NULL)
    6.72 @@ -269,7 +281,7 @@
    6.73  }
    6.74  
    6.75  struct mailmime * get_file_part(
    6.76 -        const char * filename,
    6.77 +        pEp_rid_list_t* resource,
    6.78          const char * mime_type,
    6.79          char * data,
    6.80          size_t length
    6.81 @@ -282,20 +294,32 @@
    6.82      struct mailmime_content * content = NULL;
    6.83      struct mailmime * mime = NULL;
    6.84      struct mailmime_fields * mime_fields = NULL;
    6.85 +    char* content_id = NULL;
    6.86      int r;
    6.87 -
    6.88 -    if (filename != NULL) {
    6.89 -        disposition_name = strdup(filename);
    6.90 -        if (disposition_name == NULL)
    6.91 -            goto enomem;
    6.92 +                
    6.93 +    if (resource != NULL && resource->rid != NULL) {
    6.94 +        switch (resource->rid_type) {
    6.95 +            case PEP_RID_CID:
    6.96 +                content_id = strdup(resource->rid);
    6.97 +                break;
    6.98 +            case PEP_RID_FILENAME:
    6.99 +            default:
   6.100 +                disposition_name = strdup(resource->rid);
   6.101 +                if (disposition_name == NULL)
   6.102 +                    goto enomem;
   6.103 +                    
   6.104 +                disposition =
   6.105 +                        mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_ATTACHMENT,
   6.106 +                                disposition_name, NULL, NULL, NULL, (size_t) -1);
   6.107 +                                
   6.108 +                if (disposition == NULL)
   6.109 +                    goto enomem;
   6.110 +                disposition_name = NULL;
   6.111 +                
   6.112 +                break;
   6.113 +        }    
   6.114      }
   6.115 -
   6.116 -    disposition =
   6.117 -            mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_ATTACHMENT,
   6.118 -                    disposition_name, NULL, NULL, NULL, (size_t) -1);
   6.119 -    if (disposition == NULL)
   6.120 -        goto enomem;
   6.121 -    disposition_name = NULL;
   6.122 +    
   6.123  
   6.124      content = mailmime_content_new_with_str(mime_type);
   6.125      if (content == NULL)
   6.126 @@ -306,7 +330,7 @@
   6.127      if (encoding == NULL)
   6.128          goto enomem;
   6.129  
   6.130 -    mime_fields = mailmime_fields_new_with_data(encoding, NULL, NULL,
   6.131 +    mime_fields = mailmime_fields_new_with_data(encoding, content_id, NULL,
   6.132              disposition, NULL);
   6.133      if (mime_fields == NULL)
   6.134          goto enomem;
   6.135 @@ -340,7 +364,7 @@
   6.136          mailmime_fields_free(mime_fields);
   6.137      if (mime)
   6.138          mailmime_free(mime);
   6.139 -
   6.140 +    
   6.141      return NULL;
   6.142  }
   6.143  
   6.144 @@ -596,7 +620,9 @@
   6.145      return content;
   6.146  }
   6.147  
   6.148 -char * _get_filename(struct mailmime *mime)
   6.149 +
   6.150 +/* Return a list of identifier_type and resource id (filename, cid, etc) */
   6.151 +pEp_rid_list_t* _get_resource_id_list(struct mailmime *mime)
   6.152  {
   6.153      clist * _fieldlist = NULL;
   6.154  
   6.155 @@ -608,9 +634,22 @@
   6.156          return NULL;
   6.157  
   6.158      clistiter *cur;
   6.159 +
   6.160 +    pEp_rid_list_t* rid_list = NULL; 
   6.161 +    pEp_rid_list_t** rid_list_curr_p = &rid_list; 
   6.162 +        
   6.163      for (cur = clist_begin(_fieldlist); cur; cur = clist_next(cur)) {
   6.164          struct mailmime_field * _field = clist_content(cur);
   6.165 -        if (_field && _field->fld_type == MAILMIME_FIELD_DISPOSITION) {
   6.166 +        /* content_id */
   6.167 +        if (_field && _field->fld_type == MAILMIME_FIELD_ID) {
   6.168 +            pEp_rid_list_t* new_rid = (pEp_rid_list_t*)calloc(1, sizeof(pEp_rid_list_t));
   6.169 +            new_rid->rid_type = PEP_RID_CID;
   6.170 +            new_rid->rid = strdup(_field->fld_data.fld_id);
   6.171 +            *rid_list_curr_p = new_rid;
   6.172 +            rid_list_curr_p = &new_rid->next;
   6.173 +        }
   6.174 +        else if (_field && _field->fld_type == MAILMIME_FIELD_DISPOSITION) {
   6.175 +            /* filename */
   6.176              if (_field->fld_data.fld_disposition &&
   6.177                      _field->fld_data.fld_disposition->dsp_parms) {
   6.178                  clist * _parmlist =
   6.179 @@ -620,14 +659,66 @@
   6.180                          clist_next(cur2)) {
   6.181                      struct mailmime_disposition_parm * param =
   6.182                              clist_content(cur2);
   6.183 -                    if (param->pa_type == MAILMIME_DISPOSITION_PARM_FILENAME)
   6.184 -                        return param->pa_data.pa_filename;
   6.185 +                    if (param->pa_type == MAILMIME_DISPOSITION_PARM_FILENAME) {
   6.186 +                        pEp_rid_list_t* new_rid = (pEp_rid_list_t*)calloc(1, sizeof(pEp_rid_list_t));
   6.187 +                        new_rid->rid_type = PEP_RID_FILENAME;
   6.188 +                        new_rid->rid = strdup(param->pa_data.pa_filename);
   6.189 +                        *rid_list_curr_p = new_rid;
   6.190 +                        rid_list_curr_p = &new_rid->next;
   6.191 +                    }                
   6.192                  }
   6.193              }
   6.194          }
   6.195      }
   6.196 +    /* Will almost certainly usually be a singleton, but we need to be able to decide */
   6.197 +    return rid_list;
   6.198 +}
   6.199  
   6.200 -    return NULL;
   6.201 +
   6.202 +/* FIXME: about to be obsoleted? */
   6.203 +char * _get_filename_or_cid(struct mailmime *mime)
   6.204 +{
   6.205 +    clist * _fieldlist = NULL;
   6.206 +
   6.207 +    assert(mime);
   6.208 +
   6.209 +    if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list)
   6.210 +        _fieldlist = mime->mm_mime_fields->fld_list;
   6.211 +    else
   6.212 +        return NULL;
   6.213 +
   6.214 +    clistiter *cur;
   6.215 +    
   6.216 +    char* _temp_filename_ptr = NULL;
   6.217 +    
   6.218 +    for (cur = clist_begin(_fieldlist); cur; cur = clist_next(cur)) {
   6.219 +        struct mailmime_field * _field = clist_content(cur);
   6.220 +        if (_field && _field->fld_type == MAILMIME_FIELD_ID) {
   6.221 +            /* We prefer CIDs to filenames when both are present */
   6.222 +            free(_temp_filename_ptr); /* can be null, it's ok */
   6.223 +            return build_uri("cid", _field->fld_data.fld_id); 
   6.224 +        }
   6.225 +        else if (_field && _field->fld_type == MAILMIME_FIELD_DISPOSITION) {
   6.226 +            if (_field->fld_data.fld_disposition &&
   6.227 +                    _field->fld_data.fld_disposition->dsp_parms &&
   6.228 +                    !_temp_filename_ptr) {
   6.229 +                clist * _parmlist =
   6.230 +                        _field->fld_data.fld_disposition->dsp_parms;
   6.231 +                clistiter *cur2;
   6.232 +                for (cur2 = clist_begin(_parmlist); cur2; cur2 =
   6.233 +                        clist_next(cur2)) {
   6.234 +                    struct mailmime_disposition_parm * param =
   6.235 +                            clist_content(cur2);
   6.236 +                    if (param->pa_type == MAILMIME_DISPOSITION_PARM_FILENAME) {
   6.237 +                        _temp_filename_ptr = build_uri("file", param->pa_data.pa_filename);
   6.238 +                        break;
   6.239 +                    }                
   6.240 +                }
   6.241 +            }
   6.242 +        }
   6.243 +    }
   6.244 +    /* Ok, it wasn't a CID */
   6.245 +    return _temp_filename_ptr;
   6.246  }
   6.247  
   6.248  static bool parameter_has_value(
   6.249 @@ -784,4 +875,3 @@
   6.250  
   6.251      return EINVAL;
   6.252  }
   6.253 -
     7.1 --- a/src/etpan_mime.h	Fri Jun 30 16:33:08 2017 +0200
     7.2 +++ b/src/etpan_mime.h	Wed Jul 19 10:22:13 2017 +0200
     7.3 @@ -7,6 +7,8 @@
     7.4  #include <libetpan/mailmime.h>
     7.5  #include <libetpan/mailmime_encode.h>
     7.6  
     7.7 +#include "resource_id.h"
     7.8 +
     7.9  struct mailmime * part_new_empty(
    7.10          struct mailmime_content * content,
    7.11          struct mailmime_fields * mime_fields,
    7.12 @@ -16,7 +18,7 @@
    7.13  struct mailmime * get_pgp_encrypted_part(void);
    7.14  
    7.15  struct mailmime * get_text_part(
    7.16 -        const char * filename,
    7.17 +        pEp_rid_list_t* resource,
    7.18          const char * mime_type,
    7.19          const char * text,
    7.20          size_t length,
    7.21 @@ -24,7 +26,7 @@
    7.22      );
    7.23  
    7.24  struct mailmime * get_file_part(
    7.25 -        const char * filename,
    7.26 +        pEp_rid_list_t* resource,
    7.27          const char * mime_type,
    7.28          char * data,
    7.29          size_t length
    7.30 @@ -70,7 +72,9 @@
    7.31  
    7.32  clist * _get_fields(struct mailmime * mime);
    7.33  struct mailmime_content * _get_content(struct mailmime * mime);
    7.34 -char * _get_filename(struct mailmime *mime);
    7.35 +char * _get_filename_or_cid(struct mailmime *mime);
    7.36 +pEp_rid_list_t* _get_resource_id_list(struct mailmime *mime);
    7.37 +char* _build_uri(char* uri_prefix, char* resource);
    7.38  bool _is_multipart(struct mailmime_content *content, const char *subtype);
    7.39  bool _is_PGP_MIME(struct mailmime_content *content);
    7.40  bool _is_text_part(struct mailmime_content *content, const char *subtype);
    7.41 @@ -80,4 +84,3 @@
    7.42          char **type,
    7.43          char **charset
    7.44      );
    7.45 -
     8.1 --- a/src/message_api.c	Fri Jun 30 16:33:08 2017 +0200
     8.2 +++ b/src/message_api.c	Wed Jul 19 10:22:13 2017 +0200
     8.3 @@ -20,6 +20,29 @@
     8.4  #define _MAX(A, B) ((B) > (A) ? (B) : (A))
     8.5  #endif
     8.6  
     8.7 +static char* _get_resource_ptr_noown(char* uri) {
     8.8 +    char* uri_delim = strstr(uri, "://");
     8.9 +    if (!uri_delim)
    8.10 +        return uri;
    8.11 +    else
    8.12 +        return uri + 3;
    8.13 +}
    8.14 +
    8.15 +static char* get_resource(char* uri) {
    8.16 +    const char* resource_ptr = _get_resource_ptr_noown(uri);
    8.17 +    char* resource_str = NULL;
    8.18 +    if (resource_ptr)
    8.19 +        resource_str = strdup(resource_ptr);
    8.20 +    return resource_str;
    8.21 +}
    8.22 +
    8.23 +static bool is_file_uri(char* str) {
    8.24 +    return(strncmp(str, "file://", 7) == 0);
    8.25 +}
    8.26 +
    8.27 +static bool is_cid_uri(const char* str) {
    8.28 +    return(strncmp(str, "cid://", 6) == 0);
    8.29 +}
    8.30  
    8.31  static bool string_equality(const char *s1, const char *s2)
    8.32  {
    8.33 @@ -48,7 +71,7 @@
    8.34  {
    8.35      assert(fe);
    8.36  
    8.37 -    if (bl == NULL || bl->filename == NULL || fe == NULL)
    8.38 +    if (bl == NULL || bl->filename == NULL || fe == NULL || is_cid_uri(bl->filename))
    8.39          return false;
    8.40  
    8.41      assert(bl && bl->filename);
    8.42 @@ -427,7 +450,7 @@
    8.43      dst->attachments = _a;
    8.44  
    8.45      _a = bloblist_add(_a, ctext, csize, "application/octet-stream",
    8.46 -        "msg.asc");
    8.47 +        "file://msg.asc");
    8.48      if (_a == NULL)
    8.49          goto enomem;
    8.50  
    8.51 @@ -528,7 +551,7 @@
    8.52          if (ctext) {
    8.53  
    8.54              bloblist_t *_a = bloblist_add(dst->attachments, ctext, csize,
    8.55 -                "application/octet-stream", "PGPexch.htm.pgp");
    8.56 +                "application/octet-stream", "file://PGPexch.htm.pgp");
    8.57              if (_a == NULL)
    8.58                  goto enomem;
    8.59              if (dst->attachments == NULL)
    8.60 @@ -567,24 +590,34 @@
    8.61                  if (ctext) {
    8.62                      char *filename = NULL;
    8.63  
    8.64 -                    if (_s->filename) {
    8.65 +                    char *attach_fn = _s->filename;
    8.66 +                    if (attach_fn && !is_cid_uri(attach_fn)) {
    8.67                          size_t len = strlen(_s->filename);
    8.68                          size_t bufsize = len + 5; // length of .pgp extension + NUL
    8.69 +                        bool already_uri = false;
    8.70 +                        if (is_file_uri(attach_fn))
    8.71 +                            already_uri = true;
    8.72 +                        else
    8.73 +                            bufsize += 7; // length of file://
    8.74 +                            
    8.75                          filename = calloc(1, bufsize);
    8.76                          if (filename == NULL)
    8.77                              goto enomem;
    8.78  
    8.79 -                        strlcpy(filename, _s->filename, bufsize);
    8.80 +                        if (!already_uri)
    8.81 +                            strlcpy(filename, "file://", bufsize);
    8.82 +                        // First char is NUL, so we're ok, even if not copying above. (calloc)
    8.83 +                        strlcat(filename, _s->filename, bufsize);
    8.84                          strlcat(filename, ".pgp", bufsize);
    8.85                      }
    8.86                      else {
    8.87 -                        filename = calloc(1, 20);
    8.88 +                        filename = calloc(1, 27);
    8.89                          if (filename == NULL)
    8.90                              goto enomem;
    8.91  
    8.92                          ++n;
    8.93                          n &= 0xffff;
    8.94 -                        snprintf(filename, 20, "Attachment%d.pgp", n);
    8.95 +                        snprintf(filename, 20, "file://Attachment%d.pgp", n);
    8.96                      }
    8.97  
    8.98                      _d = bloblist_add(_d, ctext, csize, "application/octet-stream",
    8.99 @@ -736,7 +769,7 @@
   8.100  {
   8.101      assert(blob);
   8.102  
   8.103 -    if (blob == NULL || blob->filename == NULL)
   8.104 +    if (blob == NULL || blob->filename == NULL || is_cid_uri(blob->filename))
   8.105          return false;
   8.106  
   8.107      char *ext = strrchr(blob->filename, '.');
   8.108 @@ -760,12 +793,13 @@
   8.109  {
   8.110      assert(blob);
   8.111      assert(blob->filename);
   8.112 -    if (blob == NULL || blob->filename == NULL)
   8.113 +    if (blob == NULL || blob->filename == NULL || is_cid_uri(blob->filename))
   8.114          return false;
   8.115  
   8.116 -    if (strncmp(blob->filename, "PGPexch.htm.", 12) == 0) {
   8.117 -        if (strcmp(blob->filename + 11, ".pgp") == 0 ||
   8.118 -            strcmp(blob->filename + 11, ".asc") == 0)
   8.119 +    const char* bare_filename_ptr = _get_resource_ptr_noown(blob->filename);
   8.120 +    if (strncmp(bare_filename_ptr, "PGPexch.htm.", 12) == 0) {
   8.121 +        if (strcmp(bare_filename_ptr + 11, ".pgp") == 0 ||
   8.122 +            strcmp(bare_filename_ptr + 11, ".asc") == 0)
   8.123              return true;
   8.124      }
   8.125  
   8.126 @@ -775,7 +809,7 @@
   8.127  static char * without_double_ending(const char *filename)
   8.128  {
   8.129      assert(filename);
   8.130 -    if (filename == NULL)
   8.131 +    if (filename == NULL || is_cid_uri(filename))
   8.132          return NULL;
   8.133  
   8.134      char *ext = strrchr(filename, '.');
   8.135 @@ -1012,7 +1046,7 @@
   8.136      assert(size);
   8.137  
   8.138       bloblist_t *bl = bloblist_add(msg->attachments, keydata, size, "application/pgp-keys",
   8.139 -                      "pEpkey.asc");
   8.140 +                      "file://pEpkey.asc");
   8.141  
   8.142      if (msg->attachments == NULL && bl)
   8.143          msg->attachments = bl;
     9.1 --- a/src/mime.c	Fri Jun 30 16:33:08 2017 +0200
     9.2 +++ b/src/mime.c	Wed Jul 19 10:22:13 2017 +0200
     9.3 @@ -9,6 +9,7 @@
     9.4  #include <assert.h>
     9.5  #include <errno.h>
     9.6  
     9.7 +#include "resource_id.h"
     9.8  #include "etpan_mime.h"
     9.9  #include "wrappers.h"
    9.10  
    9.11 @@ -118,8 +119,13 @@
    9.12      if (mime == NULL)
    9.13          goto enomem;
    9.14  
    9.15 -    submime = get_text_part("msg.txt", "text/plain", plaintext, strlen(plaintext),
    9.16 +    pEp_rid_list_t* resource = new_rid_node(PEP_RID_FILENAME, "msg.txt");
    9.17 +    
    9.18 +    submime = get_text_part(resource, "text/plain", plaintext, strlen(plaintext),
    9.19              MAILMIME_MECHANISM_QUOTED_PRINTABLE);
    9.20 +    free_rid_list(resource);
    9.21 +    resource = NULL;
    9.22 +    
    9.23      assert(submime);
    9.24      if (submime == NULL)
    9.25          goto enomem;
    9.26 @@ -134,8 +140,12 @@
    9.27          submime = NULL;
    9.28      }
    9.29  
    9.30 -    submime = get_text_part("msg.html", "text/html", htmltext, strlen(htmltext),
    9.31 +    resource = new_rid_node(PEP_RID_FILENAME, "msg.html");
    9.32 +    submime = get_text_part(resource, "text/html", htmltext, strlen(htmltext),
    9.33              MAILMIME_MECHANISM_QUOTED_PRINTABLE);
    9.34 +    free_rid_list(resource);
    9.35 +    resource = NULL;
    9.36 +    
    9.37      assert(submime);
    9.38      if (submime == NULL)
    9.39          goto enomem;
    9.40 @@ -186,7 +196,10 @@
    9.41      else
    9.42          mime_type = blob->mime_type;
    9.43  
    9.44 -    mime = get_file_part(blob->filename, mime_type, blob->value, blob->size);
    9.45 +    pEp_rid_list_t* resource = parse_uri(blob->filename);
    9.46 +    mime = get_file_part(resource, mime_type, blob->value, blob->size);
    9.47 +    free_rid_list(resource);
    9.48 +    
    9.49      assert(mime);
    9.50      if (mime == NULL)
    9.51          goto enomem;
    9.52 @@ -559,6 +572,39 @@
    9.53      return status;
    9.54  }
    9.55  
    9.56 +static bool has_exceptional_extension(char* filename) {
    9.57 +    if (!filename)
    9.58 +        return false;
    9.59 +    int len = strlen(filename);
    9.60 +    if (len < 4)
    9.61 +        return false;
    9.62 +    char* ext_start = filename + (len - 4);
    9.63 +    if (strcmp(ext_start, ".pgp") == 0 || strcmp(ext_start, ".gpg") == 0 ||
    9.64 +        strcmp(ext_start, ".asc") == 0 || strcmp(ext_start, ".pEp") == 0)
    9.65 +        return true;
    9.66 +    return false;
    9.67 +}
    9.68 +
    9.69 +static pEp_rid_list_t* choose_resource_id(pEp_rid_list_t* rid_list) {
    9.70 +    pEp_rid_list_t* retval = rid_list;
    9.71 +    
    9.72 +    /* multiple elements - least common case */
    9.73 +    if (rid_list && rid_list->next) {
    9.74 +        pEp_rid_list_t* rid_list_curr = rid_list;
    9.75 +        retval = rid_list; 
    9.76 +        
    9.77 +        while (rid_list_curr) {
    9.78 +            pEp_resource_id_type rid_type = rid_list_curr->rid_type;
    9.79 +            if (rid_type == PEP_RID_CID)
    9.80 +                retval = rid_list_curr;
    9.81 +            else if (rid_type == PEP_RID_FILENAME && has_exceptional_extension(rid_list_curr->rid))
    9.82 +                return rid_list_curr;
    9.83 +            rid_list_curr = rid_list_curr->next;
    9.84 +        }
    9.85 +    } 
    9.86 +    return retval;
    9.87 +}
    9.88 +
    9.89  static PEP_STATUS mime_encode_message_plain(
    9.90          const message *msg,
    9.91          bool omit_fields,
    9.92 @@ -586,12 +632,19 @@
    9.93              goto pep_error;
    9.94      }
    9.95      else {
    9.96 -        if (is_PGP_message_text(plaintext))
    9.97 -            mime = get_text_part("msg.asc", "application/octet-stream", plaintext,
    9.98 +        pEp_rid_list_t* resource = NULL;
    9.99 +        if (is_PGP_message_text(plaintext)) {
   9.100 +            resource = new_rid_node(PEP_RID_FILENAME, "msg.asc");
   9.101 +            mime = get_text_part(resource, "application/octet-stream", plaintext,
   9.102                      strlen(plaintext), MAILMIME_MECHANISM_7BIT);
   9.103 -        else
   9.104 -            mime = get_text_part("msg.txt", "text/plain", plaintext, strlen(plaintext),
   9.105 +        }
   9.106 +        else {
   9.107 +            resource = new_rid_node(PEP_RID_FILENAME, "msg.txt");
   9.108 +            mime = get_text_part(resource, "text/plain", plaintext, strlen(plaintext),
   9.109                      MAILMIME_MECHANISM_QUOTED_PRINTABLE);
   9.110 +        }
   9.111 +        free_rid_list(resource);
   9.112 +        
   9.113          assert(mime);
   9.114          if (mime == NULL)
   9.115              goto enomem;
   9.116 @@ -694,8 +747,12 @@
   9.117          submime = NULL;
   9.118      }
   9.119  
   9.120 -    submime = get_text_part("msg.asc", "application/octet-stream", plaintext,
   9.121 +    pEp_rid_list_t* resource = new_rid_node(PEP_RID_FILENAME, "msg.asc");
   9.122 +    submime = get_text_part(resource, "application/octet-stream", plaintext,
   9.123              plaintext_size, MAILMIME_MECHANISM_7BIT);
   9.124 +            
   9.125 +    free_rid_list(resource);
   9.126 +    
   9.127      assert(submime);
   9.128      if (submime == NULL)
   9.129          goto enomem;
   9.130 @@ -1343,19 +1400,50 @@
   9.131                  if (status)
   9.132                      return status;
   9.133  
   9.134 -                filename = _get_filename(mime);
   9.135 +                pEp_rid_list_t* resource_id_list = _get_resource_id_list(mime);
   9.136 +                pEp_rid_list_t* chosen_resource_id = choose_resource_id(resource_id_list);
   9.137 +                
   9.138 +                //filename = _get_filename_or_cid(mime);
   9.139                  char *_filename = NULL;
   9.140 -                if (filename) {
   9.141 +                
   9.142 +                if (chosen_resource_id) {
   9.143 +                    filename = chosen_resource_id->rid;
   9.144                      size_t index = 0;
   9.145 +                    /* NOTA BENE */
   9.146 +                    /* The prefix we just added shouldn't be a problem - this is about decoding %XX (RFC 2392) */
   9.147 +                    /* If it becomes one, we have some MESSY fixing to do. :(                                  */
   9.148                      r = mailmime_encoded_phrase_parse("utf-8", filename,
   9.149                              strlen(filename), &index, "utf-8", &_filename);
   9.150 -                    if (r)
   9.151 +                    if (r) {
   9.152                          goto enomem;
   9.153 +                    }
   9.154 +                    char* file_prefix = NULL;
   9.155 +                    
   9.156 +                    /* in case there are others later */
   9.157 +                    switch (chosen_resource_id->rid_type) {
   9.158 +                        case PEP_RID_CID:
   9.159 +                            file_prefix = "cid";
   9.160 +                            break;
   9.161 +                        case PEP_RID_FILENAME:
   9.162 +                            file_prefix = "file";
   9.163 +                            break;
   9.164 +                        default:
   9.165 +                            break;
   9.166 +                    }
   9.167 +
   9.168 +                    
   9.169 +                    if (file_prefix) {
   9.170 +                        filename = build_uri(file_prefix, _filename);
   9.171 +                        free(_filename);
   9.172 +                        _filename = filename;
   9.173 +                    }
   9.174                  }
   9.175  
   9.176                  bloblist_t *_a = bloblist_add(msg->attachments, data, size,
   9.177                          mime_type, _filename);
   9.178                  free(_filename);
   9.179 +                free_rid_list(resource_id_list);
   9.180 +                resource_id_list = NULL;
   9.181                  if (_a == NULL)
   9.182                      return PEP_OUT_OF_MEMORY;
   9.183                  if (msg->attachments == NULL)
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/resource_id.c	Wed Jul 19 10:22:13 2017 +0200
    10.3 @@ -0,0 +1,70 @@
    10.4 +// This file is under GNU General Public License 3.0
    10.5 +// see LICENSE.txt
    10.6 +
    10.7 +#include "pEp_internal.h"
    10.8 +#include "resource_id.h"
    10.9 +
   10.10 +pEp_rid_list_t* new_rid_node(pEp_resource_id_type type, const char* resource) {
   10.11 +    pEp_rid_list_t* retval = (pEp_rid_list_t*)calloc(1, sizeof(pEp_rid_list_t));
   10.12 +    retval->rid_type = type;
   10.13 +    retval->rid = strdup(resource);
   10.14 +    return retval;
   10.15 +}
   10.16 +
   10.17 +void free_rid_list(pEp_rid_list_t* list) {
   10.18 +    while (list) {
   10.19 +        pEp_rid_list_t* nextptr = list->next;
   10.20 +        free(list->rid);
   10.21 +        free(list);
   10.22 +        list = nextptr;
   10.23 +    }
   10.24 +}
   10.25 +
   10.26 +const char* get_resource_ptr_noown(const char* uri) {
   10.27 +    char* uri_delim = strstr(uri, "://");
   10.28 +    if (!uri_delim)
   10.29 +        return uri;
   10.30 +    else
   10.31 +        return uri_delim + 3;
   10.32 +}
   10.33 +
   10.34 +char* get_resource(char* uri) {
   10.35 +    const char* resource_ptr = get_resource_ptr_noown(uri);
   10.36 +    char* resource_str = NULL;
   10.37 +    if (resource_ptr)
   10.38 +        resource_str = strdup(resource_ptr);
   10.39 +    return resource_str;
   10.40 +}
   10.41 +
   10.42 +bool is_file_uri(char* str) {
   10.43 +    return(!str ? false : strncmp(str, "file://", 7) == 0);
   10.44 +}
   10.45 +
   10.46 +bool is_cid_uri(const char* str) {
   10.47 +    return(!str ? false : strncmp(str, "cid://", 6) == 0);
   10.48 +}
   10.49 +
   10.50 +pEp_rid_list_t* parse_uri(const char* uri) {
   10.51 +    if (!uri)
   10.52 +        return NULL;
   10.53 +    pEp_resource_id_type type = (is_cid_uri(uri) ? PEP_RID_CID : PEP_RID_FILENAME);
   10.54 +    const char* resource = get_resource_ptr_noown(uri);
   10.55 +    return new_rid_node(type, resource);
   10.56 +}
   10.57 +
   10.58 +char* build_uri(const char* uri_prefix, const char* resource) {
   10.59 +    if (!uri_prefix || !resource)
   10.60 +        return NULL;
   10.61 +    const char* delim = "://";
   10.62 +    const int delim_len = 3;
   10.63 +    int prefix_len = strlen(uri_prefix);
   10.64 +    int resource_len = strlen(resource);
   10.65 +    int retval_len = prefix_len + delim_len + resource_len;
   10.66 +
   10.67 +    char* retval = calloc(1, retval_len + 1);
   10.68 +    strlcpy(retval, uri_prefix, retval_len + 1);
   10.69 +    strlcat(retval, delim, retval_len + 1);
   10.70 +    strlcat(retval, resource, retval_len + 1);
   10.71 +    
   10.72 +    return retval;
   10.73 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/resource_id.h	Wed Jul 19 10:22:13 2017 +0200
    11.3 @@ -0,0 +1,34 @@
    11.4 +// This file is under GNU General Public License 3.0
    11.5 +// see LICENSE.txt
    11.6 +
    11.7 +#pragma once
    11.8 +
    11.9 +/* structs to contain info about parsed resource ids (filenames, uids) */
   11.10 +typedef enum _resource_id_type {
   11.11 +    PEP_RID_FILENAME,
   11.12 +    PEP_RID_CID
   11.13 +} pEp_resource_id_type;
   11.14 +
   11.15 +typedef struct pEp_rid_list_t pEp_rid_list_t;
   11.16 +
   11.17 +struct pEp_rid_list_t {
   11.18 +    pEp_resource_id_type rid_type;
   11.19 +    char* rid;
   11.20 +    pEp_rid_list_t* next;    
   11.21 +};
   11.22 +
   11.23 +pEp_rid_list_t* new_rid_node(pEp_resource_id_type type, const char* resource);
   11.24 +
   11.25 +void free_rid_list(pEp_rid_list_t* list);
   11.26 +
   11.27 +pEp_rid_list_t* parse_uri(const char* uri);
   11.28 +
   11.29 +char* build_uri(const char* uri_prefix, const char* resource);
   11.30 +
   11.31 +const char* get_resource_ptr_noown(const char* uri);
   11.32 +
   11.33 +char* get_resource(char* uri);
   11.34 +
   11.35 +bool is_file_uri(char* str);
   11.36 +
   11.37 +bool is_cid_uri(const char* str);
    12.1 --- a/src/sqlite3.c	Fri Jun 30 16:33:08 2017 +0200
    12.2 +++ b/src/sqlite3.c	Wed Jul 19 10:22:13 2017 +0200
    12.3 @@ -1,6 +1,6 @@
    12.4  /******************************************************************************
    12.5  ** This file is an amalgamation of many separate C source files from SQLite
    12.6 -** version 3.13.0.  By combining all the individual C code files into this 
    12.7 +** version 3.19.3.  By combining all the individual C code files into this
    12.8  ** single large file, the entire code can be compiled as a single translation
    12.9  ** unit.  This allows many compilers to do optimizations that would not be
   12.10  ** possible if the files were compiled separately.  Performance improvements
   12.11 @@ -9,7 +9,7 @@
   12.12  **
   12.13  ** This file is all you need to compile SQLite.  To use SQLite in other
   12.14  ** programs, you need this file and the "sqlite3.h" header file that defines
   12.15 -** the programming interface to the SQLite library.  (If you do not have 
   12.16 +** the programming interface to the SQLite library.  (If you do not have
   12.17  ** the "sqlite3.h" header file at hand, you will find a copy embedded within
   12.18  ** the text of this file.  Search for "Begin file sqlite3.h" to find the start
   12.19  ** of the embedded sqlite3.h header file.) Additional code files may be needed
   12.20 @@ -37,8 +37,8 @@
   12.21  ** Internal interface definitions for SQLite.
   12.22  **
   12.23  */
   12.24 -#ifndef _SQLITEINT_H_
   12.25 -#define _SQLITEINT_H_
   12.26 +#ifndef SQLITEINT_H
   12.27 +#define SQLITEINT_H
   12.28  
   12.29  /* Special Comments:
   12.30  **
   12.31 @@ -68,6 +68,14 @@
   12.32  */
   12.33  
   12.34  /*
   12.35 +** Make sure the Tcl calling convention macro is defined.  This macro is
   12.36 +** only used by test code and Tcl integration code.
   12.37 +*/
   12.38 +#ifndef SQLITE_TCLAPI
   12.39 +#  define SQLITE_TCLAPI
   12.40 +#endif
   12.41 +
   12.42 +/*
   12.43  ** Make sure that rand_s() is available on Windows systems with MSVC 2005
   12.44  ** or higher.
   12.45  */
   12.46 @@ -97,8 +105,8 @@
   12.47  **
   12.48  ** This file contains code that is specific to MSVC.
   12.49  */
   12.50 -#ifndef _MSVC_H_
   12.51 -#define _MSVC_H_
   12.52 +#ifndef SQLITE_MSVC_H
   12.53 +#define SQLITE_MSVC_H
   12.54  
   12.55  #if defined(_MSC_VER)
   12.56  #pragma warning(disable : 4054)
   12.57 @@ -118,7 +126,7 @@
   12.58  #pragma warning(disable : 4706)
   12.59  #endif /* defined(_MSC_VER) */
   12.60  
   12.61 -#endif /* _MSVC_H_ */
   12.62 +#endif /* SQLITE_MSVC_H */
   12.63  
   12.64  /************** End of msvc.h ************************************************/
   12.65  /************** Continuing where we left off in sqliteInt.h ******************/
   12.66 @@ -196,12 +204,29 @@
   12.67  # define _LARGEFILE_SOURCE 1
   12.68  #endif
   12.69  
   12.70 -/* What version of GCC is being used.  0 means GCC is not being used */
   12.71 -#ifdef __GNUC__
   12.72 +/* The GCC_VERSION and MSVC_VERSION macros are used to
   12.73 +** conditionally include optimizations for each of these compilers.  A
   12.74 +** value of 0 means that compiler is not being used.  The
   12.75 +** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific
   12.76 +** optimizations, and hence set all compiler macros to 0
   12.77 +**
   12.78 +** There was once also a CLANG_VERSION macro.  However, we learn that the
   12.79 +** version numbers in clang are for "marketing" only and are inconsistent
   12.80 +** and unreliable.  Fortunately, all versions of clang also recognize the
   12.81 +** gcc version numbers and have reasonable settings for gcc version numbers,
   12.82 +** so the GCC_VERSION macro will be set to a correct non-zero value even
   12.83 +** when compiling with clang.
   12.84 +*/
   12.85 +#if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC)
   12.86  # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
   12.87  #else
   12.88  # define GCC_VERSION 0
   12.89  #endif
   12.90 +#if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC)
   12.91 +# define MSVC_VERSION _MSC_VER
   12.92 +#else
   12.93 +# define MSVC_VERSION 0
   12.94 +#endif
   12.95  
   12.96  /* Needed for various definitions... */
   12.97  #if defined(__GNUC__) && !defined(_GNU_SOURCE)
   12.98 @@ -282,8 +307,8 @@
   12.99  ** the version number) and changes its name to "sqlite3.h" as
  12.100  ** part of the build process.
  12.101  */
  12.102 -#ifndef _SQLITE3_H_
  12.103 -#define _SQLITE3_H_
  12.104 +#ifndef SQLITE3_H
  12.105 +#define SQLITE3_H
  12.106  #include <stdarg.h>     /* Needed for the definition of va_list */
  12.107  
  12.108  /*
  12.109 @@ -306,8 +331,17 @@
  12.110  #ifndef SQLITE_CDECL
  12.111  # define SQLITE_CDECL
  12.112  #endif
  12.113 +#ifndef SQLITE_APICALL
  12.114 +# define SQLITE_APICALL
  12.115 +#endif
  12.116  #ifndef SQLITE_STDCALL
  12.117 -# define SQLITE_STDCALL
  12.118 +# define SQLITE_STDCALL SQLITE_APICALL
  12.119 +#endif
  12.120 +#ifndef SQLITE_CALLBACK
  12.121 +# define SQLITE_CALLBACK
  12.122 +#endif
  12.123 +#ifndef SQLITE_SYSAPI
  12.124 +# define SQLITE_SYSAPI
  12.125  #endif
  12.126  
  12.127  /*
  12.128 @@ -351,25 +385,26 @@
  12.129  ** be held constant and Z will be incremented or else Y will be incremented
  12.130  ** and Z will be reset to zero.
  12.131  **
  12.132 -** Since version 3.6.18, SQLite source code has been stored in the
  12.133 +** Since [version 3.6.18] ([dateof:3.6.18]), 
  12.134 +** SQLite source code has been stored in the
  12.135  ** <a href="http://www.fossil-scm.org/">Fossil configuration management
  12.136  ** system</a>.  ^The SQLITE_SOURCE_ID macro evaluates to
  12.137  ** a string which identifies a particular check-in of SQLite
  12.138  ** within its configuration management system.  ^The SQLITE_SOURCE_ID
  12.139 -** string contains the date and time of the check-in (UTC) and an SHA1
  12.140 -** hash of the entire source tree.
  12.141 +** string contains the date and time of the check-in (UTC) and a SHA1
  12.142 +** or SHA3-256 hash of the entire source tree.
  12.143  **
  12.144  ** See also: [sqlite3_libversion()],
  12.145  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
  12.146  ** [sqlite_version()] and [sqlite_source_id()].
  12.147  */
  12.148 -#define SQLITE_VERSION        "3.13.0"
  12.149 -#define SQLITE_VERSION_NUMBER 3013000
  12.150 -#define SQLITE_SOURCE_ID      "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
  12.151 +#define SQLITE_VERSION        "3.19.3"
  12.152 +#define SQLITE_VERSION_NUMBER 3019003
  12.153 +#define SQLITE_SOURCE_ID      "2017-06-08 14:26:16 0ee482a1e0eae22e08edc8978c9733a96603d4509645f348ebf55b579e89636b"
  12.154  
  12.155  /*
  12.156  ** CAPI3REF: Run-Time Library Version Numbers
  12.157 -** KEYWORDS: sqlite3_version, sqlite3_sourceid
  12.158 +** KEYWORDS: sqlite3_version sqlite3_sourceid
  12.159  **
  12.160  ** These interfaces provide the same information as the [SQLITE_VERSION],
  12.161  ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
  12.162 @@ -398,9 +433,9 @@
  12.163  ** See also: [sqlite_version()] and [sqlite_source_id()].
  12.164  */
  12.165  SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
  12.166 -SQLITE_API const char *SQLITE_STDCALL sqlite3_libversion(void);
  12.167 -SQLITE_API const char *SQLITE_STDCALL sqlite3_sourceid(void);
  12.168 -SQLITE_API int SQLITE_STDCALL sqlite3_libversion_number(void);
  12.169 +SQLITE_API const char *sqlite3_libversion(void);
  12.170 +SQLITE_API const char *sqlite3_sourceid(void);
  12.171 +SQLITE_API int sqlite3_libversion_number(void);
  12.172  
  12.173  /*
  12.174  ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
  12.175 @@ -425,8 +460,8 @@
  12.176  ** [sqlite_compileoption_get()] and the [compile_options pragma].
  12.177  */
  12.178  #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
  12.179 -SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName);
  12.180 -SQLITE_API const char *SQLITE_STDCALL sqlite3_compileoption_get(int N);
  12.181 +SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
  12.182 +SQLITE_API const char *sqlite3_compileoption_get(int N);
  12.183  #endif
  12.184  
  12.185  /*
  12.186 @@ -465,7 +500,7 @@
  12.187  **
  12.188  ** See the [threading mode] documentation for additional information.
  12.189  */
  12.190 -SQLITE_API int SQLITE_STDCALL sqlite3_threadsafe(void);
  12.191 +SQLITE_API int sqlite3_threadsafe(void);
  12.192  
  12.193  /*
  12.194  ** CAPI3REF: Database Connection Handle
  12.195 @@ -501,7 +536,11 @@
  12.196  */
  12.197  #ifdef SQLITE_INT64_TYPE
  12.198    typedef SQLITE_INT64_TYPE sqlite_int64;
  12.199 -  typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  12.200 +# ifdef SQLITE_UINT64_TYPE
  12.201 +    typedef SQLITE_UINT64_TYPE sqlite_uint64;
  12.202 +# else  
  12.203 +    typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
  12.204 +# endif
  12.205  #elif defined(_MSC_VER) || defined(__BORLANDC__)
  12.206    typedef __int64 sqlite_int64;
  12.207    typedef unsigned __int64 sqlite_uint64;
  12.208 @@ -562,8 +601,8 @@
  12.209  ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
  12.210  ** argument is a harmless no-op.
  12.211  */
  12.212 -SQLITE_API int SQLITE_STDCALL sqlite3_close(sqlite3*);
  12.213 -SQLITE_API int SQLITE_STDCALL sqlite3_close_v2(sqlite3*);
  12.214 +SQLITE_API int sqlite3_close(sqlite3*);
  12.215 +SQLITE_API int sqlite3_close_v2(sqlite3*);
  12.216  
  12.217  /*
  12.218  ** The type for a callback function.
  12.219 @@ -634,7 +673,7 @@
  12.220  **      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
  12.221  ** </ul>
  12.222  */
  12.223 -SQLITE_API int SQLITE_STDCALL sqlite3_exec(
  12.224 +SQLITE_API int sqlite3_exec(
  12.225    sqlite3*,                                  /* An open database */
  12.226    const char *sql,                           /* SQL to be evaluated */
  12.227    int (*callback)(void*,int,char**,char**),  /* Callback function */
  12.228 @@ -695,7 +734,8 @@
  12.229  ** [result codes].  However, experience has shown that many of
  12.230  ** these result codes are too coarse-grained.  They do not provide as
  12.231  ** much information about problems as programmers might like.  In an effort to
  12.232 -** address this, newer versions of SQLite (version 3.3.8 and later) include
  12.233 +** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
  12.234 +** and later) include
  12.235  ** support for additional result codes that provide more detailed information
  12.236  ** about errors. These [extended result codes] are enabled or disabled
  12.237  ** on a per database connection basis using the
  12.238 @@ -758,6 +798,7 @@
  12.239  #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
  12.240  #define SQLITE_WARNING_AUTOINDEX       (SQLITE_WARNING | (1<<8))
  12.241  #define SQLITE_AUTH_USER               (SQLITE_AUTH | (1<<8))
  12.242 +#define SQLITE_OK_LOAD_PERMANENTLY     (SQLITE_OK | (1<<8))
  12.243  
  12.244  /*
  12.245  ** CAPI3REF: Flags For File Open Operations
  12.246 @@ -812,7 +853,7 @@
  12.247  ** file that were written at the application level might have changed
  12.248  ** and that adjacent bytes, even bytes within the same sector are
  12.249  ** guaranteed to be unchanged.  The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
  12.250 -** flag indicate that a file cannot be deleted when open.  The
  12.251 +** flag indicates that a file cannot be deleted when open.  The
  12.252  ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
  12.253  ** read-only media and cannot be changed even by processes with
  12.254  ** elevated privileges.
  12.255 @@ -962,6 +1003,9 @@
  12.256  ** <li> [SQLITE_IOCAP_ATOMIC64K]
  12.257  ** <li> [SQLITE_IOCAP_SAFE_APPEND]
  12.258  ** <li> [SQLITE_IOCAP_SEQUENTIAL]
  12.259 +** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
  12.260 +** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
  12.261 +** <li> [SQLITE_IOCAP_IMMUTABLE]
  12.262  ** </ul>
  12.263  **
  12.264  ** The SQLITE_IOCAP_ATOMIC property means that all writes of
  12.265 @@ -1090,7 +1134,7 @@
  12.266  ** opcode allows these two values (10 retries and 25 milliseconds of delay)
  12.267  ** to be adjusted.  The values are changed for all database connections
  12.268  ** within the same process.  The argument is a pointer to an array of two
  12.269 -** integers where the first integer i the new retry count and the second
  12.270 +** integers where the first integer is the new retry count and the second
  12.271  ** integer is the delay.  If either integer is negative, then the setting
  12.272  ** is not changed but instead the prior value of that setting is written
  12.273  ** into the array entry, allowing the current retry settings to be
  12.274 @@ -1218,6 +1262,12 @@
  12.275  ** on whether or not the file has been renamed, moved, or deleted since it
  12.276  ** was first opened.
  12.277  **
  12.278 +** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
  12.279 +** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
  12.280 +** underlying native file handle associated with a file handle.  This file
  12.281 +** control interprets its argument as a pointer to a native file handle and
  12.282 +** writes the resulting value there.
  12.283 +**
  12.284  ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
  12.285  ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging.  This
  12.286  ** opcode causes the xFileControl method to swap the file handle with the one
  12.287 @@ -1268,6 +1318,8 @@
  12.288  #define SQLITE_FCNTL_RBU                    26
  12.289  #define SQLITE_FCNTL_VFS_POINTER            27
  12.290  #define SQLITE_FCNTL_JOURNAL_POINTER        28
  12.291 +#define SQLITE_FCNTL_WIN32_GET_HANDLE       29
  12.292 +#define SQLITE_FCNTL_PDB                    30
  12.293  
  12.294  /* deprecated names */
  12.295  #define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE
  12.296 @@ -1288,6 +1340,16 @@
  12.297  typedef struct sqlite3_mutex sqlite3_mutex;
  12.298  
  12.299  /*
  12.300 +** CAPI3REF: Loadable Extension Thunk
  12.301 +**
  12.302 +** A pointer to the opaque sqlite3_api_routines structure is passed as
  12.303 +** the third parameter to entry points of [loadable extensions].  This
  12.304 +** structure must be typedefed in order to work around compiler warnings
  12.305 +** on some platforms.
  12.306 +*/
  12.307 +typedef struct sqlite3_api_routines sqlite3_api_routines;
  12.308 +
  12.309 +/*
  12.310  ** CAPI3REF: OS Interface Object
  12.311  **
  12.312  ** An instance of the sqlite3_vfs object defines the interface between
  12.313 @@ -1622,10 +1684,10 @@
  12.314  ** must return [SQLITE_OK] on success and some other [error code] upon
  12.315  ** failure.
  12.316  */
  12.317 -SQLITE_API int SQLITE_STDCALL sqlite3_initialize(void);
  12.318 -SQLITE_API int SQLITE_STDCALL sqlite3_shutdown(void);
  12.319 -SQLITE_API int SQLITE_STDCALL sqlite3_os_init(void);
  12.320 -SQLITE_API int SQLITE_STDCALL sqlite3_os_end(void);
  12.321 +SQLITE_API int sqlite3_initialize(void);
  12.322 +SQLITE_API int sqlite3_shutdown(void);
  12.323 +SQLITE_API int sqlite3_os_init(void);
  12.324 +SQLITE_API int sqlite3_os_end(void);
  12.325  
  12.326  /*
  12.327  ** CAPI3REF: Configuring The SQLite Library
  12.328 @@ -1658,7 +1720,7 @@
  12.329  ** ^If the option is unknown or SQLite is unable to set the option
  12.330  ** then this routine returns a non-zero [error code].
  12.331  */
  12.332 -SQLITE_API int SQLITE_CDECL sqlite3_config(int, ...);
  12.333 +SQLITE_API int sqlite3_config(int, ...);
  12.334  
  12.335  /*
  12.336  ** CAPI3REF: Configure database connections
  12.337 @@ -1677,7 +1739,7 @@
  12.338  ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
  12.339  ** the call is considered successful.
  12.340  */
  12.341 -SQLITE_API int SQLITE_CDECL sqlite3_db_config(sqlite3*, int op, ...);
  12.342 +SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
  12.343  
  12.344  /*
  12.345  ** CAPI3REF: Memory Allocation Routines
  12.346 @@ -2191,7 +2253,7 @@
  12.347  ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
  12.348  ** There should be two additional arguments.
  12.349  ** When the first argument to this interface is 1, then only the C-API is
  12.350 -** enabled and the SQL function remains disabled.  If the first argment to
  12.351 +** enabled and the SQL function remains disabled.  If the first argument to
  12.352  ** this interface is 0, then both the C-API and the SQL function are disabled.
  12.353  ** If the first argument is -1, then no changes are made to state of either the
  12.354  ** C-API or the SQL function.
  12.355 @@ -2201,13 +2263,36 @@
  12.356  ** be a NULL pointer, in which case the new setting is not reported back.
  12.357  ** </dd>
  12.358  **
  12.359 +** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
  12.360 +** <dd> ^This option is used to change the name of the "main" database
  12.361 +** schema.  ^The sole argument is a pointer to a constant UTF8 string
  12.362 +** which will become the new schema name in place of "main".  ^SQLite
  12.363 +** does not make a copy of the new main schema name string, so the application
  12.364 +** must ensure that the argument passed into this DBCONFIG option is unchanged
  12.365 +** until after the database connection closes.
  12.366 +** </dd>
  12.367 +**
  12.368 +** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
  12.369 +** <dd> Usually, when a database in wal mode is closed or detached from a 
  12.370 +** database handle, SQLite checks if this will mean that there are now no 
  12.371 +** connections at all to the database. If so, it performs a checkpoint 
  12.372 +** operation before closing the connection. This option may be used to
  12.373 +** override this behaviour. The first parameter passed to this operation
  12.374 +** is an integer - non-zero to disable checkpoints-on-close, or zero (the
  12.375 +** default) to enable them. The second parameter is a pointer to an integer
  12.376 +** into which is written 0 or 1 to indicate whether checkpoints-on-close
  12.377 +** have been disabled - 0 if they are not disabled, 1 if they are.
  12.378 +** </dd>
  12.379 +**
  12.380  ** </dl>
  12.381  */
  12.382 +#define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
  12.383  #define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
  12.384  #define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
  12.385  #define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
  12.386  #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
  12.387  #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
  12.388 +#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */
  12.389  
  12.390  
  12.391  /*
  12.392 @@ -2218,7 +2303,7 @@
  12.393  ** [extended result codes] feature of SQLite. ^The extended result
  12.394  ** codes are disabled by default for historical compatibility.
  12.395  */
  12.396 -SQLITE_API int SQLITE_STDCALL sqlite3_extended_result_codes(sqlite3*, int onoff);
  12.397 +SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
  12.398  
  12.399  /*
  12.400  ** CAPI3REF: Last Insert Rowid
  12.401 @@ -2232,20 +2317,30 @@
  12.402  ** the table has a column of type [INTEGER PRIMARY KEY] then that column
  12.403  ** is another alias for the rowid.
  12.404  **
  12.405 -** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the 
  12.406 -** most recent successful [INSERT] into a rowid table or [virtual table]
  12.407 -** on database connection D.
  12.408 -** ^Inserts into [WITHOUT ROWID] tables are not recorded.
  12.409 -** ^If no successful [INSERT]s into rowid tables
  12.410 -** have ever occurred on the database connection D, 
  12.411 -** then sqlite3_last_insert_rowid(D) returns zero.
  12.412 -**
  12.413 -** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
  12.414 -** method, then this routine will return the [rowid] of the inserted
  12.415 -** row as long as the trigger or virtual table method is running.
  12.416 -** But once the trigger or virtual table method ends, the value returned 
  12.417 -** by this routine reverts to what it was before the trigger or virtual
  12.418 -** table method began.)^
  12.419 +** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
  12.420 +** the most recent successful [INSERT] into a rowid table or [virtual table]
  12.421 +** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
  12.422 +** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred 
  12.423 +** on the database connection D, then sqlite3_last_insert_rowid(D) returns 
  12.424 +** zero.
  12.425 +**
  12.426 +** As well as being set automatically as rows are inserted into database
  12.427 +** tables, the value returned by this function may be set explicitly by
  12.428 +** [sqlite3_set_last_insert_rowid()]
  12.429 +**
  12.430 +** Some virtual table implementations may INSERT rows into rowid tables as
  12.431 +** part of committing a transaction (e.g. to flush data accumulated in memory
  12.432 +** to disk). In this case subsequent calls to this function return the rowid
  12.433 +** associated with these internal INSERT operations, which leads to 
  12.434 +** unintuitive results. Virtual table implementations that do write to rowid
  12.435 +** tables in this way can avoid this problem by restoring the original 
  12.436 +** rowid value using [sqlite3_set_last_insert_rowid()] before returning 
  12.437 +** control to the user.
  12.438 +**
  12.439 +** ^(If an [INSERT] occurs within a trigger then this routine will 
  12.440 +** return the [rowid] of the inserted row as long as the trigger is 
  12.441 +** running. Once the trigger program ends, the value returned 
  12.442 +** by this routine reverts to what it was before the trigger was fired.)^
  12.443  **
  12.444  ** ^An [INSERT] that fails due to a constraint violation is not a
  12.445  ** successful [INSERT] and does not change the value returned by this
  12.446 @@ -2270,7 +2365,17 @@
  12.447  ** unpredictable and might not equal either the old or the new
  12.448  ** last insert [rowid].
  12.449  */
  12.450 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_last_insert_rowid(sqlite3*);
  12.451 +SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
  12.452 +
  12.453 +/*
  12.454 +** CAPI3REF: Set the Last Insert Rowid value.
  12.455 +** METHOD: sqlite3
  12.456 +**
  12.457 +** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
  12.458 +** set the value returned by calling sqlite3_last_insert_rowid(D) to R 
  12.459 +** without inserting a row into the database.
  12.460 +*/
  12.461 +SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
  12.462  
  12.463  /*
  12.464  ** CAPI3REF: Count The Number Of Rows Modified
  12.465 @@ -2323,7 +2428,7 @@
  12.466  ** while [sqlite3_changes()] is running then the value returned
  12.467  ** is unpredictable and not meaningful.
  12.468  */
  12.469 -SQLITE_API int SQLITE_STDCALL sqlite3_changes(sqlite3*);
  12.470 +SQLITE_API int sqlite3_changes(sqlite3*);
  12.471  
  12.472  /*
  12.473  ** CAPI3REF: Total Number Of Rows Modified
  12.474 @@ -2347,7 +2452,7 @@
  12.475  ** while [sqlite3_total_changes()] is running then the value
  12.476  ** returned is unpredictable and not meaningful.
  12.477  */
  12.478 -SQLITE_API int SQLITE_STDCALL sqlite3_total_changes(sqlite3*);
  12.479 +SQLITE_API int sqlite3_total_changes(sqlite3*);
  12.480  
  12.481  /*
  12.482  ** CAPI3REF: Interrupt A Long-Running Query
  12.483 @@ -2383,11 +2488,8 @@
  12.484  ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
  12.485  ** SQL statements is a no-op and has no effect on SQL statements
  12.486  ** that are started after the sqlite3_interrupt() call returns.
  12.487 -**
  12.488 -** If the database connection closes while [sqlite3_interrupt()]
  12.489 -** is running then bad things will likely happen.
  12.490 -*/
  12.491 -SQLITE_API void SQLITE_STDCALL sqlite3_interrupt(sqlite3*);
  12.492 +*/
  12.493 +SQLITE_API void sqlite3_interrupt(sqlite3*);
  12.494  
  12.495  /*
  12.496  ** CAPI3REF: Determine If An SQL Statement Is Complete
  12.497 @@ -2422,8 +2524,8 @@
  12.498  ** The input to [sqlite3_complete16()] must be a zero-terminated
  12.499  ** UTF-16 string in native byte order.
  12.500  */
  12.501 -SQLITE_API int SQLITE_STDCALL sqlite3_complete(const char *sql);
  12.502 -SQLITE_API int SQLITE_STDCALL sqlite3_complete16(const void *sql);
  12.503 +SQLITE_API int sqlite3_complete(const char *sql);
  12.504 +SQLITE_API int sqlite3_complete16(const void *sql);
  12.505  
  12.506  /*
  12.507  ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
  12.508 @@ -2484,7 +2586,7 @@
  12.509  ** A busy handler must not close the database connection
  12.510  ** or [prepared statement] that invoked the busy handler.
  12.511  */
  12.512 -SQLITE_API int SQLITE_STDCALL sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
  12.513 +SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);
  12.514  
  12.515  /*
  12.516  ** CAPI3REF: Set A Busy Timeout
  12.517 @@ -2507,7 +2609,7 @@
  12.518  **
  12.519  ** See also:  [PRAGMA busy_timeout]
  12.520  */
  12.521 -SQLITE_API int SQLITE_STDCALL sqlite3_busy_timeout(sqlite3*, int ms);
  12.522 +SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
  12.523  
  12.524  /*
  12.525  ** CAPI3REF: Convenience Routines For Running Queries
  12.526 @@ -2582,7 +2684,7 @@
  12.527  ** reflected in subsequent calls to [sqlite3_errcode()] or
  12.528  ** [sqlite3_errmsg()].
  12.529  */
  12.530 -SQLITE_API int SQLITE_STDCALL sqlite3_get_table(
  12.531 +SQLITE_API int sqlite3_get_table(
  12.532    sqlite3 *db,          /* An open database */
  12.533    const char *zSql,     /* SQL to be evaluated */
  12.534    char ***pazResult,    /* Results of the query */
  12.535 @@ -2590,7 +2692,7 @@
  12.536    int *pnColumn,        /* Number of result columns written here */
  12.537    char **pzErrmsg       /* Error msg written here */
  12.538  );
  12.539 -SQLITE_API void SQLITE_STDCALL sqlite3_free_table(char **result);
  12.540 +SQLITE_API void sqlite3_free_table(char **result);
  12.541  
  12.542  /*
  12.543  ** CAPI3REF: Formatted String Printing Functions
  12.544 @@ -2696,10 +2798,10 @@
  12.545  ** addition that after the string has been read and copied into
  12.546  ** the result, [sqlite3_free()] is called on the input string.)^
  12.547  */
  12.548 -SQLITE_API char *SQLITE_CDECL sqlite3_mprintf(const char*,...);
  12.549 -SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char*, va_list);
  12.550 -SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int,char*,const char*, ...);
  12.551 -SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int,char*,const char*, va_list);
  12.552 +SQLITE_API char *sqlite3_mprintf(const char*,...);
  12.553 +SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
  12.554 +SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
  12.555 +SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
  12.556  
  12.557  /*
  12.558  ** CAPI3REF: Memory Allocation Subsystem
  12.559 @@ -2789,12 +2891,12 @@
  12.560  ** a block of memory after it has been released using
  12.561  ** [sqlite3_free()] or [sqlite3_realloc()].
  12.562  */
  12.563 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc(int);
  12.564 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64);
  12.565 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void*, int);
  12.566 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void*, sqlite3_uint64);
  12.567 -SQLITE_API void SQLITE_STDCALL sqlite3_free(void*);
  12.568 -SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void*);
  12.569 +SQLITE_API void *sqlite3_malloc(int);
  12.570 +SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
  12.571 +SQLITE_API void *sqlite3_realloc(void*, int);
  12.572 +SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
  12.573 +SQLITE_API void sqlite3_free(void*);
  12.574 +SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
  12.575  
  12.576  /*
  12.577  ** CAPI3REF: Memory Allocator Statistics
  12.578 @@ -2819,8 +2921,8 @@
  12.579  ** by [sqlite3_memory_highwater(1)] is the high-water mark
  12.580  ** prior to the reset.
  12.581  */
  12.582 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void);
  12.583 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag);
  12.584 +SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
  12.585 +SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
  12.586  
  12.587  /*
  12.588  ** CAPI3REF: Pseudo-Random Number Generator
  12.589 @@ -2843,11 +2945,12 @@
  12.590  ** internally and without recourse to the [sqlite3_vfs] xRandomness
  12.591  ** method.
  12.592  */
  12.593 -SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *P);
  12.594 +SQLITE_API void sqlite3_randomness(int N, void *P);
  12.595  
  12.596  /*
  12.597  ** CAPI3REF: Compile-Time Authorization Callbacks
  12.598  ** METHOD: sqlite3
  12.599 +** KEYWORDS: {authorizer callback}
  12.600  **
  12.601  ** ^This routine registers an authorizer callback with a particular
  12.602  ** [database connection], supplied in the first argument.
  12.603 @@ -2875,8 +2978,10 @@
  12.604  ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
  12.605  ** to the callback is an integer [SQLITE_COPY | action code] that specifies
  12.606  ** the particular action to be authorized. ^The third through sixth parameters
  12.607 -** to the callback are zero-terminated strings that contain additional
  12.608 -** details about the action to be authorized.
  12.609 +** to the callback are either NULL pointers or zero-terminated strings
  12.610 +** that contain additional details about the action to be authorized.
  12.611 +** Applications must always be prepared to encounter a NULL pointer in any
  12.612 +** of the third through the sixth parameters of the authorization callback.
  12.613  **
  12.614  ** ^If the action code is [SQLITE_READ]
  12.615  ** and the callback returns [SQLITE_IGNORE] then the
  12.616 @@ -2885,6 +2990,10 @@
  12.617  ** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
  12.618  ** return can be used to deny an untrusted user access to individual
  12.619  ** columns of a table.
  12.620 +** ^When a table is referenced by a [SELECT] but no column values are
  12.621 +** extracted from that table (for example in a query like
  12.622 +** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
  12.623 +** is invoked once for that table with a column name that is an empty string.
  12.624  ** ^If the action code is [SQLITE_DELETE] and the callback returns
  12.625  ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
  12.626  ** [truncate optimization] is disabled and all rows are deleted individually.
  12.627 @@ -2926,7 +3035,7 @@
  12.628  ** as stated in the previous paragraph, sqlite3_step() invokes
  12.629  ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
  12.630  */
  12.631 -SQLITE_API int SQLITE_STDCALL sqlite3_set_authorizer(
  12.632 +SQLITE_API int sqlite3_set_authorizer(
  12.633    sqlite3*,
  12.634    int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
  12.635    void *pUserData
  12.636 @@ -3006,6 +3115,9 @@
  12.637  ** CAPI3REF: Tracing And Profiling Functions
  12.638  ** METHOD: sqlite3
  12.639  **
  12.640 +** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
  12.641 +** instead of the routines described here.
  12.642 +**
  12.643  ** These routines register callback functions that can be used for
  12.644  ** tracing and profiling the execution of SQL statements.
  12.645  **
  12.646 @@ -3031,11 +3143,105 @@
  12.647  ** sqlite3_profile() function is considered experimental and is
  12.648  ** subject to change in future versions of SQLite.
  12.649  */
  12.650 -SQLITE_API void *SQLITE_STDCALL sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
  12.651 -SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_profile(sqlite3*,
  12.652 +SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
  12.653 +   void(*xTrace)(void*,const char*), void*);
  12.654 +SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
  12.655     void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
  12.656  
  12.657  /*
  12.658 +** CAPI3REF: SQL Trace Event Codes
  12.659 +** KEYWORDS: SQLITE_TRACE
  12.660 +**
  12.661 +** These constants identify classes of events that can be monitored
  12.662 +** using the [sqlite3_trace_v2()] tracing logic.  The third argument
  12.663 +** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of
  12.664 +** the following constants.  ^The first argument to the trace callback
  12.665 +** is one of the following constants.
  12.666 +**
  12.667 +** New tracing constants may be added in future releases.
  12.668 +**
  12.669 +** ^A trace callback has four arguments: xCallback(T,C,P,X).
  12.670 +** ^The T argument is one of the integer type codes above.
  12.671 +** ^The C argument is a copy of the context pointer passed in as the
  12.672 +** fourth argument to [sqlite3_trace_v2()].
  12.673 +** The P and X arguments are pointers whose meanings depend on T.
  12.674 +**
  12.675 +** <dl>
  12.676 +** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
  12.677 +** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
  12.678 +** first begins running and possibly at other times during the
  12.679 +** execution of the prepared statement, such as at the start of each
  12.680 +** trigger subprogram. ^The P argument is a pointer to the
  12.681 +** [prepared statement]. ^The X argument is a pointer to a string which
  12.682 +** is the unexpanded SQL text of the prepared statement or an SQL comment 
  12.683 +** that indicates the invocation of a trigger.  ^The callback can compute
  12.684 +** the same text that would have been returned by the legacy [sqlite3_trace()]
  12.685 +** interface by using the X argument when X begins with "--" and invoking
  12.686 +** [sqlite3_expanded_sql(P)] otherwise.
  12.687 +**
  12.688 +** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
  12.689 +** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
  12.690 +** information as is provided by the [sqlite3_profile()] callback.
  12.691 +** ^The P argument is a pointer to the [prepared statement] and the
  12.692 +** X argument points to a 64-bit integer which is the estimated of
  12.693 +** the number of nanosecond that the prepared statement took to run.
  12.694 +** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
  12.695 +**
  12.696 +** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
  12.697 +** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
  12.698 +** statement generates a single row of result.  
  12.699 +** ^The P argument is a pointer to the [prepared statement] and the
  12.700 +** X argument is unused.
  12.701 +**
  12.702 +** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
  12.703 +** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
  12.704 +** connection closes.
  12.705 +** ^The P argument is a pointer to the [database connection] object
  12.706 +** and the X argument is unused.
  12.707 +** </dl>
  12.708 +*/
  12.709 +#define SQLITE_TRACE_STMT       0x01
  12.710 +#define SQLITE_TRACE_PROFILE    0x02
  12.711 +#define SQLITE_TRACE_ROW        0x04
  12.712 +#define SQLITE_TRACE_CLOSE      0x08
  12.713 +
  12.714 +/*
  12.715 +** CAPI3REF: SQL Trace Hook
  12.716 +** METHOD: sqlite3
  12.717 +**
  12.718 +** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
  12.719 +** function X against [database connection] D, using property mask M
  12.720 +** and context pointer P.  ^If the X callback is
  12.721 +** NULL or if the M mask is zero, then tracing is disabled.  The
  12.722 +** M argument should be the bitwise OR-ed combination of
  12.723 +** zero or more [SQLITE_TRACE] constants.
  12.724 +**
  12.725 +** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides 
  12.726 +** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
  12.727 +**
  12.728 +** ^The X callback is invoked whenever any of the events identified by 
  12.729 +** mask M occur.  ^The integer return value from the callback is currently
  12.730 +** ignored, though this may change in future releases.  Callback
  12.731 +** implementations should return zero to ensure future compatibility.
  12.732 +**
  12.733 +** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
  12.734 +** ^The T argument is one of the [SQLITE_TRACE]
  12.735 +** constants to indicate why the callback was invoked.
  12.736 +** ^The C argument is a copy of the context pointer.
  12.737 +** The P and X arguments are pointers whose meanings depend on T.
  12.738 +**
  12.739 +** The sqlite3_trace_v2() interface is intended to replace the legacy
  12.740 +** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
  12.741 +** are deprecated.
  12.742 +*/
  12.743 +SQLITE_API int sqlite3_trace_v2(
  12.744 +  sqlite3*,
  12.745 +  unsigned uMask,
  12.746 +  int(*xCallback)(unsigned,void*,void*,void*),
  12.747 +  void *pCtx
  12.748 +);
  12.749 +
  12.750 +/*
  12.751  ** CAPI3REF: Query Progress Callbacks
  12.752  ** METHOD: sqlite3
  12.753  **
  12.754 @@ -3067,7 +3273,7 @@
  12.755  ** database connections for the meaning of "modify" in this paragraph.
  12.756  **
  12.757  */
  12.758 -SQLITE_API void SQLITE_STDCALL sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  12.759 +SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
  12.760  
  12.761  /*
  12.762  ** CAPI3REF: Opening A New Database Connection
  12.763 @@ -3296,15 +3502,15 @@
  12.764  **
  12.765  ** See also: [sqlite3_temp_directory]
  12.766  */
  12.767 -SQLITE_API int SQLITE_STDCALL sqlite3_open(
  12.768 +SQLITE_API int sqlite3_open(
  12.769    const char *filename,   /* Database filename (UTF-8) */
  12.770    sqlite3 **ppDb          /* OUT: SQLite db handle */
  12.771  );
  12.772 -SQLITE_API int SQLITE_STDCALL sqlite3_open16(
  12.773 +SQLITE_API int sqlite3_open16(
  12.774    const void *filename,   /* Database filename (UTF-16) */
  12.775    sqlite3 **ppDb          /* OUT: SQLite db handle */
  12.776  );
  12.777 -SQLITE_API int SQLITE_STDCALL sqlite3_open_v2(
  12.778 +SQLITE_API int sqlite3_open_v2(
  12.779    const char *filename,   /* Database filename (UTF-8) */
  12.780    sqlite3 **ppDb,         /* OUT: SQLite db handle */
  12.781    int flags,              /* Flags */
  12.782 @@ -3350,9 +3556,9 @@
  12.783  ** VFS method, then the behavior of this routine is undefined and probably
  12.784  ** undesirable.
  12.785  */
  12.786 -SQLITE_API const char *SQLITE_STDCALL sqlite3_uri_parameter(const char *zFilename, const char *zParam);
  12.787 -SQLITE_API int SQLITE_STDCALL sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
  12.788 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
  12.789 +SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
  12.790 +SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
  12.791 +SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
  12.792  
  12.793  
  12.794  /*
  12.795 @@ -3396,11 +3602,11 @@
  12.796  ** was invoked incorrectly by the application.  In that case, the
  12.797  ** error code and message may or may not be set.
  12.798  */
  12.799 -SQLITE_API int SQLITE_STDCALL sqlite3_errcode(sqlite3 *db);
  12.800 -SQLITE_API int SQLITE_STDCALL sqlite3_extended_errcode(sqlite3 *db);
  12.801 -SQLITE_API const char *SQLITE_STDCALL sqlite3_errmsg(sqlite3*);
  12.802 -SQLITE_API const void *SQLITE_STDCALL sqlite3_errmsg16(sqlite3*);
  12.803 -SQLITE_API const char *SQLITE_STDCALL sqlite3_errstr(int);
  12.804 +SQLITE_API int sqlite3_errcode(sqlite3 *db);
  12.805 +SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
  12.806 +SQLITE_API const char *sqlite3_errmsg(sqlite3*);
  12.807 +SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
  12.808 +SQLITE_API const char *sqlite3_errstr(int);
  12.809  
  12.810  /*
  12.811  ** CAPI3REF: Prepared Statement Object
  12.812 @@ -3468,7 +3674,7 @@
  12.813  **
  12.814  ** New run-time limit categories may be added in future releases.
  12.815  */
  12.816 -SQLITE_API int SQLITE_STDCALL sqlite3_limit(sqlite3*, int id, int newVal);
  12.817 +SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
  12.818  
  12.819  /*
  12.820  ** CAPI3REF: Run-Time Limit Categories
  12.821 @@ -3499,9 +3705,9 @@
  12.822  **
  12.823  ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
  12.824  ** <dd>The maximum number of instructions in a virtual machine program
  12.825 -** used to implement an SQL statement.  This limit is not currently
  12.826 -** enforced, though that might be added in some future release of
  12.827 -** SQLite.</dd>)^
  12.828 +** used to implement an SQL statement.  If [sqlite3_prepare_v2()] or
  12.829 +** the equivalent tries to allocate space for more than this many opcodes
  12.830 +** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
  12.831  **
  12.832  ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
  12.833  ** <dd>The maximum number of arguments on a function.</dd>)^
  12.834 @@ -3539,6 +3745,7 @@
  12.835  #define SQLITE_LIMIT_TRIGGER_DEPTH            10
  12.836  #define SQLITE_LIMIT_WORKER_THREADS           11
  12.837  
  12.838 +
  12.839  /*
  12.840  ** CAPI3REF: Compiling An SQL Statement
  12.841  ** KEYWORDS: {SQL statement compiler}
  12.842 @@ -3620,28 +3827,28 @@
  12.843  ** </li>
  12.844  ** </ol>
  12.845  */
  12.846 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare(
  12.847 +SQLITE_API int sqlite3_prepare(
  12.848    sqlite3 *db,            /* Database handle */
  12.849    const char *zSql,       /* SQL statement, UTF-8 encoded */
  12.850    int nByte,              /* Maximum length of zSql in bytes. */
  12.851    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  12.852    const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  12.853  );
  12.854 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare_v2(
  12.855 +SQLITE_API int sqlite3_prepare_v2(
  12.856    sqlite3 *db,            /* Database handle */
  12.857    const char *zSql,       /* SQL statement, UTF-8 encoded */
  12.858    int nByte,              /* Maximum length of zSql in bytes. */
  12.859    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  12.860    const char **pzTail     /* OUT: Pointer to unused portion of zSql */
  12.861  );
  12.862 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare16(
  12.863 +SQLITE_API int sqlite3_prepare16(
  12.864    sqlite3 *db,            /* Database handle */
  12.865    const void *zSql,       /* SQL statement, UTF-16 encoded */
  12.866    int nByte,              /* Maximum length of zSql in bytes. */
  12.867    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  12.868    const void **pzTail     /* OUT: Pointer to unused portion of zSql */
  12.869  );
  12.870 -SQLITE_API int SQLITE_STDCALL sqlite3_prepare16_v2(
  12.871 +SQLITE_API int sqlite3_prepare16_v2(
  12.872    sqlite3 *db,            /* Database handle */
  12.873    const void *zSql,       /* SQL statement, UTF-16 encoded */
  12.874    int nByte,              /* Maximum length of zSql in bytes. */
  12.875 @@ -3653,11 +3860,35 @@
  12.876  ** CAPI3REF: Retrieving Statement SQL
  12.877  ** METHOD: sqlite3_stmt
  12.878  **
  12.879 -** ^This interface can be used to retrieve a saved copy of the original
  12.880 -** SQL text used to create a [prepared statement] if that statement was
  12.881 -** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  12.882 -*/
  12.883 -SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt);
  12.884 +** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
  12.885 +** SQL text used to create [prepared statement] P if P was
  12.886 +** created by either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
  12.887 +** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
  12.888 +** string containing the SQL text of prepared statement P with
  12.889 +** [bound parameters] expanded.
  12.890 +**
  12.891 +** ^(For example, if a prepared statement is created using the SQL
  12.892 +** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
  12.893 +** and parameter :xyz is unbound, then sqlite3_sql() will return
  12.894 +** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
  12.895 +** will return "SELECT 2345,NULL".)^
  12.896 +**
  12.897 +** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
  12.898 +** is available to hold the result, or if the result would exceed the
  12.899 +** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
  12.900 +**
  12.901 +** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
  12.902 +** bound parameter expansions.  ^The [SQLITE_OMIT_TRACE] compile-time
  12.903 +** option causes sqlite3_expanded_sql() to always return NULL.
  12.904 +**
  12.905 +** ^The string returned by sqlite3_sql(P) is managed by SQLite and is
  12.906 +** automatically freed when the prepared statement is finalized.
  12.907 +** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
  12.908 +** is obtained from [sqlite3_malloc()] and must be free by the application
  12.909 +** by passing it to [sqlite3_free()].
  12.910 +*/
  12.911 +SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
  12.912 +SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
  12.913  
  12.914  /*
  12.915  ** CAPI3REF: Determine If An SQL Statement Writes The Database
  12.916 @@ -3688,8 +3919,12 @@
  12.917  ** sqlite3_stmt_readonly() to return true since, while those statements
  12.918  ** change the configuration of a database connection, they do not make 
  12.919  ** changes to the content of the database files on disk.
  12.920 -*/
  12.921 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  12.922 +** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
  12.923 +** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
  12.924 +** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
  12.925 +** sqlite3_stmt_readonly() returns false for those commands.
  12.926 +*/
  12.927 +SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  12.928  
  12.929  /*
  12.930  ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
  12.931 @@ -3710,7 +3945,7 @@
  12.932  ** for example, in diagnostic routines to search for prepared 
  12.933  ** statements that are holding a transaction open.
  12.934  */
  12.935 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_busy(sqlite3_stmt*);
  12.936 +SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
  12.937  
  12.938  /*
  12.939  ** CAPI3REF: Dynamically Typed Value Object
  12.940 @@ -3751,7 +3986,7 @@
  12.941  ** The [sqlite3_value_blob | sqlite3_value_type()] family of
  12.942  ** interfaces require protected sqlite3_value objects.
  12.943  */
  12.944 -typedef struct Mem sqlite3_value;
  12.945 +typedef struct sqlite3_value sqlite3_value;
  12.946  
  12.947  /*
  12.948  ** CAPI3REF: SQL Function Context Object
  12.949 @@ -3874,20 +4109,20 @@
  12.950  ** See also: [sqlite3_bind_parameter_count()],
  12.951  ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
  12.952  */
  12.953 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  12.954 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
  12.955 +SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
  12.956 +SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
  12.957                          void(*)(void*));
  12.958 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_double(sqlite3_stmt*, int, double);
  12.959 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_int(sqlite3_stmt*, int, int);
  12.960 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  12.961 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_null(sqlite3_stmt*, int);
  12.962 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
  12.963 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  12.964 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
  12.965 +SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
  12.966 +SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
  12.967 +SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
  12.968 +SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
  12.969 +SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
  12.970 +SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
  12.971 +SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
  12.972                           void(*)(void*), unsigned char encoding);
  12.973 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  12.974 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  12.975 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
  12.976 +SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
  12.977 +SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
  12.978 +SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
  12.979  
  12.980  /*
  12.981  ** CAPI3REF: Number Of SQL Parameters
  12.982 @@ -3908,7 +4143,7 @@
  12.983  ** [sqlite3_bind_parameter_name()], and
  12.984  ** [sqlite3_bind_parameter_index()].
  12.985  */
  12.986 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_count(sqlite3_stmt*);
  12.987 +SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
  12.988  
  12.989  /*
  12.990  ** CAPI3REF: Name Of A Host Parameter
  12.991 @@ -3936,7 +4171,7 @@
  12.992  ** [sqlite3_bind_parameter_count()], and
  12.993  ** [sqlite3_bind_parameter_index()].
  12.994  */
  12.995 -SQLITE_API const char *SQLITE_STDCALL sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  12.996 +SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
  12.997  
  12.998  /*
  12.999  ** CAPI3REF: Index Of A Parameter With A Given Name
 12.1000 @@ -3953,7 +4188,7 @@
 12.1001  ** [sqlite3_bind_parameter_count()], and
 12.1002  ** [sqlite3_bind_parameter_name()].
 12.1003  */
 12.1004 -SQLITE_API int SQLITE_STDCALL sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
 12.1005 +SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
 12.1006  
 12.1007  /*
 12.1008  ** CAPI3REF: Reset All Bindings On A Prepared Statement
 12.1009 @@ -3963,19 +4198,23 @@
 12.1010  ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
 12.1011  ** ^Use this routine to reset all host parameters to NULL.
 12.1012  */
 12.1013 -SQLITE_API int SQLITE_STDCALL sqlite3_clear_bindings(sqlite3_stmt*);
 12.1014 +SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
 12.1015  
 12.1016  /*
 12.1017  ** CAPI3REF: Number Of Columns In A Result Set
 12.1018  ** METHOD: sqlite3_stmt
 12.1019  **
 12.1020  ** ^Return the number of columns in the result set returned by the
 12.1021 -** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
 12.1022 -** statement that does not return data (for example an [UPDATE]).
 12.1023 +** [prepared statement]. ^If this routine returns 0, that means the 
 12.1024 +** [prepared statement] returns no data (for example an [UPDATE]).
 12.1025 +** ^However, just because this routine returns a positive number does not
 12.1026 +** mean that one or more rows of data will be returned.  ^A SELECT statement
 12.1027 +** will always have a positive sqlite3_column_count() but depending on the
 12.1028 +** WHERE clause constraints and the table content, it might return no rows.
 12.1029  **
 12.1030  ** See also: [sqlite3_data_count()]
 12.1031  */
 12.1032 -SQLITE_API int SQLITE_STDCALL sqlite3_column_count(sqlite3_stmt *pStmt);
 12.1033 +SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
 12.1034  
 12.1035  /*
 12.1036  ** CAPI3REF: Column Names In A Result Set
 12.1037 @@ -4004,8 +4243,8 @@
 12.1038  ** then the name of the column is unspecified and may change from
 12.1039  ** one release of SQLite to the next.
 12.1040  */
 12.1041 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_name(sqlite3_stmt*, int N);
 12.1042 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_name16(sqlite3_stmt*, int N);
 12.1043 +SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
 12.1044 +SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
 12.1045  
 12.1046  /*
 12.1047  ** CAPI3REF: Source Of Data In A Query Result
 12.1048 @@ -4053,12 +4292,12 @@
 12.1049  ** for the same [prepared statement] and result column
 12.1050  ** at the same time then the results are undefined.
 12.1051  */
 12.1052 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_database_name(sqlite3_stmt*,int);
 12.1053 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_database_name16(sqlite3_stmt*,int);
 12.1054 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_table_name(sqlite3_stmt*,int);
 12.1055 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_table_name16(sqlite3_stmt*,int);
 12.1056 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_origin_name(sqlite3_stmt*,int);
 12.1057 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_origin_name16(sqlite3_stmt*,int);
 12.1058 +SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
 12.1059 +SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
 12.1060 +SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
 12.1061 +SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
 12.1062 +SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
 12.1063 +SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
 12.1064  
 12.1065  /*
 12.1066  ** CAPI3REF: Declared Datatype Of A Query Result
 12.1067 @@ -4090,8 +4329,8 @@
 12.1068  ** is associated with individual values, not with the containers
 12.1069  ** used to hold those values.
 12.1070  */
 12.1071 -SQLITE_API const char *SQLITE_STDCALL sqlite3_column_decltype(sqlite3_stmt*,int);
 12.1072 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_decltype16(sqlite3_stmt*,int);
 12.1073 +SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
 12.1074 +SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
 12.1075  
 12.1076  /*
 12.1077  ** CAPI3REF: Evaluate An SQL Statement
 12.1078 @@ -4152,7 +4391,8 @@
 12.1079  ** other than [SQLITE_ROW] before any subsequent invocation of
 12.1080  ** sqlite3_step().  Failure to reset the prepared statement using 
 12.1081  ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
 12.1082 -** sqlite3_step().  But after version 3.6.23.1, sqlite3_step() began
 12.1083 +** sqlite3_step().  But after [version 3.6.23.1] ([dateof:3.6.23.1],
 12.1084 +** sqlite3_step() began
 12.1085  ** calling [sqlite3_reset()] automatically in this circumstance rather
 12.1086  ** than returning [SQLITE_MISUSE].  This is not considered a compatibility
 12.1087  ** break because any application that ever receives an SQLITE_MISUSE error
 12.1088 @@ -4171,7 +4411,7 @@
 12.1089  ** then the more specific [error codes] are returned directly
 12.1090  ** by sqlite3_step().  The use of the "v2" interface is recommended.
 12.1091  */
 12.1092 -SQLITE_API int SQLITE_STDCALL sqlite3_step(sqlite3_stmt*);
 12.1093 +SQLITE_API int sqlite3_step(sqlite3_stmt*);
 12.1094  
 12.1095  /*
 12.1096  ** CAPI3REF: Number of columns in a result set
 12.1097 @@ -4192,7 +4432,7 @@
 12.1098  **
 12.1099  ** See also: [sqlite3_column_count()]
 12.1100  */
 12.1101 -SQLITE_API int SQLITE_STDCALL sqlite3_data_count(sqlite3_stmt *pStmt);
 12.1102 +SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
 12.1103  
 12.1104  /*
 12.1105  ** CAPI3REF: Fundamental Datatypes
 12.1106 @@ -4382,16 +4622,16 @@
 12.1107  ** pointer.  Subsequent calls to [sqlite3_errcode()] will return
 12.1108  ** [SQLITE_NOMEM].)^
 12.1109  */
 12.1110 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_blob(sqlite3_stmt*, int iCol);
 12.1111 -SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes(sqlite3_stmt*, int iCol);
 12.1112 -SQLITE_API int SQLITE_STDCALL sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
 12.1113 -SQLITE_API double SQLITE_STDCALL sqlite3_column_double(sqlite3_stmt*, int iCol);
 12.1114 -SQLITE_API int SQLITE_STDCALL sqlite3_column_int(sqlite3_stmt*, int iCol);
 12.1115 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_column_int64(sqlite3_stmt*, int iCol);
 12.1116 -SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_column_text(sqlite3_stmt*, int iCol);
 12.1117 -SQLITE_API const void *SQLITE_STDCALL sqlite3_column_text16(sqlite3_stmt*, int iCol);
 12.1118 -SQLITE_API int SQLITE_STDCALL sqlite3_column_type(sqlite3_stmt*, int iCol);
 12.1119 -SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_column_value(sqlite3_stmt*, int iCol);
 12.1120 +SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
 12.1121 +SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
 12.1122 +SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
 12.1123 +SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
 12.1124 +SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
 12.1125 +SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
 12.1126 +SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
 12.1127 +SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
 12.1128 +SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
 12.1129 +SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
 12.1130  
 12.1131  /*
 12.1132  ** CAPI3REF: Destroy A Prepared Statement Object
 12.1133 @@ -4419,7 +4659,7 @@
 12.1134  ** statement after it has been finalized can result in undefined and
 12.1135  ** undesirable behavior such as segfaults and heap corruption.
 12.1136  */
 12.1137 -SQLITE_API int SQLITE_STDCALL sqlite3_finalize(sqlite3_stmt *pStmt);
 12.1138 +SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
 12.1139  
 12.1140  /*
 12.1141  ** CAPI3REF: Reset A Prepared Statement Object
 12.1142 @@ -4446,7 +4686,7 @@
 12.1143  ** ^The [sqlite3_reset(S)] interface does not change the values
 12.1144  ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
 12.1145  */
 12.1146 -SQLITE_API int SQLITE_STDCALL sqlite3_reset(sqlite3_stmt *pStmt);
 12.1147 +SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
 12.1148  
 12.1149  /*
 12.1150  ** CAPI3REF: Create Or Redefine SQL Functions
 12.1151 @@ -4546,7 +4786,7 @@
 12.1152  ** close the database connection nor finalize or reset the prepared
 12.1153  ** statement in which the function is running.
 12.1154  */
 12.1155 -SQLITE_API int SQLITE_STDCALL sqlite3_create_function(
 12.1156 +SQLITE_API int sqlite3_create_function(
 12.1157    sqlite3 *db,
 12.1158    const char *zFunctionName,
 12.1159    int nArg,
 12.1160 @@ -4556,7 +4796,7 @@
 12.1161    void (*xStep)(sqlite3_context*,int,sqlite3_value**),
 12.1162    void (*xFinal)(sqlite3_context*)
 12.1163  );
 12.1164 -SQLITE_API int SQLITE_STDCALL sqlite3_create_function16(
 12.1165 +SQLITE_API int sqlite3_create_function16(
 12.1166    sqlite3 *db,
 12.1167    const void *zFunctionName,
 12.1168    int nArg,
 12.1169 @@ -4566,7 +4806,7 @@
 12.1170    void (*xStep)(sqlite3_context*,int,sqlite3_value**),
 12.1171    void (*xFinal)(sqlite3_context*)
 12.1172  );
 12.1173 -SQLITE_API int SQLITE_STDCALL sqlite3_create_function_v2(
 12.1174 +SQLITE_API int sqlite3_create_function_v2(
 12.1175    sqlite3 *db,
 12.1176    const char *zFunctionName,
 12.1177    int nArg,
 12.1178 @@ -4612,12 +4852,12 @@
 12.1179  ** these functions, we will not explain what they do.
 12.1180  */
 12.1181  #ifndef SQLITE_OMIT_DEPRECATED
 12.1182 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_aggregate_count(sqlite3_context*);
 12.1183 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_expired(sqlite3_stmt*);
 12.1184 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
 12.1185 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_global_recover(void);
 12.1186 -SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_thread_cleanup(void);
 12.1187 -SQLITE_API SQLITE_DEPRECATED int SQLITE_STDCALL sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
 12.1188 +SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
 12.1189 +SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
 12.1190 +SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
 12.1191 +SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
 12.1192 +SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
 12.1193 +SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
 12.1194                        void*,sqlite3_int64);
 12.1195  #endif
 12.1196  
 12.1197 @@ -4667,18 +4907,18 @@
 12.1198  ** These routines must be called from the same thread as
 12.1199  ** the SQL function that supplied the [sqlite3_value*] parameters.
 12.1200  */
 12.1201 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_blob(sqlite3_value*);
 12.1202 -SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes(sqlite3_value*);
 12.1203 -SQLITE_API int SQLITE_STDCALL sqlite3_value_bytes16(sqlite3_value*);
 12.1204 -SQLITE_API double SQLITE_STDCALL sqlite3_value_double(sqlite3_value*);
 12.1205 -SQLITE_API int SQLITE_STDCALL sqlite3_value_int(sqlite3_value*);
 12.1206 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_value_int64(sqlite3_value*);
 12.1207 -SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_value_text(sqlite3_value*);
 12.1208 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16(sqlite3_value*);
 12.1209 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*);
 12.1210 -SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*);
 12.1211 -SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
 12.1212 -SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
 12.1213 +SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
 12.1214 +SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
 12.1215 +SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
 12.1216 +SQLITE_API double sqlite3_value_double(sqlite3_value*);
 12.1217 +SQLITE_API int sqlite3_value_int(sqlite3_value*);
 12.1218 +SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
 12.1219 +SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
 12.1220 +SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
 12.1221 +SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
 12.1222 +SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
 12.1223 +SQLITE_API int sqlite3_value_type(sqlite3_value*);
 12.1224 +SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
 12.1225  
 12.1226  /*
 12.1227  ** CAPI3REF: Finding The Subtype Of SQL Values
 12.1228 @@ -4694,7 +4934,7 @@
 12.1229  ** from the result of one [application-defined SQL function] into the
 12.1230  ** input of another.
 12.1231  */
 12.1232 -SQLITE_API unsigned int SQLITE_STDCALL sqlite3_value_subtype(sqlite3_value*);
 12.1233 +SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);
 12.1234  
 12.1235  /*
 12.1236  ** CAPI3REF: Copy And Free SQL Values
 12.1237 @@ -4710,8 +4950,8 @@
 12.1238  ** previously obtained from [sqlite3_value_dup()].  ^If V is a NULL pointer
 12.1239  ** then sqlite3_value_free(V) is a harmless no-op.
 12.1240  */
 12.1241 -SQLITE_API sqlite3_value *SQLITE_STDCALL sqlite3_value_dup(const sqlite3_value*);
 12.1242 -SQLITE_API void SQLITE_STDCALL sqlite3_value_free(sqlite3_value*);
 12.1243 +SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*);
 12.1244 +SQLITE_API void sqlite3_value_free(sqlite3_value*);
 12.1245  
 12.1246  /*
 12.1247  ** CAPI3REF: Obtain Aggregate Function Context
 12.1248 @@ -4756,7 +4996,7 @@
 12.1249  ** This routine must be called from the same thread in which
 12.1250  ** the aggregate SQL function is running.
 12.1251  */
 12.1252 -SQLITE_API void *SQLITE_STDCALL sqlite3_aggregate_context(sqlite3_context*, int nBytes);
 12.1253 +SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
 12.1254  
 12.1255  /*
 12.1256  ** CAPI3REF: User Data For Functions
 12.1257 @@ -4771,7 +5011,7 @@
 12.1258  ** This routine must be called from the same thread in which
 12.1259  ** the application-defined function is running.
 12.1260  */
 12.1261 -SQLITE_API void *SQLITE_STDCALL sqlite3_user_data(sqlite3_context*);
 12.1262 +SQLITE_API void *sqlite3_user_data(sqlite3_context*);
 12.1263  
 12.1264  /*
 12.1265  ** CAPI3REF: Database Connection For Functions
 12.1266 @@ -4783,7 +5023,7 @@
 12.1267  ** and [sqlite3_create_function16()] routines that originally
 12.1268  ** registered the application defined function.
 12.1269  */
 12.1270 -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context*);
 12.1271 +SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
 12.1272  
 12.1273  /*
 12.1274  ** CAPI3REF: Function Auxiliary Data
 12.1275 @@ -4800,10 +5040,11 @@
 12.1276  ** the compiled regular expression can be reused on multiple
 12.1277  ** invocations of the same function.
 12.1278  **
 12.1279 -** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
 12.1280 -** associated by the sqlite3_set_auxdata() function with the Nth argument
 12.1281 -** value to the application-defined function. ^If there is no metadata
 12.1282 -** associated with the function argument, this sqlite3_get_auxdata() interface
 12.1283 +** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
 12.1284 +** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
 12.1285 +** value to the application-defined function.  ^N is zero for the left-most
 12.1286 +** function argument.  ^If there is no metadata
 12.1287 +** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
 12.1288  ** returns a NULL pointer.
 12.1289  **
 12.1290  ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
 12.1291 @@ -4815,12 +5056,13 @@
 12.1292  ** SQLite will invoke the destructor function X with parameter P exactly
 12.1293  ** once, when the metadata is discarded.
 12.1294  ** SQLite is free to discard the metadata at any time, including: <ul>
 12.1295 -** <li> when the corresponding function parameter changes, or
 12.1296 -** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
 12.1297 -**      SQL statement, or
 12.1298 -** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
 12.1299 -** <li> during the original sqlite3_set_auxdata() call when a memory 
 12.1300 -**      allocation error occurs. </ul>)^
 12.1301 +** <li> ^(when the corresponding function parameter changes)^, or
 12.1302 +** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
 12.1303 +**      SQL statement)^, or
 12.1304 +** <li> ^(when sqlite3_set_auxdata() is invoked again on the same
 12.1305 +**       parameter)^, or
 12.1306 +** <li> ^(during the original sqlite3_set_auxdata() call when a memory 
 12.1307 +**      allocation error occurs.)^ </ul>
 12.1308  **
 12.1309  ** Note the last bullet in particular.  The destructor X in 
 12.1310  ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
 12.1311 @@ -4833,11 +5075,15 @@
 12.1312  ** function parameters that are compile-time constants, including literal
 12.1313  ** values and [parameters] and expressions composed from the same.)^
 12.1314  **
 12.1315 +** The value of the N parameter to these interfaces should be non-negative.
 12.1316 +** Future enhancements may make use of negative N values to define new
 12.1317 +** kinds of function caching behavior.
 12.1318 +**
 12.1319  ** These routines must be called from the same thread in which
 12.1320  ** the SQL function is running.
 12.1321  */
 12.1322 -SQLITE_API void *SQLITE_STDCALL sqlite3_get_auxdata(sqlite3_context*, int N);
 12.1323 -SQLITE_API void SQLITE_STDCALL sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
 12.1324 +SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
 12.1325 +SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
 12.1326  
 12.1327  
 12.1328  /*
 12.1329 @@ -4973,27 +5219,27 @@
 12.1330  ** than the one containing the application-defined function that received
 12.1331  ** the [sqlite3_context] pointer, the results are undefined.
 12.1332  */
 12.1333 -SQLITE_API void SQLITE_STDCALL sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
 12.1334 -SQLITE_API void SQLITE_STDCALL sqlite3_result_blob64(sqlite3_context*,const void*,
 12.1335 +SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
 12.1336 +SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
 12.1337                             sqlite3_uint64,void(*)(void*));
 12.1338 -SQLITE_API void SQLITE_STDCALL sqlite3_result_double(sqlite3_context*, double);
 12.1339 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error(sqlite3_context*, const char*, int);
 12.1340 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error16(sqlite3_context*, const void*, int);
 12.1341 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_toobig(sqlite3_context*);
 12.1342 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_nomem(sqlite3_context*);
 12.1343 -SQLITE_API void SQLITE_STDCALL sqlite3_result_error_code(sqlite3_context*, int);
 12.1344 -SQLITE_API void SQLITE_STDCALL sqlite3_result_int(sqlite3_context*, int);
 12.1345 -SQLITE_API void SQLITE_STDCALL sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
 12.1346 -SQLITE_API void SQLITE_STDCALL sqlite3_result_null(sqlite3_context*);
 12.1347 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
 12.1348 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
 12.1349 +SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
 12.1350 +SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
 12.1351 +SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
 12.1352 +SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
 12.1353 +SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
 12.1354 +SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
 12.1355 +SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
 12.1356 +SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
 12.1357 +SQLITE_API void sqlite3_result_null(sqlite3_context*);
 12.1358 +SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
 12.1359 +SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
 12.1360                             void(*)(void*), unsigned char encoding);
 12.1361 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
 12.1362 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
 12.1363 -SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
 12.1364 -SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
 12.1365 -SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
 12.1366 -SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
 12.1367 +SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
 12.1368 +SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
 12.1369 +SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
 12.1370 +SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
 12.1371 +SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
 12.1372 +SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
 12.1373  
 12.1374  
 12.1375  /*
 12.1376 @@ -5008,7 +5254,7 @@
 12.1377  ** The number of subtype bytes preserved by SQLite might increase
 12.1378  ** in future releases of SQLite.
 12.1379  */
 12.1380 -SQLITE_API void SQLITE_STDCALL sqlite3_result_subtype(sqlite3_context*,unsigned int);
 12.1381 +SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int);
 12.1382  
 12.1383  /*
 12.1384  ** CAPI3REF: Define New Collating Sequences
 12.1385 @@ -5090,14 +5336,14 @@
 12.1386  **
 12.1387  ** See also:  [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
 12.1388  */
 12.1389 -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation(
 12.1390 +SQLITE_API int sqlite3_create_collation(
 12.1391    sqlite3*, 
 12.1392    const char *zName, 
 12.1393    int eTextRep, 
 12.1394    void *pArg,
 12.1395    int(*xCompare)(void*,int,const void*,int,const void*)
 12.1396  );
 12.1397 -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation_v2(
 12.1398 +SQLITE_API int sqlite3_create_collation_v2(
 12.1399    sqlite3*, 
 12.1400    const char *zName, 
 12.1401    int eTextRep, 
 12.1402 @@ -5105,7 +5351,7 @@
 12.1403    int(*xCompare)(void*,int,const void*,int,const void*),
 12.1404    void(*xDestroy)(void*)
 12.1405  );
 12.1406 -SQLITE_API int SQLITE_STDCALL sqlite3_create_collation16(
 12.1407 +SQLITE_API int sqlite3_create_collation16(
 12.1408    sqlite3*, 
 12.1409    const void *zName,
 12.1410    int eTextRep, 
 12.1411 @@ -5140,12 +5386,12 @@
 12.1412  ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
 12.1413  ** [sqlite3_create_collation_v2()].
 12.1414  */
 12.1415 -SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed(
 12.1416 +SQLITE_API int sqlite3_collation_needed(
 12.1417    sqlite3*, 
 12.1418    void*, 
 12.1419    void(*)(void*,sqlite3*,int eTextRep,const char*)
 12.1420  );
 12.1421 -SQLITE_API int SQLITE_STDCALL sqlite3_collation_needed16(
 12.1422 +SQLITE_API int sqlite3_collation_needed16(
 12.1423    sqlite3*, 
 12.1424    void*,
 12.1425    void(*)(void*,sqlite3*,int eTextRep,const void*)
 12.1426 @@ -5159,11 +5405,11 @@
 12.1427  ** The code to implement this API is not available in the public release
 12.1428  ** of SQLite.
 12.1429  */
 12.1430 -SQLITE_API int SQLITE_STDCALL sqlite3_key(
 12.1431 +SQLITE_API int sqlite3_key(
 12.1432    sqlite3 *db,                   /* Database to be rekeyed */
 12.1433    const void *pKey, int nKey     /* The key */
 12.1434  );
 12.1435 -SQLITE_API int SQLITE_STDCALL sqlite3_key_v2(
 12.1436 +SQLITE_API int sqlite3_key_v2(
 12.1437    sqlite3 *db,                   /* Database to be rekeyed */
 12.1438    const char *zDbName,           /* Name of the database */
 12.1439    const void *pKey, int nKey     /* The key */
 12.1440 @@ -5177,11 +5423,11 @@
 12.1441  ** The code to implement this API is not available in the public release
 12.1442  ** of SQLite.
 12.1443  */
 12.1444 -SQLITE_API int SQLITE_STDCALL sqlite3_rekey(
 12.1445 +SQLITE_API int sqlite3_rekey(
 12.1446    sqlite3 *db,                   /* Database to be rekeyed */
 12.1447    const void *pKey, int nKey     /* The new key */
 12.1448  );
 12.1449 -SQLITE_API int SQLITE_STDCALL sqlite3_rekey_v2(
 12.1450 +SQLITE_API int sqlite3_rekey_v2(
 12.1451    sqlite3 *db,                   /* Database to be rekeyed */
 12.1452    const char *zDbName,           /* Name of the database */
 12.1453    const void *pKey, int nKey     /* The new key */
 12.1454 @@ -5191,7 +5437,7 @@
 12.1455  ** Specify the activation key for a SEE database.  Unless 
 12.1456  ** activated, none of the SEE routines will work.
 12.1457  */
 12.1458 -SQLITE_API void SQLITE_STDCALL sqlite3_activate_see(
 12.1459 +SQLITE_API void sqlite3_activate_see(
 12.1460    const char *zPassPhrase        /* Activation phrase */
 12.1461  );
 12.1462  #endif
 12.1463 @@ -5201,7 +5447,7 @@
 12.1464  ** Specify the activation key for a CEROD database.  Unless 
 12.1465  ** activated, none of the CEROD routines will work.
 12.1466  */
 12.1467 -SQLITE_API void SQLITE_STDCALL sqlite3_activate_cerod(
 12.1468 +SQLITE_API void sqlite3_activate_cerod(
 12.1469    const char *zPassPhrase        /* Activation phrase */
 12.1470  );
 12.1471  #endif
 12.1472 @@ -5223,7 +5469,7 @@
 12.1473  ** all, then the behavior of sqlite3_sleep() may deviate from the description
 12.1474  ** in the previous paragraphs.
 12.1475  */
 12.1476 -SQLITE_API int SQLITE_STDCALL sqlite3_sleep(int);
 12.1477 +SQLITE_API int sqlite3_sleep(int);
 12.1478  
 12.1479  /*
 12.1480  ** CAPI3REF: Name Of The Folder Holding Temporary Files
 12.1481 @@ -5342,7 +5588,7 @@
 12.1482  ** connection while this routine is running, then the return value
 12.1483  ** is undefined.
 12.1484  */
 12.1485 -SQLITE_API int SQLITE_STDCALL sqlite3_get_autocommit(sqlite3*);
 12.1486 +SQLITE_API int sqlite3_get_autocommit(sqlite3*);
 12.1487  
 12.1488  /*
 12.1489  ** CAPI3REF: Find The Database Handle Of A Prepared Statement
 12.1490 @@ -5355,7 +5601,7 @@
 12.1491  ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
 12.1492  ** create the statement in the first place.
 12.1493  */
 12.1494 -SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_db_handle(sqlite3_stmt*);
 12.1495 +SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
 12.1496  
 12.1497  /*
 12.1498  ** CAPI3REF: Return The Filename For A Database Connection
 12.1499 @@ -5372,7 +5618,7 @@
 12.1500  ** will be an absolute pathname, even if the filename used
 12.1501  ** to open the database originally was a URI or relative pathname.
 12.1502  */
 12.1503 -SQLITE_API const char *SQLITE_STDCALL sqlite3_db_filename(sqlite3 *db, const char *zDbName);
 12.1504 +SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
 12.1505  
 12.1506  /*
 12.1507  ** CAPI3REF: Determine if a database is read-only
 12.1508 @@ -5382,7 +5628,7 @@
 12.1509  ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
 12.1510  ** the name of a database on connection D.
 12.1511  */
 12.1512 -SQLITE_API int SQLITE_STDCALL sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
 12.1513 +SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
 12.1514  
 12.1515  /*
 12.1516  ** CAPI3REF: Find the next prepared statement
 12.1517 @@ -5398,7 +5644,7 @@
 12.1518  ** [sqlite3_next_stmt(D,S)] must refer to an open database
 12.1519  ** connection and in particular must not be a NULL pointer.
 12.1520  */
 12.1521 -SQLITE_API sqlite3_stmt *SQLITE_STDCALL sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
 12.1522 +SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
 12.1523  
 12.1524  /*
 12.1525  ** CAPI3REF: Commit And Rollback Notification Callbacks
 12.1526 @@ -5447,8 +5693,8 @@
 12.1527  **
 12.1528  ** See also the [sqlite3_update_hook()] interface.
 12.1529  */
 12.1530 -SQLITE_API void *SQLITE_STDCALL sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
 12.1531 -SQLITE_API void *SQLITE_STDCALL sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
 12.1532 +SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
 12.1533 +SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
 12.1534  
 12.1535  /*
 12.1536  ** CAPI3REF: Data Change Notification Callbacks
 12.1537 @@ -5478,7 +5724,7 @@
 12.1538  ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
 12.1539  **
 12.1540  ** ^In the current implementation, the update hook
 12.1541 -** is not invoked when duplication rows are deleted because of an
 12.1542 +** is not invoked when conflicting rows are deleted because of an
 12.1543  ** [ON CONFLICT | ON CONFLICT REPLACE] clause.  ^Nor is the update hook
 12.1544  ** invoked when rows are deleted using the [truncate optimization].
 12.1545  ** The exceptions defined in this paragraph might change in a future
 12.1546 @@ -5499,7 +5745,7 @@
 12.1547  ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
 12.1548  ** and [sqlite3_preupdate_hook()] interfaces.
 12.1549  */
 12.1550 -SQLITE_API void *SQLITE_STDCALL sqlite3_update_hook(
 12.1551 +SQLITE_API void *sqlite3_update_hook(
 12.1552    sqlite3*, 
 12.1553    void(*)(void *,int ,char const *,char const *,sqlite3_int64),
 12.1554    void*
 12.1555 @@ -5514,7 +5760,8 @@
 12.1556  ** and disabled if the argument is false.)^
 12.1557  **
 12.1558  ** ^Cache sharing is enabled and disabled for an entire process.
 12.1559 -** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
 12.1560 +** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]). 
 12.1561 +** In prior versions of SQLite,
 12.1562  ** sharing was enabled or disabled for each thread separately.
 12.1563  **
 12.1564  ** ^(The cache sharing mode set by this interface effects all subsequent
 12.1565 @@ -5539,7 +5786,7 @@
 12.1566  **
 12.1567  ** See Also:  [SQLite Shared-Cache Mode]
 12.1568  */
 12.1569 -SQLITE_API int SQLITE_STDCALL sqlite3_enable_shared_cache(int);
 12.1570 +SQLITE_API int sqlite3_enable_shared_cache(int);
 12.1571  
 12.1572  /*
 12.1573  ** CAPI3REF: Attempt To Free Heap Memory
 12.1574 @@ -5555,7 +5802,7 @@
 12.1575  **
 12.1576  ** See also: [sqlite3_db_release_memory()]
 12.1577  */
 12.1578 -SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int);
 12.1579 +SQLITE_API int sqlite3_release_memory(int);
 12.1580  
 12.1581  /*
 12.1582  ** CAPI3REF: Free Memory Used By A Database Connection
 12.1583 @@ -5569,7 +5816,7 @@
 12.1584  **
 12.1585  ** See also: [sqlite3_release_memory()]
 12.1586  */
 12.1587 -SQLITE_API int SQLITE_STDCALL sqlite3_db_release_memory(sqlite3*);
 12.1588 +SQLITE_API int sqlite3_db_release_memory(sqlite3*);
 12.1589  
 12.1590  /*
 12.1591  ** CAPI3REF: Impose A Limit On Heap Size
 12.1592 @@ -5608,7 +5855,8 @@
 12.1593  **      from the heap.
 12.1594  ** </ul>)^
 12.1595  **
 12.1596 -** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
 12.1597 +** Beginning with SQLite [version 3.7.3] ([dateof:3.7.3]), 
 12.1598 +** the soft heap limit is enforced
 12.1599  ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
 12.1600  ** compile-time option is invoked.  With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
 12.1601  ** the soft heap limit is enforced on every memory allocation.  Without
 12.1602 @@ -5621,7 +5869,7 @@
 12.1603  ** The circumstances under which SQLite will enforce the soft heap limit may
 12.1604  ** changes in future releases of SQLite.
 12.1605  */
 12.1606 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 N);
 12.1607 +SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
 12.1608  
 12.1609  /*
 12.1610  ** CAPI3REF: Deprecated Soft Heap Limit Interface
 12.1611 @@ -5632,7 +5880,7 @@
 12.1612  ** only.  All new applications should use the
 12.1613  ** [sqlite3_soft_heap_limit64()] interface rather than this one.
 12.1614  */
 12.1615 -SQLITE_API SQLITE_DEPRECATED void SQLITE_STDCALL sqlite3_soft_heap_limit(int N);
 12.1616 +SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
 12.1617  
 12.1618  
 12.1619  /*
 12.1620 @@ -5647,7 +5895,7 @@
 12.1621  ** column exists.  ^The sqlite3_table_column_metadata() interface returns
 12.1622  ** SQLITE_ERROR and if the specified column does not exist.
 12.1623  ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
 12.1624 -** NULL pointer, then this routine simply checks for the existance of the
 12.1625 +** NULL pointer, then this routine simply checks for the existence of the
 12.1626  ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
 12.1627  ** does not.
 12.1628  **
 12.1629 @@ -5702,7 +5950,7 @@
 12.1630  ** parsed, if that has not already been done, and returns an error if
 12.1631  ** any errors are encountered while loading the schema.
 12.1632  */
 12.1633 -SQLITE_API int SQLITE_STDCALL sqlite3_table_column_metadata(
 12.1634 +SQLITE_API int sqlite3_table_column_metadata(
 12.1635    sqlite3 *db,                /* Connection handle */
 12.1636    const char *zDbName,        /* Database name or NULL */
 12.1637    const char *zTableName,     /* Table name */
 12.1638 @@ -5758,7 +6006,7 @@
 12.1639  **
 12.1640  ** See also the [load_extension() SQL function].
 12.1641  */
 12.1642 -SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
 12.1643 +SQLITE_API int sqlite3_load_extension(
 12.1644    sqlite3 *db,          /* Load the extension into this database connection */
 12.1645    const char *zFile,    /* Name of the shared library containing extension */
 12.1646    const char *zProc,    /* Entry point.  Derived from zFile if 0 */
 12.1647 @@ -5781,8 +6029,8 @@
 12.1648  **
 12.1649  ** ^This interface enables or disables both the C-API
 12.1650  ** [sqlite3_load_extension()] and the SQL function [load_extension()].
 12.1651 -** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
 12.1652 -** to enable or disable only the C-API.
 12.1653 +** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
 12.1654 +** to enable or disable only the C-API.)^
 12.1655  **
 12.1656  ** <b>Security warning:</b> It is recommended that extension loading
 12.1657  ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
 12.1658 @@ -5790,7 +6038,7 @@
 12.1659  ** remains disabled. This will prevent SQL injections from giving attackers
 12.1660  ** access to extension loading capabilities.
 12.1661  */
 12.1662 -SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
 12.1663 +SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
 12.1664  
 12.1665  /*
 12.1666  ** CAPI3REF: Automatically Load Statically Linked Extensions
 12.1667 @@ -5802,7 +6050,7 @@
 12.1668  **
 12.1669  ** ^(Even though the function prototype shows that xEntryPoint() takes
 12.1670  ** no arguments and returns void, SQLite invokes xEntryPoint() with three
 12.1671 -** arguments and expects and integer result as if the signature of the
 12.1672 +** arguments and expects an integer result as if the signature of the
 12.1673  ** entry point where as follows:
 12.1674  **
 12.1675  ** <blockquote><pre>
 12.1676 @@ -5828,7 +6076,7 @@
 12.1677  ** See also: [sqlite3_reset_auto_extension()]
 12.1678  ** and [sqlite3_cancel_auto_extension()]
 12.1679  */
 12.1680 -SQLITE_API int SQLITE_STDCALL sqlite3_auto_extension(void (*xEntryPoint)(void));
 12.1681 +SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void));
 12.1682  
 12.1683  /*
 12.1684  ** CAPI3REF: Cancel Automatic Extension Loading
 12.1685 @@ -5840,7 +6088,7 @@
 12.1686  ** unregistered and it returns 0 if X was not on the list of initialization
 12.1687  ** routines.
 12.1688  */
 12.1689 -SQLITE_API int SQLITE_STDCALL sqlite3_cancel_auto_extension(void (*xEntryPoint)(void));
 12.1690 +SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void));
 12.1691  
 12.1692  /*
 12.1693  ** CAPI3REF: Reset Automatic Extension Loading
 12.1694 @@ -5848,7 +6096,7 @@
 12.1695  ** ^This interface disables all automatic extensions previously
 12.1696  ** registered using [sqlite3_auto_extension()].
 12.1697  */
 12.1698 -SQLITE_API void SQLITE_STDCALL sqlite3_reset_auto_extension(void);
 12.1699 +SQLITE_API void sqlite3_reset_auto_extension(void);
 12.1700  
 12.1701  /*
 12.1702  ** The interface to the virtual-table mechanism is currently considered
 12.1703 @@ -6002,13 +6250,15 @@
 12.1704  ** the xUpdate method are automatically rolled back by SQLite.
 12.1705  **
 12.1706  ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
 12.1707 -** structure for SQLite version 3.8.2. If a virtual table extension is
 12.1708 +** structure for SQLite [version 3.8.2] ([dateof:3.8.2]). 
 12.1709 +** If a virtual table extension is
 12.1710  ** used with an SQLite version earlier than 3.8.2, the results of attempting 
 12.1711  ** to read or write the estimatedRows field are undefined (but are likely 
 12.1712  ** to included crashing the application). The estimatedRows field should
 12.1713  ** therefore only be used if [sqlite3_libversion_number()] returns a
 12.1714  ** value greater than or equal to 3008002. Similarly, the idxFlags field
 12.1715 -** was added for version 3.9.0. It may therefore only be used if
 12.1716 +** was added for [version 3.9.0] ([dateof:3.9.0]). 
 12.1717 +** It may therefore only be used if
 12.1718  ** sqlite3_libversion_number() returns a value greater than or equal to
 12.1719  ** 3009000.
 12.1720  */
 12.1721 @@ -6093,13 +6343,13 @@
 12.1722  ** interface is equivalent to sqlite3_create_module_v2() with a NULL
 12.1723  ** destructor.
 12.1724  */
 12.1725 -SQLITE_API int SQLITE_STDCALL sqlite3_create_module(
 12.1726 +SQLITE_API int sqlite3_create_module(
 12.1727    sqlite3 *db,               /* SQLite connection to register module with */
 12.1728    const char *zName,         /* Name of the module */
 12.1729    const sqlite3_module *p,   /* Methods for the module */
 12.1730    void *pClientData          /* Client data for xCreate/xConnect */
 12.1731  );
 12.1732 -SQLITE_API int SQLITE_STDCALL sqlite3_create_module_v2(
 12.1733 +SQLITE_API int sqlite3_create_module_v2(
 12.1734    sqlite3 *db,               /* SQLite connection to register module with */
 12.1735    const char *zName,         /* Name of the module */
 12.1736    const sqlite3_module *p,   /* Methods for the module */
 12.1737 @@ -6162,7 +6412,7 @@
 12.1738  ** to declare the format (the names and datatypes of the columns) of
 12.1739  ** the virtual tables they implement.
 12.1740  */
 12.1741 -SQLITE_API int SQLITE_STDCALL sqlite3_declare_vtab(sqlite3*, const char *zSQL);
 12.1742 +SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
 12.1743  
 12.1744  /*
 12.1745  ** CAPI3REF: Overload A Function For A Virtual Table
 12.1746 @@ -6181,7 +6431,7 @@
 12.1747  ** purpose is to be a placeholder function that can be overloaded
 12.1748  ** by a [virtual table].
 12.1749  */
 12.1750 -SQLITE_API int SQLITE_STDCALL sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
 12.1751 +SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
 12.1752  
 12.1753  /*
 12.1754  ** The interface to the virtual-table mechanism defined above (back up
 12.1755 @@ -6256,6 +6506,12 @@
 12.1756  ** [database connection] error code and message accessible via 
 12.1757  ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. 
 12.1758  **
 12.1759 +** A BLOB referenced by sqlite3_blob_open() may be read using the
 12.1760 +** [sqlite3_blob_read()] interface and modified by using
 12.1761 +** [sqlite3_blob_write()].  The [BLOB handle] can be moved to a
 12.1762 +** different row of the same table using the [sqlite3_blob_reopen()]
 12.1763 +** interface.  However, the column, table, or database of a [BLOB handle]
 12.1764 +** cannot be changed after the [BLOB handle] is opened.
 12.1765  **
 12.1766  ** ^(If the row that a BLOB handle points to is modified by an
 12.1767  ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
 12.1768 @@ -6279,8 +6535,12 @@
 12.1769  **
 12.1770  ** To avoid a resource leak, every open [BLOB handle] should eventually
 12.1771  ** be released by a call to [sqlite3_blob_close()].
 12.1772 -*/
 12.1773 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_open(
 12.1774 +**
 12.1775 +** See also: [sqlite3_blob_close()],
 12.1776 +** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
 12.1777 +** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
 12.1778 +*/
 12.1779 +SQLITE_API int sqlite3_blob_open(
 12.1780    sqlite3*,
 12.1781    const char *zDb,
 12.1782    const char *zTable,
 12.1783 @@ -6294,11 +6554,11 @@
 12.1784  ** CAPI3REF: Move a BLOB Handle to a New Row
 12.1785  ** METHOD: sqlite3_blob
 12.1786  **
 12.1787 -** ^This function is used to move an existing blob handle so that it points
 12.1788 +** ^This function is used to move an existing [BLOB handle] so that it points
 12.1789  ** to a different row of the same database table. ^The new row is identified
 12.1790  ** by the rowid value passed as the second argument. Only the row can be
 12.1791  ** changed. ^The database, table and column on which the blob handle is open
 12.1792 -** remain the same. Moving an existing blob handle to a new row can be
 12.1793 +** remain the same. Moving an existing [BLOB handle] to a new row is
 12.1794  ** faster than closing the existing handle and opening a new one.
 12.1795  **
 12.1796  ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
 12.1797 @@ -6313,7 +6573,7 @@
 12.1798  **
 12.1799  ** ^This function sets the database handle error code and message.
 12.1800  */
 12.1801 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
 12.1802 +SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
 12.1803  
 12.1804  /*
 12.1805  ** CAPI3REF: Close A BLOB Handle
 12.1806 @@ -6336,7 +6596,7 @@
 12.1807  ** is passed a valid open blob handle, the values returned by the 
 12.1808  ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
 12.1809  */
 12.1810 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_close(sqlite3_blob *);
 12.1811 +SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
 12.1812  
 12.1813  /*
 12.1814  ** CAPI3REF: Return The Size Of An Open BLOB
 12.1815 @@ -6352,7 +6612,7 @@
 12.1816  ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
 12.1817  ** to this routine results in undefined and probably undesirable behavior.
 12.1818  */
 12.1819 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_bytes(sqlite3_blob *);
 12.1820 +SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
 12.1821  
 12.1822  /*
 12.1823  ** CAPI3REF: Read Data From A BLOB Incrementally
 12.1824 @@ -6381,7 +6641,7 @@
 12.1825  **
 12.1826  ** See also: [sqlite3_blob_write()].
 12.1827  */
 12.1828 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
 12.1829 +SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
 12.1830  
 12.1831  /*
 12.1832  ** CAPI3REF: Write Data Into A BLOB Incrementally
 12.1833 @@ -6423,7 +6683,7 @@
 12.1834  **
 12.1835  ** See also: [sqlite3_blob_read()].
 12.1836  */
 12.1837 -SQLITE_API int SQLITE_STDCALL sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
 12.1838 +SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
 12.1839  
 12.1840  /*
 12.1841  ** CAPI3REF: Virtual File System Objects
 12.1842 @@ -6454,9 +6714,9 @@
 12.1843  ** ^(If the default VFS is unregistered, another VFS is chosen as
 12.1844  ** the default.  The choice for the new VFS is arbitrary.)^
 12.1845  */
 12.1846 -SQLITE_API sqlite3_vfs *SQLITE_STDCALL sqlite3_vfs_find(const char *zVfsName);
 12.1847 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
 12.1848 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_unregister(sqlite3_vfs*);
 12.1849 +SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
 12.1850 +SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
 12.1851 +SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
 12.1852  
 12.1853  /*
 12.1854  ** CAPI3REF: Mutexes
 12.1855 @@ -6572,11 +6832,11 @@
 12.1856  **
 12.1857  ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
 12.1858  */
 12.1859 -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int);
 12.1860 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex*);
 12.1861 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex*);
 12.1862 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex*);
 12.1863 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex*);
 12.1864 +SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
 12.1865 +SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
 12.1866 +SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
 12.1867 +SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
 12.1868 +SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
 12.1869  
 12.1870  /*
 12.1871  ** CAPI3REF: Mutex Methods Object
 12.1872 @@ -6686,8 +6946,8 @@
 12.1873  ** interface should also return 1 when given a NULL pointer.
 12.1874  */
 12.1875  #ifndef NDEBUG
 12.1876 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex*);
 12.1877 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex*);
 12.1878 +SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
 12.1879 +SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
 12.1880  #endif
 12.1881  
 12.1882  /*
 12.1883 @@ -6706,7 +6966,7 @@
 12.1884  #define SQLITE_MUTEX_STATIC_MEM       3  /* sqlite3_malloc() */
 12.1885  #define SQLITE_MUTEX_STATIC_MEM2      4  /* NOT USED */
 12.1886  #define SQLITE_MUTEX_STATIC_OPEN      4  /* sqlite3BtreeOpen() */
 12.1887 -#define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_random() */
 12.1888 +#define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_randomness() */
 12.1889  #define SQLITE_MUTEX_STATIC_LRU       6  /* lru page list */
 12.1890  #define SQLITE_MUTEX_STATIC_LRU2      7  /* NOT USED */
 12.1891  #define SQLITE_MUTEX_STATIC_PMEM      7  /* sqlite3PageMalloc() */
 12.1892 @@ -6727,7 +6987,7 @@
 12.1893  ** ^If the [threading mode] is Single-thread or Multi-thread then this
 12.1894  ** routine returns a NULL pointer.
 12.1895  */
 12.1896 -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_db_mutex(sqlite3*);
 12.1897 +SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
 12.1898  
 12.1899  /*
 12.1900  ** CAPI3REF: Low-Level Control Of Database Files
 12.1901 @@ -6762,7 +7022,7 @@
 12.1902  **
 12.1903  ** See also: [SQLITE_FCNTL_LOCKSTATE]
 12.1904  */
 12.1905 -SQLITE_API int SQLITE_STDCALL sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
 12.1906 +SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
 12.1907  
 12.1908  /*
 12.1909  ** CAPI3REF: Testing Interface
 12.1910 @@ -6781,7 +7041,7 @@
 12.1911  ** Unlike most of the SQLite API, this function is not guaranteed to
 12.1912  ** operate consistently from one release to the next.
 12.1913  */
 12.1914 -SQLITE_API int SQLITE_CDECL sqlite3_test_control(int op, ...);
 12.1915 +SQLITE_API int sqlite3_test_control(int op, ...);
 12.1916  
 12.1917  /*
 12.1918  ** CAPI3REF: Testing Interface Operation Codes
 12.1919 @@ -6810,6 +7070,7 @@
 12.1920  #define SQLITE_TESTCTRL_SCRATCHMALLOC           17
 12.1921  #define SQLITE_TESTCTRL_LOCALTIME_FAULT         18
 12.1922  #define SQLITE_TESTCTRL_EXPLAIN_STMT            19  /* NOT USED */
 12.1923 +#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD    19
 12.1924  #define SQLITE_TESTCTRL_NEVER_CORRUPT           20
 12.1925  #define SQLITE_TESTCTRL_VDBE_COVERAGE           21
 12.1926  #define SQLITE_TESTCTRL_BYTEORDER               22
 12.1927 @@ -6844,8 +7105,8 @@
 12.1928  **
 12.1929  ** See also: [sqlite3_db_status()]
 12.1930  */
 12.1931 -SQLITE_API int SQLITE_STDCALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
 12.1932 -SQLITE_API int SQLITE_STDCALL sqlite3_status64(
 12.1933 +SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
 12.1934 +SQLITE_API int sqlite3_status64(
 12.1935    int op,
 12.1936    sqlite3_int64 *pCurrent,
 12.1937    sqlite3_int64 *pHighwater,
 12.1938 @@ -6970,7 +7231,7 @@
 12.1939  **
 12.1940  ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
 12.1941  */
 12.1942 -SQLITE_API int SQLITE_STDCALL sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
 12.1943 +SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
 12.1944  
 12.1945  /*
 12.1946  ** CAPI3REF: Status Parameters for database connections
 12.1947 @@ -7016,6 +7277,18 @@
 12.1948  ** memory used by all pager caches associated with the database connection.)^
 12.1949  ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
 12.1950  **
 12.1951 +** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]] 
 12.1952 +** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
 12.1953 +** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
 12.1954 +** pager cache is shared between two or more connections the bytes of heap
 12.1955 +** memory used by that pager cache is divided evenly between the attached
 12.1956 +** connections.)^  In other words, if none of the pager caches associated
 12.1957 +** with the database connection are shared, this request returns the same
 12.1958 +** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
 12.1959 +** shared, the value returned by this call will be smaller than that returned
 12.1960 +** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
 12.1961 +** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
 12.1962 +**
 12.1963  ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
 12.1964  ** <dd>This parameter returns the approximate number of bytes of heap
 12.1965  ** memory used to store the schema for all databases associated
 12.1966 @@ -7073,7 +7346,8 @@
 12.1967  #define SQLITE_DBSTATUS_CACHE_MISS           8
 12.1968  #define SQLITE_DBSTATUS_CACHE_WRITE          9
 12.1969  #define SQLITE_DBSTATUS_DEFERRED_FKS        10
 12.1970 -#define SQLITE_DBSTATUS_MAX                 10   /* Largest defined DBSTATUS */
 12.1971 +#define SQLITE_DBSTATUS_CACHE_USED_SHARED   11
 12.1972 +#define SQLITE_DBSTATUS_MAX                 11   /* Largest defined DBSTATUS */
 12.1973  
 12.1974  
 12.1975  /*
 12.1976 @@ -7100,7 +7374,7 @@
 12.1977  **
 12.1978  ** See also: [sqlite3_status()] and [sqlite3_db_status()].
 12.1979  */
 12.1980 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
 12.1981 +SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
 12.1982  
 12.1983  /*
 12.1984  ** CAPI3REF: Status Parameters for prepared statements
 12.1985 @@ -7569,16 +7843,16 @@
 12.1986  ** same time as another thread is invoking sqlite3_backup_step() it is
 12.1987  ** possible that they return invalid values.
 12.1988  */
 12.1989 -SQLITE_API sqlite3_backup *SQLITE_STDCALL sqlite3_backup_init(
 12.1990 +SQLITE_API sqlite3_backup *sqlite3_backup_init(
 12.1991    sqlite3 *pDest,                        /* Destination database handle */
 12.1992    const char *zDestName,                 /* Destination database name */
 12.1993    sqlite3 *pSource,                      /* Source database handle */
 12.1994    const char *zSourceName                /* Source database name */
 12.1995  );
 12.1996 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_step(sqlite3_backup *p, int nPage);
 12.1997 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_finish(sqlite3_backup *p);
 12.1998 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_remaining(sqlite3_backup *p);
 12.1999 -SQLITE_API int SQLITE_STDCALL sqlite3_backup_pagecount(sqlite3_backup *p);
 12.2000 +SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
 12.2001 +SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
 12.2002 +SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
 12.2003 +SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
 12.2004  
 12.2005  /*
 12.2006  ** CAPI3REF: Unlock Notification
 12.2007 @@ -7695,7 +7969,7 @@
 12.2008  ** the special "DROP TABLE/INDEX" case, the extended error code is just 
 12.2009  ** SQLITE_LOCKED.)^
 12.2010  */
 12.2011 -SQLITE_API int SQLITE_STDCALL sqlite3_unlock_notify(
 12.2012 +SQLITE_API int sqlite3_unlock_notify(
 12.2013    sqlite3 *pBlocked,                          /* Waiting connection */
 12.2014    void (*xNotify)(void **apArg, int nArg),    /* Callback function to invoke */
 12.2015    void *pNotifyArg                            /* Argument to pass to xNotify */
 12.2016 @@ -7710,8 +7984,8 @@
 12.2017  ** strings in a case-independent fashion, using the same definition of "case
 12.2018  ** independence" that SQLite uses internally when comparing identifiers.
 12.2019  */
 12.2020 -SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *, const char *);
 12.2021 -SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *, const char *, int);
 12.2022 +SQLITE_API int sqlite3_stricmp(const char *, const char *);
 12.2023 +SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
 12.2024  
 12.2025  /*
 12.2026  ** CAPI3REF: String Globbing
 12.2027 @@ -7728,7 +8002,7 @@
 12.2028  **
 12.2029  ** See also: [sqlite3_strlike()].
 12.2030  */
 12.2031 -SQLITE_API int SQLITE_STDCALL sqlite3_strglob(const char *zGlob, const char *zStr);
 12.2032 +SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
 12.2033  
 12.2034  /*
 12.2035  ** CAPI3REF: String LIKE Matching
 12.2036 @@ -7751,7 +8025,7 @@
 12.2037  **
 12.2038  ** See also: [sqlite3_strglob()].
 12.2039  */
 12.2040 -SQLITE_API int SQLITE_STDCALL sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
 12.2041 +SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
 12.2042  
 12.2043  /*
 12.2044  ** CAPI3REF: Error Logging Interface
 12.2045 @@ -7774,7 +8048,7 @@
 12.2046  ** a few hundred characters, it will be truncated to the length of the
 12.2047  ** buffer.
 12.2048  */
 12.2049 -SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...);
 12.2050 +SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
 12.2051  
 12.2052  /*
 12.2053  ** CAPI3REF: Write-Ahead Log Commit Hook
 12.2054 @@ -7810,7 +8084,7 @@
 12.2055  ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
 12.2056  ** overwrite any prior [sqlite3_wal_hook()] settings.
 12.2057  */
 12.2058 -SQLITE_API void *SQLITE_STDCALL sqlite3_wal_hook(
 12.2059 +SQLITE_API void *sqlite3_wal_hook(
 12.2060    sqlite3*, 
 12.2061    int(*)(void *,sqlite3*,const char*,int),
 12.2062    void*
 12.2063 @@ -7845,7 +8119,7 @@
 12.2064  ** is only necessary if the default setting is found to be suboptimal
 12.2065  ** for a particular application.
 12.2066  */
 12.2067 -SQLITE_API int SQLITE_STDCALL sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
 12.2068 +SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
 12.2069  
 12.2070  /*
 12.2071  ** CAPI3REF: Checkpoint a database
 12.2072 @@ -7867,7 +8141,7 @@
 12.2073  ** start a callback but which do not need the full power (and corresponding
 12.2074  ** complication) of [sqlite3_wal_checkpoint_v2()].
 12.2075  */
 12.2076 -SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
 12.2077 +SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
 12.2078  
 12.2079  /*
 12.2080  ** CAPI3REF: Checkpoint a database
 12.2081 @@ -7961,7 +8235,7 @@
 12.2082  ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
 12.2083  ** from SQL.
 12.2084  */
 12.2085 -SQLITE_API int SQLITE_STDCALL sqlite3_wal_checkpoint_v2(
 12.2086 +SQLITE_API int sqlite3_wal_checkpoint_v2(
 12.2087    sqlite3 *db,                    /* Database handle */
 12.2088    const char *zDb,                /* Name of attached database (or NULL) */
 12.2089    int eMode,                      /* SQLITE_CHECKPOINT_* value */
 12.2090 @@ -7997,7 +8271,7 @@
 12.2091  ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].)  Further options
 12.2092  ** may be added in the future.
 12.2093  */
 12.2094 -SQLITE_API int SQLITE_CDECL sqlite3_vtab_config(sqlite3*, int op, ...);
 12.2095 +SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
 12.2096  
 12.2097  /*
 12.2098  ** CAPI3REF: Virtual Table Configuration Options
 12.2099 @@ -8050,7 +8324,7 @@
 12.2100  ** of the SQL statement that triggered the call to the [xUpdate] method of the
 12.2101  ** [virtual table].
 12.2102  */
 12.2103 -SQLITE_API int SQLITE_STDCALL sqlite3_vtab_on_conflict(sqlite3 *);
 12.2104 +SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
 12.2105  
 12.2106  /*
 12.2107  ** CAPI3REF: Conflict resolution modes
 12.2108 @@ -8155,7 +8429,7 @@
 12.2109  **
 12.2110  ** See also: [sqlite3_stmt_scanstatus_reset()]
 12.2111  */
 12.2112 -SQLITE_API int SQLITE_STDCALL sqlite3_stmt_scanstatus(
 12.2113 +SQLITE_API int sqlite3_stmt_scanstatus(
 12.2114    sqlite3_stmt *pStmt,      /* Prepared statement for which info desired */
 12.2115    int idx,                  /* Index of loop to report on */
 12.2116    int iScanStatusOp,        /* Information desired.  SQLITE_SCANSTAT_* */
 12.2117 @@ -8171,7 +8445,7 @@
 12.2118  ** This API is only available if the library is built with pre-processor
 12.2119  ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
 12.2120  */
 12.2121 -SQLITE_API void SQLITE_STDCALL sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
 12.2122 +SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
 12.2123  
 12.2124  /*
 12.2125  ** CAPI3REF: Flush caches to disk mid-transaction
 12.2126 @@ -8203,7 +8477,7 @@
 12.2127  ** ^This function does not set the database handle error code or message
 12.2128  ** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.
 12.2129  */
 12.2130 -SQLITE_API int SQLITE_STDCALL sqlite3_db_cacheflush(sqlite3*);
 12.2131 +SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
 12.2132  
 12.2133  /*
 12.2134  ** CAPI3REF: The pre-update hook.
 12.2135 @@ -8213,7 +8487,7 @@
 12.2136  **
 12.2137  ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
 12.2138  ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
 12.2139 -** on a [rowid table].
 12.2140 +** on a database table.
 12.2141  ** ^At most one preupdate hook may be registered at a time on a single
 12.2142  ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
 12.2143  ** the previous setting.
 12.2144 @@ -8222,14 +8496,14 @@
 12.2145  ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
 12.2146  ** the first parameter to callbacks.
 12.2147  **
 12.2148 -** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate
 12.2149 -** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID]
 12.2150 -** tables.
 12.2151 +** ^The preupdate hook only fires for changes to real database tables; the
 12.2152 +** preupdate hook is not invoked for changes to [virtual tables] or to
 12.2153 +** system tables like sqlite_master or sqlite_stat1.
 12.2154  **
 12.2155  ** ^The second parameter to the preupdate callback is a pointer to
 12.2156  ** the [database connection] that registered the preupdate hook.
 12.2157  ** ^The third parameter to the preupdate callback is one of the constants
 12.2158 -** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to indentify the
 12.2159 +** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
 12.2160  ** kind of update operation that is about to occur.
 12.2161  ** ^(The fourth parameter to the preupdate callback is the name of the
 12.2162  ** database within the database connection that is being modified.  This
 12.2163 @@ -8238,12 +8512,16 @@
 12.2164  ** databases.)^
 12.2165  ** ^The fifth parameter to the preupdate callback is the name of the
 12.2166  ** table that is being modified.
 12.2167 -** ^The sixth parameter to the preupdate callback is the initial [rowid] of the
 12.2168 -** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is
 12.2169 -** undefined for SQLITE_INSERT changes.
 12.2170 -** ^The seventh parameter to the preupdate callback is the final [rowid] of
 12.2171 -** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is
 12.2172 -** undefined for SQLITE_DELETE changes.
 12.2173 +**
 12.2174 +** For an UPDATE or DELETE operation on a [rowid table], the sixth
 12.2175 +** parameter passed to the preupdate callback is the initial [rowid] of the 
 12.2176 +** row being modified or deleted. For an INSERT operation on a rowid table,
 12.2177 +** or any operation on a WITHOUT ROWID table, the value of the sixth 
 12.2178 +** parameter is undefined. For an INSERT or UPDATE on a rowid table the
 12.2179 +** seventh parameter is the final rowid value of the row being inserted
 12.2180 +** or updated. The value of the seventh parameter passed to the callback
 12.2181 +** function is not defined for operations on WITHOUT ROWID tables, or for
 12.2182 +** INSERT operations on rowid tables.
 12.2183  **
 12.2184  ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
 12.2185  ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
 12.2186 @@ -8283,7 +8561,8 @@
 12.2187  **
 12.2188  ** See also:  [sqlite3_update_hook()]
 12.2189  */
 12.2190 -SQLITE_API SQLITE_EXPERIMENTAL void *SQLITE_STDCALL sqlite3_preupdate_hook(
 12.2191 +#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
 12.2192 +SQLITE_API void *sqlite3_preupdate_hook(
 12.2193    sqlite3 *db,
 12.2194    void(*xPreUpdate)(
 12.2195      void *pCtx,                   /* Copy of third arg to preupdate_hook() */
 12.2196 @@ -8296,10 +8575,11 @@
 12.2197    ),
 12.2198    void*
 12.2199  );
 12.2200 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
 12.2201 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_count(sqlite3 *);
 12.2202 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_depth(sqlite3 *);
 12.2203 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
 12.2204 +SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
 12.2205 +SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
 12.2206 +SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
 12.2207 +SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
 12.2208 +#endif
 12.2209  
 12.2210  /*
 12.2211  ** CAPI3REF: Low-level system error code
 12.2212 @@ -8311,11 +8591,11 @@
 12.2213  ** called to get back the underlying "errno" that caused the problem, such
 12.2214  ** as ENOSPC, EAUTH, EISDIR, and so forth.  
 12.2215  */
 12.2216 -SQLITE_API int SQLITE_STDCALL sqlite3_system_errno(sqlite3*);
 12.2217 +SQLITE_API int sqlite3_system_errno(sqlite3*);
 12.2218  
 12.2219  /*
 12.2220  ** CAPI3REF: Database Snapshot
 12.2221 -** KEYWORDS: {snapshot}
 12.2222 +** KEYWORDS: {snapshot} {sqlite3_snapshot}
 12.2223  ** EXPERIMENTAL
 12.2224  **
 12.2225  ** An instance of the snapshot object records the state of a [WAL mode]
 12.2226 @@ -8339,7 +8619,9 @@
 12.2227  ** to an historical snapshot (if possible).  The destructor for 
 12.2228  ** sqlite3_snapshot objects is [sqlite3_snapshot_free()].
 12.2229  */
 12.2230 -typedef struct sqlite3_snapshot sqlite3_snapshot;
 12.2231 +typedef struct sqlite3_snapshot {
 12.2232 +  unsigned char hidden[48];
 12.2233 +} sqlite3_snapshot;
 12.2234  
 12.2235  /*
 12.2236  ** CAPI3REF: Record A Database Snapshot
 12.2237 @@ -8350,9 +8632,32 @@
 12.2238  ** schema S in database connection D.  ^On success, the
 12.2239  ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
 12.2240  ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
 12.2241 -** ^If schema S of [database connection] D is not a [WAL mode] database
 12.2242 -** that is in a read transaction, then [sqlite3_snapshot_get(D,S,P)]
 12.2243 -** leaves the *P value unchanged and returns an appropriate [error code].
 12.2244 +** If there is not already a read-transaction open on schema S when
 12.2245 +** this function is called, one is opened automatically. 
 12.2246 +**
 12.2247 +** The following must be true for this function to succeed. If any of
 12.2248 +** the following statements are false when sqlite3_snapshot_get() is
 12.2249 +** called, SQLITE_ERROR is returned. The final value of *P is undefined
 12.2250 +** in this case. 
 12.2251 +**
 12.2252 +** <ul>
 12.2253 +**   <li> The database handle must be in [autocommit mode].
 12.2254 +**
 12.2255 +**   <li> Schema S of [database connection] D must be a [WAL mode] database.
 12.2256 +**
 12.2257 +**   <li> There must not be a write transaction open on schema S of database
 12.2258 +**        connection D.
 12.2259 +**
 12.2260 +**   <li> One or more transactions must have been written to the current wal
 12.2261 +**        file since it was created on disk (by any connection). This means
 12.2262 +**        that a snapshot cannot be taken on a wal mode database with no wal 
 12.2263 +**        file immediately after it is first opened. At least one transaction
 12.2264 +**        must be written to it first.
 12.2265 +** </ul>
 12.2266 +**
 12.2267 +** This function may also return SQLITE_NOMEM.  If it is called with the
 12.2268 +** database handle in autocommit mode but fails for some other reason, 
 12.2269 +** whether or not a read transaction is opened on schema S is undefined.
 12.2270  **
 12.2271  ** The [sqlite3_snapshot] object returned from a successful call to
 12.2272  ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
 12.2273 @@ -8361,7 +8666,7 @@
 12.2274  ** The [sqlite3_snapshot_get()] interface is only available when the
 12.2275  ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
 12.2276  */
 12.2277 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_get(
 12.2278 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
 12.2279    sqlite3 *db,
 12.2280    const char *zSchema,
 12.2281    sqlite3_snapshot **ppSnapshot
 12.2282 @@ -8399,7 +8704,7 @@
 12.2283  ** The [sqlite3_snapshot_open()] interface is only available when the
 12.2284  ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
 12.2285  */
 12.2286 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_open(
 12.2287 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
 12.2288    sqlite3 *db,
 12.2289    const char *zSchema,
 12.2290    sqlite3_snapshot *pSnapshot
 12.2291 @@ -8416,7 +8721,7 @@
 12.2292  ** The [sqlite3_snapshot_free()] interface is only available when the
 12.2293  ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
 12.2294  */
 12.2295 -SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
 12.2296 +SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
 12.2297  
 12.2298  /*
 12.2299  ** CAPI3REF: Compare the ages of two snapshot handles.
 12.2300 @@ -8440,12 +8745,34 @@
 12.2301  ** snapshot than P2, zero if the two handles refer to the same database
 12.2302  ** snapshot, and a positive value if P1 is a newer snapshot than P2.
 12.2303  */
 12.2304 -SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
 12.2305 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
 12.2306    sqlite3_snapshot *p1,
 12.2307    sqlite3_snapshot *p2
 12.2308  );
 12.2309  
 12.2310  /*
 12.2311 +** CAPI3REF: Recover snapshots from a wal file
 12.2312 +** EXPERIMENTAL
 12.2313 +**
 12.2314 +** If all connections disconnect from a database file but do not perform
 12.2315 +** a checkpoint, the existing wal file is opened along with the database
 12.2316 +** file the next time the database is opened. At this point it is only
 12.2317 +** possible to successfully call sqlite3_snapshot_open() to open the most
 12.2318 +** recent snapshot of the database (the one at the head of the wal file),
 12.2319 +** even though the wal file may contain other valid snapshots for which
 12.2320 +** clients have sqlite3_snapshot handles.
 12.2321 +**
 12.2322 +** This function attempts to scan the wal file associated with database zDb
 12.2323 +** of database handle db and make all valid snapshots available to
 12.2324 +** sqlite3_snapshot_open(). It is an error if there is already a read
 12.2325 +** transaction open on the database, or if the database is not a wal mode
 12.2326 +** database.
 12.2327 +**
 12.2328 +** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
 12.2329 +*/
 12.2330 +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
 12.2331 +
 12.2332 +/*
 12.2333  ** Undo the hack that converts floating point types to integer for
 12.2334  ** builds on processors without floating point support.
 12.2335  */
 12.2336 @@ -8456,7 +8783,7 @@
 12.2337  #if 0
 12.2338  }  /* End of the 'extern "C"' block */
 12.2339  #endif
 12.2340 -#endif /* _SQLITE3_H_ */
 12.2341 +#endif /* SQLITE3_H */
 12.2342  
 12.2343  /******** Begin file sqlite3rtree.h *********/
 12.2344  /*
 12.2345 @@ -8498,7 +8825,7 @@
 12.2346  **
 12.2347  **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
 12.2348  */
 12.2349 -SQLITE_API int SQLITE_STDCALL sqlite3_rtree_geometry_callback(
 12.2350 +SQLITE_API int sqlite3_rtree_geometry_callback(
 12.2351    sqlite3 *db,
 12.2352    const char *zGeom,
 12.2353    int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
 12.2354 @@ -8524,7 +8851,7 @@
 12.2355  **
 12.2356  **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
 12.2357  */
 12.2358 -SQLITE_API int SQLITE_STDCALL sqlite3_rtree_query_callback(
 12.2359 +SQLITE_API int sqlite3_rtree_query_callback(
 12.2360    sqlite3 *db,
 12.2361    const char *zQueryFunc,
 12.2362    int (*xQueryFunc)(sqlite3_rtree_query_info*),
 12.2363 @@ -8630,7 +8957,7 @@
 12.2364  ** attached database. It is not an error if database zDb is not attached
 12.2365  ** to the database when the session object is created.
 12.2366  */
 12.2367 -int sqlite3session_create(
 12.2368 +SQLITE_API int sqlite3session_create(
 12.2369    sqlite3 *db,                    /* Database handle */
 12.2370    const char *zDb,                /* Name of db (e.g. "main") */
 12.2371    sqlite3_session **ppSession     /* OUT: New session object */
 12.2372 @@ -8648,7 +8975,7 @@
 12.2373  ** are attached is closed. Refer to the documentation for 
 12.2374  ** [sqlite3session_create()] for details.
 12.2375  */
 12.2376 -void sqlite3session_delete(sqlite3_session *pSession);
 12.2377 +SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
 12.2378  
 12.2379  
 12.2380  /*
 12.2381 @@ -8668,7 +8995,7 @@
 12.2382  ** The return value indicates the final state of the session object: 0 if 
 12.2383  ** the session is disabled, or 1 if it is enabled.
 12.2384  */
 12.2385 -int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
 12.2386 +SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
 12.2387  
 12.2388  /*
 12.2389  ** CAPI3REF: Set Or Clear the Indirect Change Flag
 12.2390 @@ -8697,7 +9024,7 @@
 12.2391  ** The return value indicates the final state of the indirect flag: 0 if 
 12.2392  ** it is clear, or 1 if it is set.
 12.2393  */
 12.2394 -int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
 12.2395 +SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
 12.2396  
 12.2397  /*
 12.2398  ** CAPI3REF: Attach A Table To A Session Object
 12.2399 @@ -8727,7 +9054,7 @@
 12.2400  ** SQLITE_OK is returned if the call completes without error. Or, if an error 
 12.2401  ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
 12.2402  */
 12.2403 -int sqlite3session_attach(
 12.2404 +SQLITE_API int sqlite3session_attach(
 12.2405    sqlite3_session *pSession,      /* Session object */
 12.2406    const char *zTab                /* Table name */
 12.2407  );
 12.2408 @@ -8736,12 +9063,12 @@
 12.2409  ** CAPI3REF: Set a table filter on a Session Object.
 12.2410  **
 12.2411  ** The second argument (xFilter) is the "filter callback". For changes to rows 
 12.2412 -** in tables that are not attached to the Session oject, the filter is called
 12.2413 +** in tables that are not attached to the Session object, the filter is called
 12.2414  ** to determine whether changes to the table's rows should be tracked or not. 
 12.2415  ** If xFilter returns 0, changes is not tracked. Note that once a table is 
 12.2416  ** attached, xFilter will not be called again.
 12.2417  */
 12.2418 -void sqlite3session_table_filter(
 12.2419 +SQLITE_API void sqlite3session_table_filter(
 12.2420    sqlite3_session *pSession,      /* Session object */
 12.2421    int(*xFilter)(
 12.2422      void *pCtx,                   /* Copy of third arg to _filter_table() */
 12.2423 @@ -8854,7 +9181,7 @@
 12.2424  ** another field of the same row is updated while the session is enabled, the
 12.2425  ** resulting changeset will contain an UPDATE change that updates both fields.
 12.2426  */
 12.2427 -int sqlite3session_changeset(
 12.2428 +SQLITE_API int sqlite3session_changeset(
 12.2429    sqlite3_session *pSession,      /* Session object */
 12.2430    int *pnChangeset,               /* OUT: Size of buffer at *ppChangeset */
 12.2431    void **ppChangeset              /* OUT: Buffer containing changeset */
 12.2432 @@ -8898,7 +9225,8 @@
 12.2433  **     the from-table, a DELETE record is added to the session object.
 12.2434  **
 12.2435  **   <li> For each row (primary key) that exists in both tables, but features 
 12.2436 -**     different in each, an UPDATE record is added to the session.
 12.2437 +**     different non-PK values in each, an UPDATE record is added to the
 12.2438 +**     session.  
 12.2439  ** </ul>
 12.2440  **
 12.2441  ** To clarify, if this function is called and then a changeset constructed
 12.2442 @@ -8915,7 +9243,7 @@
 12.2443  ** message. It is the responsibility of the caller to free this buffer using
 12.2444  ** sqlite3_free().
 12.2445  */
 12.2446 -int sqlite3session_diff(
 12.2447 +SQLITE_API int sqlite3session_diff(
 12.2448    sqlite3_session *pSession,
 12.2449    const char *zFromDb,
 12.2450    const char *zTbl,
 12.2451 @@ -8951,7 +9279,7 @@
 12.2452  ** a single table are grouped together, tables appear in the order in which
 12.2453  ** they were attached to the session object).
 12.2454  */
 12.2455 -int sqlite3session_patchset(
 12.2456 +SQLITE_API int sqlite3session_patchset(
 12.2457    sqlite3_session *pSession,      /* Session object */
 12.2458    int *pnPatchset,                /* OUT: Size of buffer at *ppChangeset */
 12.2459    void **ppPatchset               /* OUT: Buffer containing changeset */
 12.2460 @@ -8972,7 +9300,7 @@
 12.2461  ** guaranteed that a call to sqlite3session_changeset() will return a 
 12.2462  ** changeset containing zero changes.
 12.2463  */
 12.2464 -int sqlite3session_isempty(sqlite3_session *pSession);
 12.2465 +SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
 12.2466  
 12.2467  /*
 12.2468  ** CAPI3REF: Create An Iterator To Traverse A Changeset 
 12.2469 @@ -9002,12 +9330,12 @@
 12.2470  ** [sqlite3changeset_invert()] functions, all changes within the changeset 
 12.2471  ** that apply to a single table are grouped together. This means that when 
 12.2472  ** an application iterates through a changeset using an iterator created by 
 12.2473 -** this function, all changes that relate to a single table are visted 
 12.2474 +** this function, all changes that relate to a single table are visited 
 12.2475  ** consecutively. There is no chance that the iterator will visit a change 
 12.2476  ** the applies to table X, then one for table Y, and then later on visit 
 12.2477  ** another change for table X.
 12.2478  */
 12.2479 -int sqlite3changeset_start(
 12.2480 +SQLITE_API int sqlite3changeset_start(
 12.2481    sqlite3_changeset_iter **pp,    /* OUT: New changeset iterator handle */
 12.2482    int nChangeset,                 /* Size of changeset blob in bytes */
 12.2483    void *pChangeset                /* Pointer to blob containing changeset */
 12.2484 @@ -9036,7 +9364,7 @@
 12.2485  ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or 
 12.2486  ** SQLITE_NOMEM.
 12.2487  */
 12.2488 -int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
 12.2489 +SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
 12.2490  
 12.2491  /*
 12.2492  ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
 12.2493 @@ -9064,7 +9392,7 @@
 12.2494  ** SQLite error code is returned. The values of the output variables may not
 12.2495  ** be trusted in this case.
 12.2496  */
 12.2497 -int sqlite3changeset_op(
 12.2498 +SQLITE_API int sqlite3changeset_op(
 12.2499    sqlite3_changeset_iter *pIter,  /* Iterator object */
 12.2500    const char **pzTab,             /* OUT: Pointer to table name */
 12.2501    int *pnCol,                     /* OUT: Number of columns in table */
 12.2502 @@ -9089,7 +9417,7 @@
 12.2503  ** 0x01 if the corresponding column is part of the tables primary key, or
 12.2504  ** 0x00 if it is not.
 12.2505  **
 12.2506 -** If argumet pnCol is not NULL, then *pnCol is set to the number of columns
 12.2507 +** If argument pnCol is not NULL, then *pnCol is set to the number of columns
 12.2508  ** in the table.
 12.2509  **
 12.2510  ** If this function is called when the iterator does not point to a valid
 12.2511 @@ -9097,7 +9425,7 @@
 12.2512  ** SQLITE_OK is returned and the output variables populated as described
 12.2513  ** above.
 12.2514  */
 12.2515 -int sqlite3changeset_pk(
 12.2516 +SQLITE_API int sqlite3changeset_pk(
 12.2517    sqlite3_changeset_iter *pIter,  /* Iterator object */
 12.2518    unsigned char **pabPK,          /* OUT: Array of boolean - true for PK cols */
 12.2519    int *pnCol                      /* OUT: Number of entries in output array */
 12.2520 @@ -9127,7 +9455,7 @@
 12.2521  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
 12.2522  ** is returned and *ppValue is set to NULL.
 12.2523  */
 12.2524 -int sqlite3changeset_old(
 12.2525 +SQLITE_API int sqlite3changeset_old(
 12.2526    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
 12.2527    int iVal,                       /* Column number */
 12.2528    sqlite3_value **ppValue         /* OUT: Old value (or NULL pointer) */
 12.2529 @@ -9160,7 +9488,7 @@
 12.2530  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
 12.2531  ** is returned and *ppValue is set to NULL.
 12.2532  */
 12.2533 -int sqlite3changeset_new(
 12.2534 +SQLITE_API int sqlite3changeset_new(
 12.2535    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
 12.2536    int iVal,                       /* Column number */
 12.2537    sqlite3_value **ppValue         /* OUT: New value (or NULL pointer) */
 12.2538 @@ -9187,7 +9515,7 @@
 12.2539  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
 12.2540  ** is returned and *ppValue is set to NULL.
 12.2541  */
 12.2542 -int sqlite3changeset_conflict(
 12.2543 +SQLITE_API int sqlite3changeset_conflict(
 12.2544    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
 12.2545    int iVal,                       /* Column number */
 12.2546    sqlite3_value **ppValue         /* OUT: Value from conflicting row */
 12.2547 @@ -9203,7 +9531,7 @@
 12.2548  **
 12.2549  ** In all other cases this function returns SQLITE_MISUSE.
 12.2550  */
 12.2551 -int sqlite3changeset_fk_conflicts(
 12.2552 +SQLITE_API int sqlite3changeset_fk_conflicts(
 12.2553    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
 12.2554    int *pnOut                      /* OUT: Number of FK violations */
 12.2555  );
 12.2556 @@ -9236,7 +9564,7 @@
 12.2557  **     // An error has occurred 
 12.2558  **   }
 12.2559  */
 12.2560 -int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
 12.2561 +SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
 12.2562  
 12.2563  /*
 12.2564  ** CAPI3REF: Invert A Changeset
 12.2565 @@ -9266,7 +9594,7 @@
 12.2566  ** WARNING/TODO: This function currently assumes that the input is a valid
 12.2567  ** changeset. If it is not, the results are undefined.
 12.2568  */
 12.2569 -int sqlite3changeset_invert(
 12.2570 +SQLITE_API int sqlite3changeset_invert(
 12.2571    int nIn, const void *pIn,       /* Input changeset */
 12.2572    int *pnOut, void **ppOut        /* OUT: Inverse of input */
 12.2573  );
 12.2574 @@ -9295,7 +9623,7 @@
 12.2575  **
 12.2576  ** Refer to the sqlite3_changegroup documentation below for details.
 12.2577  */
 12.2578 -int sqlite3changeset_concat(
 12.2579 +SQLITE_API int sqlite3changeset_concat(
 12.2580    int nA,                         /* Number of bytes in buffer pA */
 12.2581    void *pA,                       /* Pointer to buffer containing changeset A */
 12.2582    int nB,                         /* Number of bytes in buffer pB */
 12.2583 @@ -9306,12 +9634,12 @@
 12.2584  
 12.2585  
 12.2586  /*
 12.2587 -** Changegroup handle.
 12.2588 +** CAPI3REF: Changegroup Handle
 12.2589  */
 12.2590  typedef struct sqlite3_changegroup sqlite3_changegroup;
 12.2591  
 12.2592  /*
 12.2593 -** CAPI3REF: Combine two or more changesets into a single changeset.
 12.2594 +** CAPI3REF: Create A New Changegroup Object
 12.2595  **
 12.2596  ** An sqlite3_changegroup object is used to combine two or more changesets
 12.2597  ** (or patchsets) into a single changeset (or patchset). A single changegroup
 12.2598 @@ -9345,9 +9673,11 @@
 12.2599  ** sqlite3changegroup_output() functions, also available are the streaming
 12.2600  ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
 12.2601  */
 12.2602 -int sqlite3changegroup_new(sqlite3_changegroup **pp);
 12.2603 -
 12.2604 -/*
 12.2605 +SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
 12.2606 +
 12.2607 +/*
 12.2608 +** CAPI3REF: Add A Changeset To A Changegroup
 12.2609 +**
 12.2610  ** Add all changes within the changeset (or patchset) in buffer pData (size
 12.2611  ** nData bytes) to the changegroup. 
 12.2612  **
 12.2613 @@ -9362,7 +9692,7 @@
 12.2614  ** apply to the same row as a change already present in the changegroup if
 12.2615  ** the two rows have the same primary key.
 12.2616  **
 12.2617 -** Changes to rows that that do not already appear in the changegroup are
 12.2618 +** Changes to rows that do not already appear in the changegroup are
 12.2619  ** simply copied into it. Or, if both the new changeset and the changegroup
 12.2620  ** contain changes that apply to a single row, the final contents of the
 12.2621  ** changegroup depends on the type of each change, as follows:
 12.2622 @@ -9420,9 +9750,11 @@
 12.2623  **
 12.2624  ** If no error occurs, SQLITE_OK is returned.
 12.2625  */
 12.2626 -int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
 12.2627 -
 12.2628 -/*
 12.2629 +SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
 12.2630 +
 12.2631 +/*
 12.2632 +** CAPI3REF: Obtain A Composite Changeset From A Changegroup
 12.2633 +**
 12.2634  ** Obtain a buffer containing a changeset (or patchset) representing the
 12.2635  ** current contents of the changegroup. If the inputs to the changegroup
 12.2636  ** were themselves changesets, the output is a changeset. Or, if the
 12.2637 @@ -9444,16 +9776,16 @@
 12.2638  ** responsibility of the caller to eventually free the buffer using a
 12.2639  ** call to sqlite3_free().
 12.2640  */
 12.2641 -int sqlite3changegroup_output(
 12.2642 +SQLITE_API int sqlite3changegroup_output(
 12.2643    sqlite3_changegroup*,
 12.2644    int *pnData,                    /* OUT: Size of output buffer in bytes */
 12.2645    void **ppData                   /* OUT: Pointer to output buffer */
 12.2646  );
 12.2647  
 12.2648  /*
 12.2649 -** Delete a changegroup object.
 12.2650 -*/
 12.2651 -void sqlite3changegroup_delete(sqlite3_changegroup*);
 12.2652 +** CAPI3REF: Delete A Changegroup Object
 12.2653 +*/
 12.2654 +SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
 12.2655  
 12.2656  /*
 12.2657  ** CAPI3REF: Apply A Changeset To A Database
 12.2658 @@ -9479,7 +9811,7 @@
 12.2659  ** <ul>
 12.2660  **   <li> The table has the same name as the name recorded in the 
 12.2661  **        changeset, and
 12.2662 -**   <li> The table has the same number of columns as recorded in the 
 12.2663 +**   <li> The table has at least as many columns as recorded in the 
 12.2664  **        changeset, and
 12.2665  **   <li> The table has primary key columns in the same position as 
 12.2666  **        recorded in the changeset.
 12.2667 @@ -9524,7 +9856,11 @@
 12.2668  **   If a row with matching primary key values is found, but one or more of
 12.2669  **   the non-primary key fields contains a value different from the original
 12.2670  **   row value stored in the changeset, the conflict-handler function is
 12.2671 -**   invoked with [SQLITE_CHANGESET_DATA] as the second argument.
 12.2672 +**   invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
 12.2673 +**   database table has more columns than are recorded in the changeset,
 12.2674 +**   only the values of those non-primary key fields are compared against
 12.2675 +**   the current database contents - any trailing database table columns
 12.2676 +**   are ignored.
 12.2677  **
 12.2678  **   If no row with matching primary key values is found in the database,
 12.2679  **   the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
 12.2680 @@ -9539,7 +9875,9 @@
 12.2681  **
 12.2682  ** <dt>INSERT Changes<dd>
 12.2683  **   For each INSERT change, an attempt is made to insert the new row into
 12.2684 -**   the database.
 12.2685 +**   the database. If the changeset row contains fewer fields than the
 12.2686 +**   database table, the trailing fields are populated with their default
 12.2687 +**   values.
 12.2688  **
 12.2689  **   If the attempt to insert the row fails because the database already 
 12.2690  **   contains a row with the same primary key values, the conflict handler
 12.2691 @@ -9557,13 +9895,13 @@
 12.2692  **   For each UPDATE change, this function checks if the target database 
 12.2693  **   contains a row with the same primary key value (or values) as the 
 12.2694  **   original row values stored in the changeset. If it does, and the values 
 12.2695 -**   stored in all non-primary key columns also match the values stored in 
 12.2696 -**   the changeset the row is updated within the target database.
 12.2697 +**   stored in all modified non-primary key columns also match the values
 12.2698 +**   stored in the changeset the row is updated within the target database.
 12.2699  **
 12.2700  **   If a row with matching primary key values is found, but one or more of
 12.2701 -**   the non-primary key fields contains a value different from an original
 12.2702 -**   row value stored in the changeset, the conflict-handler function is
 12.2703 -**   invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
 12.2704 +**   the modified non-primary key fields contains a value different from an
 12.2705 +**   original row value stored in the changeset, the conflict-handler function
 12.2706 +**   is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
 12.2707  **   UPDATE changes only contain values for non-primary key fields that are
 12.2708  **   to be modified, only those fields need to match the original values to
 12.2709  **   avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
 12.2710 @@ -9591,7 +9929,7 @@
 12.2711  ** rolled back, restoring the target database to its original state, and an 
 12.2712  ** SQLite error code returned.
 12.2713  */
 12.2714 -int sqlite3changeset_apply(
 12.2715 +SQLITE_API int sqlite3changeset_apply(
 12.2716    sqlite3 *db,                    /* Apply change to "main" db of this handle */
 12.2717    int nChangeset,                 /* Size of changeset in bytes */
 12.2718    void *pChangeset,               /* Changeset blob */
 12.2719 @@ -9792,7 +10130,7 @@
 12.2720  ** parameter set to a value less than or equal to zero. Other than this,
 12.2721  ** no guarantees are made as to the size of the chunks of data returned.
 12.2722  */
 12.2723 -int sqlite3changeset_apply_strm(
 12.2724 +SQLITE_API int sqlite3changeset_apply_strm(
 12.2725    sqlite3 *db,                    /* Apply change to "main" db of this handle */
 12.2726    int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
 12.2727    void *pIn,                                          /* First arg for xInput */
 12.2728 @@ -9807,7 +10145,7 @@
 12.2729    ),
 12.2730    void *pCtx                      /* First argument passed to xConflict */
 12.2731  );
 12.2732 -int sqlite3changeset_concat_strm(
 12.2733 +SQLITE_API int sqlite3changeset_concat_strm(
 12.2734    int (*xInputA)(void *pIn, void *pData, int *pnData),
 12.2735    void *pInA,
 12.2736    int (*xInputB)(void *pIn, void *pData, int *pnData),
 12.2737 @@ -9815,32 +10153,32 @@
 12.2738    int (*xOutput)(void *pOut, const void *pData, int nData),
 12.2739    void *pOut
 12.2740  );
 12.2741 -int sqlite3changeset_invert_strm(
 12.2742 +SQLITE_API int sqlite3changeset_invert_strm(
 12.2743    int (*xInput)(void *pIn, void *pData, int *pnData),
 12.2744    void *pIn,
 12.2745    int (*xOutput)(void *pOut, const void *pData, int nData),
 12.2746    void *pOut
 12.2747  );
 12.2748 -int sqlite3changeset_start_strm(
 12.2749 +SQLITE_API int sqlite3changeset_start_strm(
 12.2750    sqlite3_changeset_iter **pp,
 12.2751    int (*xInput)(void *pIn, void *pData, int *pnData),
 12.2752    void *pIn
 12.2753  );
 12.2754 -int sqlite3session_changeset_strm(
 12.2755 +SQLITE_API int sqlite3session_changeset_strm(
 12.2756    sqlite3_session *pSession,
 12.2757    int (*xOutput)(void *pOut, const void *pData, int nData),
 12.2758    void *pOut
 12.2759  );
 12.2760 -int sqlite3session_patchset_strm(
 12.2761 +SQLITE_API int sqlite3session_patchset_strm(
 12.2762    sqlite3_session *pSession,
 12.2763    int (*xOutput)(void *pOut, const void *pData, int nData),
 12.2764    void *pOut
 12.2765  );
 12.2766 -int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
 12.2767 +SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*, 
 12.2768      int (*xInput)(void *pIn, void *pData, int *pnData),
 12.2769      void *pIn
 12.2770  );
 12.2771 -int sqlite3changegroup_output_strm(sqlite3_changegroup*,
 12.2772 +SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
 12.2773      int (*xOutput)(void *pOut, const void *pData, int nData), 
 12.2774      void *pOut
 12.2775  );
 12.2776 @@ -10176,7 +10514,7 @@
 12.2777  ** behaviour. The structure methods are expected to function as follows:
 12.2778  **
 12.2779  ** xCreate:
 12.2780 -**   This function is used to allocate and inititalize a tokenizer instance.
 12.2781 +**   This function is used to allocate and initialize a tokenizer instance.
 12.2782  **   A tokenizer instance is required to actually tokenize text.
 12.2783  **
 12.2784  **   The first argument passed to this function is a copy of the (void*)
 12.2785 @@ -10436,7 +10774,6 @@
 12.2786  
 12.2787  #endif /* _FTS5_H */
 12.2788  
 12.2789 -
 12.2790  /******** End of fts5.h *********/
 12.2791  
 12.2792  /************** End of sqlite3.h *********************************************/
 12.2793 @@ -10541,7 +10878,7 @@
 12.2794  ** Not currently enforced.
 12.2795  */
 12.2796  #ifndef SQLITE_MAX_VDBE_OP
 12.2797 -# define SQLITE_MAX_VDBE_OP 25000
 12.2798 +# define SQLITE_MAX_VDBE_OP 250000000
 12.2799  #endif
 12.2800  
 12.2801  /*
 12.2802 @@ -10734,11 +11071,12 @@
 12.2803  ** the SQLITE_DISABLE_INTRINSIC define.
 12.2804  */
 12.2805  #if !defined(SQLITE_DISABLE_INTRINSIC)
 12.2806 -#  if defined(_MSC_VER) && _MSC_VER>=1300
 12.2807 +#  if defined(_MSC_VER) && _MSC_VER>=1400
 12.2808  #    if !defined(_WIN32_WCE)
 12.2809  #      include <intrin.h>
 12.2810  #      pragma intrinsic(_byteswap_ushort)
 12.2811  #      pragma intrinsic(_byteswap_ulong)
 12.2812 +#      pragma intrinsic(_byteswap_uint64)
 12.2813  #      pragma intrinsic(_ReadWriteBarrier)
 12.2814  #    else
 12.2815  #      include <cmnintrin.h>
 12.2816 @@ -11011,8 +11349,8 @@
 12.2817  ** This is the header file for the generic hash-table implementation
 12.2818  ** used in SQLite.
 12.2819  */
 12.2820 -#ifndef _SQLITE_HASH_H_
 12.2821 -#define _SQLITE_HASH_H_
 12.2822 +#ifndef SQLITE_HASH_H
 12.2823 +#define SQLITE_HASH_H
 12.2824  
 12.2825  /* Forward declarations of structures. */
 12.2826  typedef struct Hash Hash;
 12.2827 @@ -11092,7 +11430,7 @@
 12.2828  */
 12.2829  /* #define sqliteHashCount(H)  ((H)->count) // NOT USED */
 12.2830  
 12.2831 -#endif /* _SQLITE_HASH_H_ */
 12.2832 +#endif /* SQLITE_HASH_H */
 12.2833  
 12.2834  /************** End of hash.h ************************************************/
 12.2835  /************** Continuing where we left off in sqliteInt.h ******************/
 12.2836 @@ -11124,76 +11462,76 @@
 12.2837  #define TK_AS                              24
 12.2838  #define TK_WITHOUT                         25
 12.2839  #define TK_COMMA                           26
 12.2840 -#define TK_OR                              27
 12.2841 -#define TK_AND                             28
 12.2842 -#define TK_IS                              29
 12.2843 -#define TK_MATCH                           30
 12.2844 -#define TK_LIKE_KW                         31
 12.2845 -#define TK_BETWEEN                         32
 12.2846 -#define TK_IN                              33
 12.2847 -#define TK_ISNULL                          34
 12.2848 -#define TK_NOTNULL                         35
 12.2849 -#define TK_NE                              36
 12.2850 -#define TK_EQ                              37
 12.2851 -#define TK_GT                              38
 12.2852 -#define TK_LE                              39
 12.2853 -#define TK_LT                              40
 12.2854 -#define TK_GE                              41
 12.2855 -#define TK_ESCAPE                          42
 12.2856 -#define TK_BITAND                          43
 12.2857 -#define TK_BITOR                           44
 12.2858 -#define TK_LSHIFT                          45
 12.2859 -#define TK_RSHIFT                          46
 12.2860 -#define TK_PLUS                            47
 12.2861 -#define TK_MINUS                           48
 12.2862 -#define TK_STAR                            49
 12.2863 -#define TK_SLASH                           50
 12.2864 -#define TK_REM                             51
 12.2865 -#define TK_CONCAT                          52
 12.2866 -#define TK_COLLATE                         53
 12.2867 -#define TK_BITNOT                          54
 12.2868 -#define TK_ID                              55
 12.2869 -#define TK_INDEXED                         56
 12.2870 -#define TK_ABORT                           57
 12.2871 -#define TK_ACTION                          58
 12.2872 -#define TK_AFTER                           59
 12.2873 -#define TK_ANALYZE                         60
 12.2874 -#define TK_ASC                             61
 12.2875 -#define TK_ATTACH                          62
 12.2876 -#define TK_BEFORE                          63
 12.2877 -#define TK_BY                              64
 12.2878 -#define TK_CASCADE                         65
 12.2879 -#define TK_CAST                            66
 12.2880 -#define TK_COLUMNKW                        67
 12.2881 -#define TK_CONFLICT                        68
 12.2882 -#define TK_DATABASE                        69
 12.2883 -#define TK_DESC                            70
 12.2884 -#define TK_DETACH                          71
 12.2885 -#define TK_EACH                            72
 12.2886 -#define TK_FAIL                            73
 12.2887 -#define TK_FOR                             74
 12.2888 -#define TK_IGNORE                          75
 12.2889 -#define TK_INITIALLY                       76
 12.2890 -#define TK_INSTEAD                         77
 12.2891 -#define TK_NO                              78
 12.2892 -#define TK_KEY                             79
 12.2893 -#define TK_OF                              80
 12.2894 -#define TK_OFFSET                          81
 12.2895 -#define TK_PRAGMA                          82
 12.2896 -#define TK_RAISE                           83
 12.2897 -#define TK_RECURSIVE                       84
 12.2898 -#define TK_REPLACE                         85
 12.2899 -#define TK_RESTRICT                        86
 12.2900 -#define TK_ROW                             87
 12.2901 -#define TK_TRIGGER                         88
 12.2902 -#define TK_VACUUM                          89
 12.2903 -#define TK_VIEW                            90
 12.2904 -#define TK_VIRTUAL                         91
 12.2905 -#define TK_WITH                            92
 12.2906 -#define TK_REINDEX                         93
 12.2907 -#define TK_RENAME                          94
 12.2908 -#define TK_CTIME_KW                        95
 12.2909 -#define TK_ANY                             96
 12.2910 +#define TK_ID                              27
 12.2911 +#define TK_ABORT                           28
 12.2912 +#define TK_ACTION                          29
 12.2913 +#define TK_AFTER                           30
 12.2914 +#define TK_ANALYZE                         31
 12.2915 +#define TK_ASC                             32
 12.2916 +#define TK_ATTACH                          33
 12.2917 +#define TK_BEFORE                          34
 12.2918 +#define TK_BY                              35
 12.2919 +#define TK_CASCADE                         36
 12.2920 +#define TK_CAST                            37
 12.2921 +#define TK_COLUMNKW                        38
 12.2922 +#define TK_CONFLICT                        39
 12.2923 +#define TK_DATABASE                        40
 12.2924 +#define TK_DESC                            41
 12.2925 +#define TK_DETACH                          42
 12.2926 +#define TK_EACH                            43
 12.2927 +#define TK_FAIL                            44
 12.2928 +#define TK_FOR                             45
 12.2929 +#define TK_IGNORE                          46
 12.2930 +#define TK_INITIALLY                       47
 12.2931 +#define TK_INSTEAD                         48
 12.2932 +#define TK_LIKE_KW                         49
 12.2933 +#define TK_MATCH                           50
 12.2934 +#define TK_NO                              51
 12.2935 +#define TK_KEY                             52
 12.2936 +#define TK_OF                              53
 12.2937 +#define TK_OFFSET                          54
 12.2938 +#define TK_PRAGMA                          55
 12.2939 +#define TK_RAISE                           56
 12.2940 +#define TK_RECURSIVE                       57
 12.2941 +#define TK_REPLACE                         58
 12.2942 +#define TK_RESTRICT                        59
 12.2943 +#define TK_ROW                             60
 12.2944 +#define TK_TRIGGER                         61
 12.2945 +#define TK_VACUUM                          62
 12.2946 +#define TK_VIEW                            63
 12.2947 +#define TK_VIRTUAL                         64
 12.2948 +#define TK_WITH                            65
 12.2949 +#define TK_REINDEX                         66
 12.2950 +#define TK_RENAME                          67
 12.2951 +#define TK_CTIME_KW                        68
 12.2952 +#define TK_ANY                             69
 12.2953 +#define TK_OR                              70
 12.2954 +#define TK_AND                             71
 12.2955 +#define TK_IS                              72
 12.2956 +#define TK_BETWEEN                         73
 12.2957 +#define TK_IN                              74
 12.2958 +#define TK_ISNULL                          75
 12.2959 +#define TK_NOTNULL                         76
 12.2960 +#define TK_NE                              77
 12.2961 +#define TK_EQ                              78
 12.2962 +#define TK_GT                              79
 12.2963 +#define TK_LE                              80
 12.2964 +#define TK_LT                              81
 12.2965 +#define TK_GE                              82
 12.2966 +#define TK_ESCAPE                          83
 12.2967 +#define TK_BITAND                          84
 12.2968 +#define TK_BITOR                           85
 12.2969 +#define TK_LSHIFT                          86
 12.2970 +#define TK_RSHIFT                          87
 12.2971 +#define TK_PLUS                            88
 12.2972 +#define TK_MINUS                           89
 12.2973 +#define TK_STAR                            90
 12.2974 +#define TK_SLASH                           91
 12.2975 +#define TK_REM                             92
 12.2976 +#define TK_CONCAT                          93
 12.2977 +#define TK_COLLATE                         94
 12.2978 +#define TK_BITNOT                          95
 12.2979 +#define TK_INDEXED                         96
 12.2980  #define TK_STRING                          97
 12.2981  #define TK_JOIN_KW                         98
 12.2982  #define TK_CONSTRAINT                      99
 12.2983 @@ -11229,9 +11567,9 @@
 12.2984  #define TK_LIMIT                          129
 12.2985  #define TK_WHERE                          130
 12.2986  #define TK_INTO                           131
 12.2987 -#define TK_INTEGER                        132
 12.2988 -#define TK_FLOAT                          133
 12.2989 -#define TK_BLOB                           134
 12.2990 +#define TK_FLOAT                          132
 12.2991 +#define TK_BLOB                           133
 12.2992 +#define TK_INTEGER                        134
 12.2993  #define TK_VARIABLE                       135
 12.2994  #define TK_CASE                           136
 12.2995  #define TK_WHEN                           137
 12.2996 @@ -11255,10 +11593,13 @@
 12.2997  #define TK_UMINUS                         155
 12.2998  #define TK_UPLUS                          156
 12.2999  #define TK_REGISTER                       157
 12.3000 -#define TK_ASTERISK                       158
 12.3001 -#define TK_SPAN                           159
 12.3002 -#define TK_SPACE                          160
 12.3003 -#define TK_ILLEGAL                        161
 12.3004 +#define TK_VECTOR                         158
 12.3005 +#define TK_SELECT_COLUMN                  159
 12.3006 +#define TK_IF_NULL_ROW                    160
 12.3007 +#define TK_ASTERISK                       161
 12.3008 +#define TK_SPAN                           162
 12.3009 +#define TK_SPACE                          163
 12.3010 +#define TK_ILLEGAL                        164
 12.3011  
 12.3012  /* The token codes above must all fit in 8 bits */
 12.3013  #define TKFLG_MASK           0xff  
 12.3014 @@ -11276,6 +11617,18 @@
 12.3015  #include <stddef.h>
 12.3016  
 12.3017  /*
 12.3018 +** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY.
 12.3019 +** This allows better measurements of where memcpy() is used when running
 12.3020 +** cachegrind.  But this macro version of memcpy() is very slow so it
 12.3021 +** should not be used in production.  This is a performance measurement
 12.3022 +** hack only.
 12.3023 +*/
 12.3024 +#ifdef SQLITE_INLINE_MEMCPY
 12.3025 +# define memcpy(D,S,N) {char*xxd=(char*)(D);const char*xxs=(const char*)(S);\
 12.3026 +                        int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);}
 12.3027 +#endif
 12.3028 +
 12.3029 +/*
 12.3030  ** If compiling for a processor that lacks floating point support,
 12.3031  ** substitute integer for floating-point
 12.3032  */
 12.3033 @@ -11359,9 +11712,12 @@
 12.3034  ** pagecaches for each database connection.  A positive number is the
 12.3035  ** number of pages.  A negative number N translations means that a buffer
 12.3036  ** of -1024*N bytes is allocated and used for as many pages as it will hold.
 12.3037 +**
 12.3038 +** The default value of "20" was choosen to minimize the run-time of the
 12.3039 +** speedtest1 test program with options: --shrink-memory --reprepare
 12.3040  */
 12.3041  #ifndef SQLITE_DEFAULT_PCACHE_INITSZ
 12.3042 -# define SQLITE_DEFAULT_PCACHE_INITSZ 100
 12.3043 +# define SQLITE_DEFAULT_PCACHE_INITSZ 20
 12.3044  #endif
 12.3045  
 12.3046  /*
 12.3047 @@ -11536,32 +11892,35 @@
 12.3048  **
 12.3049  ** For best performance, an attempt is made to guess at the byte-order
 12.3050  ** using C-preprocessor macros.  If that is unsuccessful, or if
 12.3051 -** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
 12.3052 +** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
 12.3053  ** at run-time.
 12.3054  */
 12.3055 -#if (defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
 12.3056 +#ifndef SQLITE_BYTEORDER
 12.3057 +# if defined(i386)     || defined(__i386__)   || defined(_M_IX86) ||    \
 12.3058       defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)  ||    \
 12.3059       defined(_M_AMD64) || defined(_M_ARM)     || defined(__x86)   ||    \
 12.3060 -     defined(__arm__)) && !defined(SQLITE_RUNTIME_BYTEORDER)
 12.3061 -# define SQLITE_BYTEORDER    1234
 12.3062 +     defined(__arm__)
 12.3063 +#   define SQLITE_BYTEORDER    1234
 12.3064 +# elif defined(sparc)    || defined(__ppc__)
 12.3065 +#   define SQLITE_BYTEORDER    4321
 12.3066 +# else
 12.3067 +#   define SQLITE_BYTEORDER 0
 12.3068 +# endif
 12.3069 +#endif
 12.3070 +#if SQLITE_BYTEORDER==4321
 12.3071 +# define SQLITE_BIGENDIAN    1
 12.3072 +# define SQLITE_LITTLEENDIAN 0
 12.3073 +# define SQLITE_UTF16NATIVE  SQLITE_UTF16BE
 12.3074 +#elif SQLITE_BYTEORDER==1234
 12.3075  # define SQLITE_BIGENDIAN    0
 12.3076  # define SQLITE_LITTLEENDIAN 1
 12.3077  # define SQLITE_UTF16NATIVE  SQLITE_UTF16LE
 12.3078 -#endif
 12.3079 -#if (defined(sparc)    || defined(__ppc__))  \
 12.3080 -    && !defined(SQLITE_RUNTIME_BYTEORDER)
 12.3081 -# define SQLITE_BYTEORDER    4321
 12.3082 -# define SQLITE_BIGENDIAN    1
 12.3083 -# define SQLITE_LITTLEENDIAN 0
 12.3084 -# define SQLITE_UTF16NATIVE  SQLITE_UTF16BE
 12.3085 -#endif
 12.3086 -#if !defined(SQLITE_BYTEORDER)
 12.3087 +#else
 12.3088  # ifdef SQLITE_AMALGAMATION
 12.3089    const int sqlite3one = 1;
 12.3090  # else
 12.3091    extern const int sqlite3one;
 12.3092  # endif
 12.3093 -# define SQLITE_BYTEORDER    0     /* 0 means "unknown at compile-time" */
 12.3094  # define SQLITE_BIGENDIAN    (*(char *)(&sqlite3one)==0)
 12.3095  # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
 12.3096  # define SQLITE_UTF16NATIVE  (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
 12.3097 @@ -11740,8 +12099,8 @@
 12.3098    #define SQLITE_WSD const
 12.3099    #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v)))
 12.3100    #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config)
 12.3101 -SQLITE_API int SQLITE_STDCALL sqlite3_wsd_init(int N, int J);
 12.3102 -SQLITE_API void *SQLITE_STDCALL sqlite3_wsd_find(void *K, int L);
 12.3103 +SQLITE_API int sqlite3_wsd_init(int N, int J);
 12.3104 +SQLITE_API void *sqlite3_wsd_find(void *K, int L);
 12.3105  #else
 12.3106    #define SQLITE_WSD
 12.3107    #define GLOBAL(t,v) v
 12.3108 @@ -11818,6 +12177,14 @@
 12.3109  typedef struct WhereInfo WhereInfo;
 12.3110  typedef struct With With;
 12.3111  
 12.3112 +/* A VList object records a mapping between parameters/variables/wildcards
 12.3113 +** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
 12.3114 +** variable number associated with that parameter.  See the format description
 12.3115 +** on the sqlite3VListAdd() routine for more information.  A VList is really
 12.3116 +** just an array of integers.
 12.3117 +*/
 12.3118 +typedef int VList;
 12.3119 +
 12.3120  /*
 12.3121  ** Defer sourcing vdbe.h and btree.h until after the "u8" and
 12.3122  ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
 12.3123 @@ -11840,8 +12207,8 @@
 12.3124  ** subsystem.  See comments in the source code for a detailed description
 12.3125  ** of what each interface routine does.
 12.3126  */
 12.3127 -#ifndef _BTREE_H_
 12.3128 -#define _BTREE_H_
 12.3129 +#ifndef SQLITE_BTREE_H
 12.3130 +#define SQLITE_BTREE_H
 12.3131  
 12.3132  /* TODO: This definition is just included so other modules compile. It
 12.3133  ** needs to be revisited.
 12.3134 @@ -11866,6 +12233,7 @@
 12.3135  typedef struct Btree Btree;
 12.3136  typedef struct BtCursor BtCursor;
 12.3137  typedef struct BtShared BtShared;
 12.3138 +typedef struct BtreePayload BtreePayload;
 12.3139  
 12.3140  
 12.3141  SQLITE_PRIVATE int sqlite3BtreeOpen(
 12.3142 @@ -11916,7 +12284,9 @@
 12.3143  SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
 12.3144  SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
 12.3145  SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
 12.3146 +#ifndef SQLITE_OMIT_SHARED_CACHE
 12.3147  SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
 12.3148 +#endif
 12.3149  SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int);
 12.3150  
 12.3151  SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
 12.3152 @@ -12073,30 +12443,60 @@
 12.3153  SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*);
 12.3154  SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags);
 12.3155  
 12.3156 -/* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */
 12.3157 +/* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */
 12.3158  #define BTREE_SAVEPOSITION 0x02  /* Leave cursor pointing at NEXT or PREV */
 12.3159  #define BTREE_AUXDELETE    0x04  /* not the primary delete operation */
 12.3160 -
 12.3161 -SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
 12.3162 -                                  const void *pData, int nData,
 12.3163 -                                  int nZero, int bias, int seekResult);
 12.3164 +#define BTREE_APPEND       0x08  /* Insert is likely an append */
 12.3165 +
 12.3166 +/* An instance of the BtreePayload object describes the content of a single
 12.3167 +** entry in either an index or table btree.
 12.3168 +**
 12.3169 +** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
 12.3170 +** an arbitrary key and no data.  These btrees have pKey,nKey set to their
 12.3171 +** key and pData,nData,nZero set to zero.
 12.3172 +**
 12.3173 +** Table btrees (used for rowid tables) contain an integer rowid used as
 12.3174 +** the key and passed in the nKey field.  The pKey field is zero.  
 12.3175 +** pData,nData hold the content of the new entry.  nZero extra zero bytes
 12.3176 +** are appended to the end of the content when constructing the entry.
 12.3177 +**
 12.3178 +** This object is used to pass information into sqlite3BtreeInsert().  The
 12.3179 +** same information used to be passed as five separate parameters.  But placing
 12.3180 +** the information into this object helps to keep the interface more 
 12.3181 +** organized and understandable, and it also helps the resulting code to
 12.3182 +** run a little faster by using fewer registers for parameter passing.
 12.3183 +*/
 12.3184 +struct BtreePayload {
 12.3185 +  const void *pKey;       /* Key content for indexes.  NULL for tables */
 12.3186 +  sqlite3_int64 nKey;     /* Size of pKey for indexes.  PRIMARY KEY for tabs */
 12.3187 +  const void *pData;      /* Data for tables.  NULL for indexes */
 12.3188 +  sqlite3_value *aMem;    /* First of nMem value in the unpacked pKey */
 12.3189 +  u16 nMem;               /* Number of aMem[] value.  Might be zero */
 12.3190 +  int nData;              /* Size of pData.  0 if none. */
 12.3191 +  int nZero;              /* Extra zero data appended after pData,nData */
 12.3192 +};
 12.3193 +
 12.3194 +SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
 12.3195 +                       int flags, int seekResult);
 12.3196  SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
 12.3197  SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
 12.3198  SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
 12.3199  SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
 12.3200  SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
 12.3201 -SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
 12.3202 -SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
 12.3203 -SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
 12.3204 -SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
 12.3205 -SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
 12.3206 -SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
 12.3207 +SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
 12.3208 +SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
 12.3209 +SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
 12.3210 +SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
 12.3211  
 12.3212  SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
 12.3213  SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
 12.3214 -
 12.3215 +SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
 12.3216 +
 12.3217 +#ifndef SQLITE_OMIT_INCRBLOB
 12.3218 +SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*);
 12.3219  SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
 12.3220  SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
 12.3221 +#endif
 12.3222  SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
 12.3223  SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
 12.3224  SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask);
 12.3225 @@ -12106,6 +12506,7 @@
 12.3226  #ifndef NDEBUG
 12.3227  SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
 12.3228  #endif
 12.3229 +SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor*);
 12.3230  
 12.3231  #ifndef SQLITE_OMIT_BTREECOUNT
 12.3232  SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *, i64 *);
 12.3233 @@ -12130,11 +12531,13 @@
 12.3234  SQLITE_PRIVATE   void sqlite3BtreeEnterAll(sqlite3*);
 12.3235  SQLITE_PRIVATE   int sqlite3BtreeSharable(Btree*);
 12.3236  SQLITE_PRIVATE   void sqlite3BtreeEnterCursor(BtCursor*);
 12.3237 +SQLITE_PRIVATE   int sqlite3BtreeConnectionCount(Btree*);
 12.3238  #else
 12.3239  # define sqlite3BtreeEnter(X) 
 12.3240  # define sqlite3BtreeEnterAll(X)
 12.3241  # define sqlite3BtreeSharable(X) 0
 12.3242  # define sqlite3BtreeEnterCursor(X)
 12.3243 +# define sqlite3BtreeConnectionCount(X) 1
 12.3244  #endif
 12.3245  
 12.3246  #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
 12.3247 @@ -12159,7 +12562,7 @@
 12.3248  #endif
 12.3249  
 12.3250  
 12.3251 -#endif /* _BTREE_H_ */
 12.3252 +#endif /* SQLITE_BTREE_H */
 12.3253  
 12.3254  /************** End of btree.h ***********************************************/
 12.3255  /************** Continuing where we left off in sqliteInt.h ******************/
 12.3256 @@ -12182,8 +12585,8 @@
 12.3257  ** or VDBE.  The VDBE implements an abstract machine that runs a
 12.3258  ** simple program to access and modify the underlying database.
 12.3259  */
 12.3260 -#ifndef _SQLITE_VDBE_H_
 12.3261 -#define _SQLITE_VDBE_H_
 12.3262 +#ifndef SQLITE_VDBE_H
 12.3263 +#define SQLITE_VDBE_H
 12.3264  /* #include <stdio.h> */
 12.3265  
 12.3266  /*
 12.3267 @@ -12197,7 +12600,7 @@
 12.3268  ** The names of the following types declared in vdbeInt.h are required
 12.3269  ** for the VdbeOp definition.
 12.3270  */
 12.3271 -typedef struct Mem Mem;
 12.3272 +typedef struct sqlite3_value Mem;
 12.3273  typedef struct SubProgram SubProgram;
 12.3274  
 12.3275  /*
 12.3276 @@ -12208,8 +12611,7 @@
 12.3277  struct VdbeOp {
 12.3278    u8 opcode;          /* What operation to perform */
 12.3279    signed char p4type; /* One of the P4_xxx constants for p4 */
 12.3280 -  u8 notUsed1;
 12.3281 -  u8 p5;              /* Fifth parameter is an unsigned character */
 12.3282 +  u16 p5;             /* Fifth parameter is an unsigned 16-bit integer */
 12.3283    int p1;             /* First operand */
 12.3284    int p2;             /* Second parameter (often the jump destination) */
 12.3285    int p3;             /* The third parameter */
 12.3286 @@ -12255,7 +12657,7 @@
 12.3287    int nOp;                      /* Elements in aOp[] */
 12.3288    int nMem;                     /* Number of memory cells required */
 12.3289    int nCsr;                     /* Number of cursors required */
 12.3290 -  int nOnce;                    /* Number of OP_Once instructions */
 12.3291 +  u8 *aOnce;                    /* Array of OP_Once flags */
 12.3292    void *token;                  /* id that may be used to recursive triggers */
 12.3293    SubProgram *pNext;            /* Next sub-program already visited */
 12.3294  };
 12.3295 @@ -12278,22 +12680,21 @@
 12.3296  #define P4_NOTUSED    0   /* The P4 parameter is not used */
 12.3297  #define P4_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
 12.3298  #define P4_STATIC   (-2)  /* Pointer to a static string */
 12.3299 -#define P4_COLLSEQ  (-4)  /* P4 is a pointer to a CollSeq structure */
 12.3300 -#define P4_FUNCDEF  (-5)  /* P4 is a pointer to a FuncDef structure */
 12.3301 -#define P4_KEYINFO  (-6)  /* P4 is a pointer to a KeyInfo structure */
 12.3302 -#define P4_EXPR     (-7)  /* P4 is a pointer to an Expr tree */
 12.3303 -#define P4_MEM      (-8)  /* P4 is a pointer to a Mem*    structure */
 12.3304 +#define P4_COLLSEQ  (-3)  /* P4 is a pointer to a CollSeq structure */
 12.3305 +#define P4_FUNCDEF  (-4)  /* P4 is a pointer to a FuncDef structure */
 12.3306 +#define P4_KEYINFO  (-5)  /* P4 is a pointer to a KeyInfo structure */
 12.3307 +#define P4_EXPR     (-6)  /* P4 is a pointer to an Expr tree */
 12.3308 +#define P4_MEM      (-7)  /* P4 is a pointer to a Mem*    structure */
 12.3309  #define P4_TRANSIENT  0   /* P4 is a pointer to a transient string */
 12.3310 -#define P4_VTAB     (-10) /* P4 is a pointer to an sqlite3_vtab structure */
 12.3311 -#define P4_MPRINTF  (-11) /* P4 is a string obtained from sqlite3_mprintf() */
 12.3312 -#define P4_REAL     (-12) /* P4 is a 64-bit floating point value */
 12.3313 -#define P4_INT64    (-13) /* P4 is a 64-bit signed integer */
 12.3314 -#define P4_INT32    (-14) /* P4 is a 32-bit signed integer */
 12.3315 -#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
 12.3316 -#define P4_SUBPROGRAM  (-18) /* P4 is a pointer to a SubProgram structure */
 12.3317 -#define P4_ADVANCE  (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */
 12.3318 -#define P4_TABLE    (-20) /* P4 is a pointer to a Table structure */
 12.3319 -#define P4_FUNCCTX  (-21) /* P4 is a pointer to an sqlite3_context object */
 12.3320 +#define P4_VTAB     (-8) /* P4 is a pointer to an sqlite3_vtab structure */
 12.3321 +#define P4_REAL     (-9) /* P4 is a 64-bit floating point value */
 12.3322 +#define P4_INT64    (-10) /* P4 is a 64-bit signed integer */
 12.3323 +#define P4_INT32    (-11) /* P4 is a 32-bit signed integer */
 12.3324 +#define P4_INTARRAY (-12) /* P4 is a vector of 32-bit integers */
 12.3325 +#define P4_SUBPROGRAM  (-13) /* P4 is a pointer to a SubProgram structure */
 12.3326 +#define P4_ADVANCE  (-14) /* P4 is a pointer to BtreeNext() or BtreePrev() */
 12.3327 +#define P4_TABLE    (-15) /* P4 is a pointer to a Table structure */
 12.3328 +#define P4_FUNCCTX  (-16) /* P4 is a pointer to an sqlite3_context object */
 12.3329  
 12.3330  /* Error message codes for OP_Halt */
 12.3331  #define P5_ConstraintNotNull 1
 12.3332 @@ -12359,144 +12760,149 @@
 12.3333  #define OP_Once           20
 12.3334  #define OP_If             21
 12.3335  #define OP_IfNot          22
 12.3336 -#define OP_SeekLT         23 /* synopsis: key=r[P3@P4]                     */
 12.3337 -#define OP_SeekLE         24 /* synopsis: key=r[P3@P4]                     */
 12.3338 -#define OP_SeekGE         25 /* synopsis: key=r[P3@P4]                     */
 12.3339 -#define OP_SeekGT         26 /* synopsis: key=r[P3@P4]                     */
 12.3340 -#define OP_Or             27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
 12.3341 -#define OP_And            28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
 12.3342 -#define OP_NoConflict     29 /* synopsis: key=r[P3@P4]                     */
 12.3343 -#define OP_NotFound       30 /* synopsis: key=r[P3@P4]                     */
 12.3344 -#define OP_Found          31 /* synopsis: key=r[P3@P4]                     */
 12.3345 +#define OP_IfNullRow      23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
 12.3346 +#define OP_SeekLT         24 /* synopsis: key=r[P3@P4]                     */
 12.3347 +#define OP_SeekLE         25 /* synopsis: key=r[P3@P4]                     */
 12.3348 +#define OP_SeekGE         26 /* synopsis: key=r[P3@P4]                     */
 12.3349 +#define OP_SeekGT         27 /* synopsis: key=r[P3@P4]                     */
 12.3350 +#define OP_NoConflict     28 /* synopsis: key=r[P3@P4]                     */
 12.3351 +#define OP_NotFound       29 /* synopsis: key=r[P3@P4]                     */
 12.3352 +#define OP_Found          30 /* synopsis: key=r[P3@P4]                     */
 12.3353 +#define OP_SeekRowid      31 /* synopsis: intkey=r[P3]                     */
 12.3354  #define OP_NotExists      32 /* synopsis: intkey=r[P3]                     */
 12.3355  #define OP_Last           33
 12.3356 -#define OP_IsNull         34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
 12.3357 -#define OP_NotNull        35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
 12.3358 -#define OP_Ne             36 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
 12.3359 -#define OP_Eq             37 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
 12.3360 -#define OP_Gt             38 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
 12.3361 -#define OP_Le             39 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
 12.3362 -#define OP_Lt             40 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
 12.3363 -#define OP_Ge             41 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
 12.3364 -#define OP_SorterSort     42
 12.3365 -#define OP_BitAnd         43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
 12.3366 -#define OP_BitOr          44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
 12.3367 -#define OP_ShiftLeft      45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
 12.3368 -#define OP_ShiftRight     46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
 12.3369 -#define OP_Add            47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
 12.3370 -#define OP_Subtract       48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
 12.3371 -#define OP_Multiply       49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
 12.3372 -#define OP_Divide         50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
 12.3373 -#define OP_Remainder      51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
 12.3374 -#define OP_Concat         52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
 12.3375 -#define OP_Sort           53
 12.3376 -#define OP_BitNot         54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
 12.3377 -#define OP_Rewind         55
 12.3378 -#define OP_IdxLE          56 /* synopsis: key=r[P3@P4]                     */
 12.3379 -#define OP_IdxGT          57 /* synopsis: key=r[P3@P4]                     */
 12.3380 -#define OP_IdxLT          58 /* synopsis: key=r[P3@P4]                     */
 12.3381 -#define OP_IdxGE          59 /* synopsis: key=r[P3@P4]                     */
 12.3382 -#define OP_RowSetRead     60 /* synopsis: r[P3]=rowset(P1)                 */
 12.3383 -#define OP_RowSetTest     61 /* synopsis: if r[P3] in rowset(P1) goto P2   */
 12.3384 -#define OP_Program        62
 12.3385 -#define OP_FkIfZero       63 /* synopsis: if fkctr[P1]==0 goto P2          */
 12.3386 -#define OP_IfPos          64 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
 12.3387 -#define OP_IfNotZero      65 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
 12.3388 -#define OP_DecrJumpZero   66 /* synopsis: if (--r[P1])==0 goto P2          */
 12.3389 -#define OP_IncrVacuum     67
 12.3390 -#define OP_VNext          68
 12.3391 -#define OP_Init           69 /* synopsis: Start at P2                      */
 12.3392 -#define OP_Return         70
 12.3393 -#define OP_EndCoroutine   71
 12.3394 -#define OP_HaltIfNull     72 /* synopsis: if r[P3]=null halt               */
 12.3395 -#define OP_Halt           73
 12.3396 -#define OP_Integer        74 /* synopsis: r[P2]=P1                         */
 12.3397 -#define OP_Int64          75 /* synopsis: r[P2]=P4                         */
 12.3398 -#define OP_String         76 /* synopsis: r[P2]='P4' (len=P1)              */
 12.3399 -#define OP_Null           77 /* synopsis: r[P2..P3]=NULL                   */
 12.3400 -#define OP_SoftNull       78 /* synopsis: r[P1]=NULL                       */
 12.3401 -#define OP_Blob           79 /* synopsis: r[P2]=P4 (len=P1)                */
 12.3402 -#define OP_Variable       80 /* synopsis: r[P2]=parameter(P1,P4)           */
 12.3403 -#define OP_Move           81 /* synopsis: r[P2@P3]=r[P1@P3]                */
 12.3404 -#define OP_Copy           82 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
 12.3405 -#define OP_SCopy          83 /* synopsis: r[P2]=r[P1]                      */
 12.3406 -#define OP_IntCopy        84 /* synopsis: r[P2]=r[P1]                      */
 12.3407 -#define OP_ResultRow      85 /* synopsis: output=r[P1@P2]                  */
 12.3408 -#define OP_CollSeq        86
 12.3409 -#define OP_Function0      87 /* synopsis: r[P3]=func(r[P2@P5])             */
 12.3410 -#define OP_Function       88 /* synopsis: r[P3]=func(r[P2@P5])             */
 12.3411 -#define OP_AddImm         89 /* synopsis: r[P1]=r[P1]+P2                   */
 12.3412 -#define OP_RealAffinity   90
 12.3413 -#define OP_Cast           91 /* synopsis: affinity(r[P1])                  */
 12.3414 -#define OP_Permutation    92
 12.3415 -#define OP_Compare        93 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
 12.3416 -#define OP_Column         94 /* synopsis: r[P3]=PX                         */
 12.3417 -#define OP_Affinity       95 /* synopsis: affinity(r[P1@P2])               */
 12.3418 -#define OP_MakeRecord     96 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
 12.3419 +#define OP_IfSmaller      34
 12.3420 +#define OP_SorterSort     35
 12.3421 +#define OP_Sort           36
 12.3422 +#define OP_Rewind         37
 12.3423 +#define OP_IdxLE          38 /* synopsis: key=r[P3@P4]                     */
 12.3424 +#define OP_IdxGT          39 /* synopsis: key=r[P3@P4]                     */
 12.3425 +#define OP_IdxLT          40 /* synopsis: key=r[P3@P4]                     */
 12.3426 +#define OP_IdxGE          41 /* synopsis: key=r[P3@P4]                     */
 12.3427 +#define OP_RowSetRead     42 /* synopsis: r[P3]=rowset(P1)                 */
 12.3428 +#define OP_RowSetTest     43 /* synopsis: if r[P3] in rowset(P1) goto P2   */
 12.3429 +#define OP_Program        44
 12.3430 +#define OP_FkIfZero       45 /* synopsis: if fkctr[P1]==0 goto P2          */
 12.3431 +#define OP_IfPos          46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
 12.3432 +#define OP_IfNotZero      47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
 12.3433 +#define OP_DecrJumpZero   48 /* synopsis: if (--r[P1])==0 goto P2          */
 12.3434 +#define OP_IncrVacuum     49
 12.3435 +#define OP_VNext          50
 12.3436 +#define OP_Init           51 /* synopsis: Start at P2                      */
 12.3437 +#define OP_Return         52
 12.3438 +#define OP_EndCoroutine   53
 12.3439 +#define OP_HaltIfNull     54 /* synopsis: if r[P3]=null halt               */
 12.3440 +#define OP_Halt           55
 12.3441 +#define OP_Integer        56 /* synopsis: r[P2]=P1                         */
 12.3442 +#define OP_Int64          57 /* synopsis: r[P2]=P4                         */
 12.3443 +#define OP_String         58 /* synopsis: r[P2]='P4' (len=P1)              */
 12.3444 +#define OP_Null           59 /* synopsis: r[P2..P3]=NULL                   */
 12.3445 +#define OP_SoftNull       60 /* synopsis: r[P1]=NULL                       */
 12.3446 +#define OP_Blob           61 /* synopsis: r[P2]=P4 (len=P1)                */
 12.3447 +#define OP_Variable       62 /* synopsis: r[P2]=parameter(P1,P4)           */
 12.3448 +#define OP_Move           63 /* synopsis: r[P2@P3]=r[P1@P3]                */
 12.3449 +#define OP_Copy           64 /* synopsis: r[P2@P3+1]=r[P1@P3+1]            */
 12.3450 +#define OP_SCopy          65 /* synopsis: r[P2]=r[P1]                      */
 12.3451 +#define OP_IntCopy        66 /* synopsis: r[P2]=r[P1]                      */
 12.3452 +#define OP_ResultRow      67 /* synopsis: output=r[P1@P2]                  */
 12.3453 +#define OP_CollSeq        68
 12.3454 +#define OP_Function0      69 /* synopsis: r[P3]=func(r[P2@P5])             */
 12.3455 +#define OP_Or             70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
 12.3456 +#define OP_And            71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
 12.3457 +#define OP_Function       72 /* synopsis: r[P3]=func(r[P2@P5])             */
 12.3458 +#define OP_AddImm         73 /* synopsis: r[P1]=r[P1]+P2                   */
 12.3459 +#define OP_RealAffinity   74
 12.3460 +#define OP_IsNull         75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
 12.3461 +#define OP_NotNull        76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
 12.3462 +#define OP_Ne             77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1]   */
 12.3463 +#define OP_Eq             78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1]   */
 12.3464 +#define OP_Gt             79 /* same as TK_GT, synopsis: IF r[P3]>r[P1]    */
 12.3465 +#define OP_Le             80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1]   */
 12.3466 +#define OP_Lt             81 /* same as TK_LT, synopsis: IF r[P3]<r[P1]    */
 12.3467 +#define OP_Ge             82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1]   */
 12.3468 +#define OP_ElseNotEq      83 /* same as TK_ESCAPE                          */
 12.3469 +#define OP_BitAnd         84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
 12.3470 +#define OP_BitOr          85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
 12.3471 +#define OP_ShiftLeft      86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
 12.3472 +#define OP_ShiftRight     87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
 12.3473 +#define OP_Add            88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
 12.3474 +#define OP_Subtract       89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
 12.3475 +#define OP_Multiply       90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
 12.3476 +#define OP_Divide         91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
 12.3477 +#define OP_Remainder      92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
 12.3478 +#define OP_Concat         93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
 12.3479 +#define OP_Cast           94 /* synopsis: affinity(r[P1])                  */
 12.3480 +#define OP_BitNot         95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
 12.3481 +#define OP_Permutation    96
 12.3482  #define OP_String8        97 /* same as TK_STRING, synopsis: r[P2]='P4'    */
 12.3483 -#define OP_Count          98 /* synopsis: r[P2]=count()                    */
 12.3484 -#define OP_ReadCookie     99
 12.3485 -#define OP_SetCookie     100
 12.3486 -#define OP_ReopenIdx     101 /* synopsis: root=P2 iDb=P3                   */
 12.3487 -#define OP_OpenRead      102 /* synopsis: root=P2 iDb=P3                   */
 12.3488 -#define OP_OpenWrite     103 /* synopsis: root=P2 iDb=P3                   */
 12.3489 -#define OP_OpenAutoindex 104 /* synopsis: nColumn=P2                       */
 12.3490 -#define OP_OpenEphemeral 105 /* synopsis: nColumn=P2                       */
 12.3491 -#define OP_SorterOpen    106
 12.3492 -#define OP_SequenceTest  107 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
 12.3493 -#define OP_OpenPseudo    108 /* synopsis: P3 columns in r[P2]              */
 12.3494 -#define OP_Close         109
 12.3495 -#define OP_ColumnsUsed   110
 12.3496 -#define OP_Sequence      111 /* synopsis: r[P2]=cursor[P1].ctr++           */
 12.3497 -#define OP_NewRowid      112 /* synopsis: r[P2]=rowid                      */
 12.3498 -#define OP_Insert        113 /* synopsis: intkey=r[P3] data=r[P2]          */
 12.3499 -#define OP_InsertInt     114 /* synopsis: intkey=P3 data=r[P2]             */
 12.3500 -#define OP_Delete        115
 12.3501 -#define OP_ResetCount    116
 12.3502 -#define OP_SorterCompare 117 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
 12.3503 -#define OP_SorterData    118 /* synopsis: r[P2]=data                       */
 12.3504 -#define OP_RowKey        119 /* synopsis: r[P2]=key                        */
 12.3505 -#define OP_RowData       120 /* synopsis: r[P2]=data                       */
 12.3506 -#define OP_Rowid         121 /* synopsis: r[P2]=rowid                      */
 12.3507 -#define OP_NullRow       122
 12.3508 -#define OP_SorterInsert  123
 12.3509 -#define OP_IdxInsert     124 /* synopsis: key=r[P2]                        */
 12.3510 -#define OP_IdxDelete     125 /* synopsis: key=r[P2@P3]                     */
 12.3511 -#define OP_Seek          126 /* synopsis: Move P3 to P1.rowid              */
 12.3512 -#define OP_IdxRowid      127 /* synopsis: r[P2]=rowid                      */
 12.3513 -#define OP_Destroy       128
 12.3514 -#define OP_Clear         129
 12.3515 -#define OP_ResetSorter   130
 12.3516 -#define OP_CreateIndex   131 /* synopsis: r[P2]=root iDb=P1                */
 12.3517 -#define OP_CreateTable   132 /* synopsis: r[P2]=root iDb=P1                */
 12.3518 -#define OP_Real          133 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
 12.3519 -#define OP_ParseSchema   134
 12.3520 -#define OP_LoadAnalysis  135
 12.3521 -#define OP_DropTable     136
 12.3522 -#define OP_DropIndex     137
 12.3523 -#define OP_DropTrigger   138
 12.3524 -#define OP_IntegrityCk   139
 12.3525 -#define OP_RowSetAdd     140 /* synopsis: rowset(P1)=r[P2]                 */
 12.3526 -#define OP_Param         141
 12.3527 -#define OP_FkCounter     142 /* synopsis: fkctr[P1]+=P2                    */
 12.3528 -#define OP_MemMax        143 /* synopsis: r[P1]=max(r[P1],r[P2])           */
 12.3529 -#define OP_OffsetLimit   144 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
 12.3530 -#define OP_AggStep0      145 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 12.3531 -#define OP_AggStep       146 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 12.3532 -#define OP_AggFinal      147 /* synopsis: accum=r[P1] N=P2                 */
 12.3533 -#define OP_Expire        148
 12.3534 -#define OP_TableLock     149 /* synopsis: iDb=P1 root=P2 write=P3          */
 12.3535 -#define OP_VBegin        150
 12.3536 -#define OP_VCreate       151
 12.3537 -#define OP_VDestroy      152
 12.3538 -#define OP_VOpen         153
 12.3539 -#define OP_VColumn       154 /* synopsis: r[P3]=vcolumn(P2)                */
 12.3540 -#define OP_VRename       155
 12.3541 -#define OP_Pagecount     156
 12.3542 -#define OP_MaxPgcnt      157
 12.3543 -#define OP_CursorHint    158
 12.3544 -#define OP_Noop          159
 12.3545 -#define OP_Explain       160
 12.3546 +#define OP_Compare        98 /* synopsis: r[P1@P3] <-> r[P2@P3]            */
 12.3547 +#define OP_Column         99 /* synopsis: r[P3]=PX                         */
 12.3548 +#define OP_Affinity      100 /* synopsis: affinity(r[P1@P2])               */
 12.3549 +#define OP_MakeRecord    101 /* synopsis: r[P3]=mkrec(r[P1@P2])            */
 12.3550 +#define OP_Count         102 /* synopsis: r[P2]=count()                    */
 12.3551 +#define OP_ReadCookie    103
 12.3552 +#define OP_SetCookie     104
 12.3553 +#define OP_ReopenIdx     105 /* synopsis: root=P2 iDb=P3                   */
 12.3554 +#define OP_OpenRead      106 /* synopsis: root=P2 iDb=P3                   */
 12.3555 +#define OP_OpenWrite     107 /* synopsis: root=P2 iDb=P3                   */
 12.3556 +#define OP_OpenDup       108
 12.3557 +#define OP_OpenAutoindex 109 /* synopsis: nColumn=P2                       */
 12.3558 +#define OP_OpenEphemeral 110 /* synopsis: nColumn=P2                       */
 12.3559 +#define OP_SorterOpen    111
 12.3560 +#define OP_SequenceTest  112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2   */
 12.3561 +#define OP_OpenPseudo    113 /* synopsis: P3 columns in r[P2]              */
 12.3562 +#define OP_Close         114
 12.3563 +#define OP_ColumnsUsed   115
 12.3564 +#define OP_Sequence      116 /* synopsis: r[P2]=cursor[P1].ctr++           */
 12.3565 +#define OP_NewRowid      117 /* synopsis: r[P2]=rowid                      */
 12.3566 +#define OP_Insert        118 /* synopsis: intkey=r[P3] data=r[P2]          */
 12.3567 +#define OP_InsertInt     119 /* synopsis: intkey=P3 data=r[P2]             */
 12.3568 +#define OP_Delete        120
 12.3569 +#define OP_ResetCount    121
 12.3570 +#define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
 12.3571 +#define OP_SorterData    123 /* synopsis: r[P2]=data                       */
 12.3572 +#define OP_RowData       124 /* synopsis: r[P2]=data                       */
 12.3573 +#define OP_Rowid         125 /* synopsis: r[P2]=rowid                      */
 12.3574 +#define OP_NullRow       126
 12.3575 +#define OP_SorterInsert  127 /* synopsis: key=r[P2]                        */
 12.3576 +#define OP_IdxInsert     128 /* synopsis: key=r[P2]                        */
 12.3577 +#define OP_IdxDelete     129 /* synopsis: key=r[P2@P3]                     */
 12.3578 +#define OP_Seek          130 /* synopsis: Move P3 to P1.rowid              */
 12.3579 +#define OP_IdxRowid      131 /* synopsis: r[P2]=rowid                      */
 12.3580 +#define OP_Real          132 /* same as TK_FLOAT, synopsis: r[P2]=P4       */
 12.3581 +#define OP_Destroy       133
 12.3582 +#define OP_Clear         134
 12.3583 +#define OP_ResetSorter   135
 12.3584 +#define OP_CreateIndex   136 /* synopsis: r[P2]=root iDb=P1                */
 12.3585 +#define OP_CreateTable   137 /* synopsis: r[P2]=root iDb=P1                */
 12.3586 +#define OP_SqlExec       138
 12.3587 +#define OP_ParseSchema   139
 12.3588 +#define OP_LoadAnalysis  140
 12.3589 +#define OP_DropTable     141
 12.3590 +#define OP_DropIndex     142
 12.3591 +#define OP_DropTrigger   143
 12.3592 +#define OP_IntegrityCk   144
 12.3593 +#define OP_RowSetAdd     145 /* synopsis: rowset(P1)=r[P2]                 */
 12.3594 +#define OP_Param         146
 12.3595 +#define OP_FkCounter     147 /* synopsis: fkctr[P1]+=P2                    */
 12.3596 +#define OP_MemMax        148 /* synopsis: r[P1]=max(r[P1],r[P2])           */
 12.3597 +#define OP_OffsetLimit   149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
 12.3598 +#define OP_AggStep0      150 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 12.3599 +#define OP_AggStep       151 /* synopsis: accum=r[P3] step(r[P2@P5])       */
 12.3600 +#define OP_AggFinal      152 /* synopsis: accum=r[P1] N=P2                 */
 12.3601 +#define OP_Expire        153
 12.3602 +#define OP_TableLock     154 /* synopsis: iDb=P1 root=P2 write=P3          */
 12.3603 +#define OP_VBegin        155
 12.3604 +#define OP_VCreate       156
 12.3605 +#define OP_VDestroy      157
 12.3606 +#define OP_VOpen         158
 12.3607 +#define OP_VColumn       159 /* synopsis: r[P3]=vcolumn(P2)                */
 12.3608 +#define OP_VRename       160
 12.3609 +#define OP_Pagecount     161
 12.3610 +#define OP_MaxPgcnt      162
 12.3611 +#define OP_CursorHint    163
 12.3612 +#define OP_Noop          164
 12.3613 +#define OP_Explain       165
 12.3614  
 12.3615  /* Properties such as "out2" or "jump" that are specified in
 12.3616  ** comments following the "case" for each opcode in the vdbe.c
 12.3617 @@ -12511,25 +12917,25 @@
 12.3618  #define OPFLG_INITIALIZER {\
 12.3619  /*   0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
 12.3620  /*   8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
 12.3621 -/*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
 12.3622 -/*  24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
 12.3623 -/*  32 */ 0x09, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
 12.3624 -/*  40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
 12.3625 -/*  48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
 12.3626 -/*  56 */ 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01,\
 12.3627 -/*  64 */ 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x02, 0x02,\
 12.3628 -/*  72 */ 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10,\
 12.3629 -/*  80 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
 12.3630 -/*  88 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
 12.3631 -/*  96 */ 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
 12.3632 -/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
 12.3633 -/* 112 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 12.3634 -/* 120 */ 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
 12.3635 -/* 128 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
 12.3636 -/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
 12.3637 -/* 144 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 12.3638 -/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
 12.3639 -/* 160 */ 0x00,}
 12.3640 +/*  16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
 12.3641 +/*  24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
 12.3642 +/*  32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
 12.3643 +/*  40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
 12.3644 +/*  48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
 12.3645 +/*  56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
 12.3646 +/*  64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
 12.3647 +/*  72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
 12.3648 +/*  80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
 12.3649 +/*  88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
 12.3650 +/*  96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
 12.3651 +/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 12.3652 +/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
 12.3653 +/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
 12.3654 +/* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
 12.3655 +/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 12.3656 +/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
 12.3657 +/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 12.3658 +/* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,}
 12.3659  
 12.3660  /* The sqlite3P2Values() routine is able to run faster if it knows
 12.3661  ** the value of the largest JUMP opcode.  The smaller the maximum
 12.3662 @@ -12537,7 +12943,7 @@
 12.3663  ** generated this include file strives to group all JUMP opcodes
 12.3664  ** together near the beginning of the list.
 12.3665  */
 12.3666 -#define SQLITE_MX_JUMP_OPCODE  69  /* Maximum JUMP opcode */
 12.3667 +#define SQLITE_MX_JUMP_OPCODE  83  /* Maximum JUMP opcode */
 12.3668  
 12.3669  /************** End of opcodes.h *********************************************/
 12.3670  /************** Continuing where we left off in vdbe.h ***********************/
 12.3671 @@ -12560,8 +12966,10 @@
 12.3672  SQLITE_PRIVATE void sqlite3VdbeEndCoroutine(Vdbe*,int);
 12.3673  #if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
 12.3674  SQLITE_PRIVATE   void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N);
 12.3675 +SQLITE_PRIVATE   void sqlite3VdbeVerifyNoResultRow(Vdbe *p);
 12.3676  #else
 12.3677  # define sqlite3VdbeVerifyNoMallocRequired(A,B)
 12.3678 +# define sqlite3VdbeVerifyNoResultRow(A)
 12.3679  #endif
 12.3680  SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
 12.3681  SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
 12.3682 @@ -12569,11 +12977,12 @@
 12.3683  SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
 12.3684  SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
 12.3685  SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
 12.3686 -SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
 12.3687 +SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
 12.3688  SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
 12.3689  SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
 12.3690  SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
 12.3691  SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
 12.3692 +SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
 12.3693  SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
 12.3694  SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
 12.3695  SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
 12.3696 @@ -12609,7 +13018,7 @@
 12.3697  SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
 12.3698  SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
 12.3699  SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
 12.3700 -SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
 12.3701 +SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
 12.3702  
 12.3703  typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
 12.3704  SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
 12.3705 @@ -12684,7 +13093,7 @@
 12.3706  # define sqlite3VdbeScanStatus(a,b,c,d,e)
 12.3707  #endif
 12.3708  
 12.3709 -#endif
 12.3710 +#endif /* SQLITE_VDBE_H */
 12.3711  
 12.3712  /************** End of vdbe.h ************************************************/
 12.3713  /************** Continuing where we left off in sqliteInt.h ******************/
 12.3714 @@ -12706,8 +13115,8 @@
 12.3715  ** at a time and provides a journal for rollback.
 12.3716  */
 12.3717  
 12.3718 -#ifndef _PAGER_H_
 12.3719 -#define _PAGER_H_
 12.3720 +#ifndef SQLITE_PAGER_H
 12.3721 +#define SQLITE_PAGER_H
 12.3722  
 12.3723  /*
 12.3724  ** Default maximum size for persistent journal files. A negative 
 12.3725 @@ -12814,7 +13223,7 @@
 12.3726    int,
 12.3727    void(*)(DbPage*)
 12.3728  );
 12.3729 -SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager);
 12.3730 +SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3*);
 12.3731  SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
 12.3732  
 12.3733  /* Functions used to configure a Pager object. */
 12.3734 @@ -12865,15 +13274,21 @@
 12.3735  SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
 12.3736  
 12.3737  #ifndef SQLITE_OMIT_WAL
 12.3738 -SQLITE_PRIVATE   int sqlite3PagerCheckpoint(Pager *pPager, int, int*, int*);
 12.3739 +SQLITE_PRIVATE   int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*);
 12.3740  SQLITE_PRIVATE   int sqlite3PagerWalSupported(Pager *pPager);
 12.3741  SQLITE_PRIVATE   int sqlite3PagerWalCallback(Pager *pPager);
 12.3742  SQLITE_PRIVATE   int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
 12.3743 -SQLITE_PRIVATE   int sqlite3PagerCloseWal(Pager *pPager);
 12.3744 +SQLITE_PRIVATE   int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
 12.3745 +# ifdef SQLITE_DIRECT_OVERFLOW_READ
 12.3746 +SQLITE_PRIVATE   int sqlite3PagerUseWal(Pager *pPager, Pgno);
 12.3747 +# endif
 12.3748  # ifdef SQLITE_ENABLE_SNAPSHOT
 12.3749  SQLITE_PRIVATE   int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot);
 12.3750  SQLITE_PRIVATE   int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot);
 12.3751 +SQLITE_PRIVATE   int sqlite3PagerSnapshotRecover(Pager *pPager);
 12.3752  # endif
 12.3753 +#else
 12.3754 +# define sqlite3PagerUseWal(x,y) 0
 12.3755  #endif
 12.3756  
 12.3757  #ifdef SQLITE_ENABLE_ZIPVFS
 12.3758 @@ -12895,7 +13310,7 @@
 12.3759  SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
 12.3760  SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
 12.3761  SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *);
 12.3762 -SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *);
 12.3763 +SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*);
 12.3764  SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
 12.3765  
 12.3766  /* Functions used to truncate the database file. */
 12.3767 @@ -12922,7 +13337,7 @@
 12.3768  # define enable_simulated_io_errors()
 12.3769  #endif
 12.3770  
 12.3771 -#endif /* _PAGER_H_ */
 12.3772 +#endif /* SQLITE_PAGER_H */
 12.3773  
 12.3774  /************** End of pager.h ***********************************************/
 12.3775  /************** Continuing where we left off in sqliteInt.h ******************/
 12.3776 @@ -13160,8 +13575,8 @@
 12.3777  ** This file contains pre-processor directives related to operating system
 12.3778  ** detection and/or setup.
 12.3779  */
 12.3780 -#ifndef _OS_SETUP_H_
 12.3781 -#define _OS_SETUP_H_
 12.3782 +#ifndef SQLITE_OS_SETUP_H
 12.3783 +#define SQLITE_OS_SETUP_H
 12.3784  
 12.3785  /*
 12.3786  ** Figure out if we are dealing with Unix, Windows, or some other operating
 12.3787 @@ -13201,7 +13616,7 @@
 12.3788  #  endif
 12.3789  #endif
 12.3790  
 12.3791 -#endif /* _OS_SETUP_H_ */
 12.3792 +#endif /* SQLITE_OS_SETUP_H */
 12.3793  
 12.3794  /************** End of os_setup.h ********************************************/
 12.3795  /************** Continuing where we left off in os.h *************************/
 12.3796 @@ -13492,7 +13907,7 @@
 12.3797  ** and the one-based values are used internally.
 12.3798  */
 12.3799  #ifndef SQLITE_DEFAULT_SYNCHRONOUS
 12.3800 -# define SQLITE_DEFAULT_SYNCHRONOUS (PAGER_SYNCHRONOUS_FULL-1)
 12.3801 +# define SQLITE_DEFAULT_SYNCHRONOUS 2
 12.3802  #endif
 12.3803  #ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS
 12.3804  # define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS
 12.3805 @@ -13506,7 +13921,7 @@
 12.3806  ** databases may be attached.
 12.3807  */
 12.3808  struct Db {
 12.3809 -  char *zName;         /* Name of this database */
 12.3810 +  char *zDbSName;      /* Name of this database. (schema name, not filename) */
 12.3811    Btree *pBt;          /* The B*Tree structure for this database file */
 12.3812    u8 safety_level;     /* How aggressive at syncing data to disk */
 12.3813    u8 bSyncSet;         /* True if "PRAGMA synchronous=N" has been run */
 12.3814 @@ -13658,6 +14073,15 @@
 12.3815                                 const char*);
 12.3816  #endif
 12.3817  
 12.3818 +#ifndef SQLITE_OMIT_DEPRECATED
 12.3819 +/* This is an extra SQLITE_TRACE macro that indicates "legacy" tracing
 12.3820 +** in the style of sqlite3_trace()
 12.3821 +*/
 12.3822 +#define SQLITE_TRACE_LEGACY  0x80
 12.3823 +#else
 12.3824 +#define SQLITE_TRACE_LEGACY  0
 12.3825 +#endif /* SQLITE_OMIT_DEPRECATED */
 12.3826 +
 12.3827  
 12.3828  /*
 12.3829  ** Each database connection is an instance of the following structure.
 12.3830 @@ -13687,6 +14111,9 @@
 12.3831    u8 suppressErr;               /* Do not issue error messages if true */
 12.3832    u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */
 12.3833    u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */
 12.3834 +  u8 mTrace;                    /* zero or more SQLITE_TRACE flags */
 12.3835 +  u8 skipBtreeMutex;            /* True if no shared-cache backends */
 12.3836 +  u8 nSqlExec;                  /* Number of pending OP_SqlExec opcodes */
 12.3837    int nextPagesize;             /* Pagesize after VACUUM if >0 */
 12.3838    u32 magic;                    /* Magic number for detect library misuse */
 12.3839    int nChange;                  /* Value returned by sqlite3_changes() */
 12.3840 @@ -13707,7 +14134,7 @@
 12.3841    int nVDestroy;                /* Number of active OP_VDestroy operations */
 12.3842    int nExtension;               /* Number of loaded extensions */
 12.3843    void **aExtension;            /* Array of shared library handles */
 12.3844 -  void (*xTrace)(void*,const char*);        /* Trace function */
 12.3845 +  int (*xTrace)(u32,void*,void*,void*);     /* Trace function */
 12.3846    void *pTraceArg;                          /* Argument to the trace function */
 12.3847    void (*xProfile)(void*,const char*,u64);  /* Profiling function */
 12.3848    void *pProfileArg;                        /* Argument to profile function */
 12.3849 @@ -13834,6 +14261,7 @@
 12.3850  #define SQLITE_Vacuum         0x10000000  /* Currently in a VACUUM */
 12.3851  #define SQLITE_CellSizeCk     0x20000000  /* Check btree cell sizes on load */
 12.3852  #define SQLITE_Fts3Tokenizer  0x40000000  /* Enable fts3_tokenizer(2) */
 12.3853 +#define SQLITE_NoCkptOnClose  0x80000000  /* No checkpoint on close()/DETACH */
 12.3854  
 12.3855  
 12.3856  /*
 12.3857 @@ -13859,13 +14287,8 @@
 12.3858  /*
 12.3859  ** Macros for testing whether or not optimizations are enabled or disabled.
 12.3860  */
 12.3861 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.3862  #define OptimizationDisabled(db, mask)  (((db)->dbOptFlags&(mask))!=0)
 12.3863  #define OptimizationEnabled(db, mask)   (((db)->dbOptFlags&(mask))==0)
 12.3864 -#else
 12.3865 -#define OptimizationDisabled(db, mask)  0
 12.3866 -#define OptimizationEnabled(db, mask)   1
 12.3867 -#endif
 12.3868  
 12.3869  /*
 12.3870  ** Return true if it OK to factor constant expressions into the initialization
 12.3871 @@ -13956,6 +14379,7 @@
 12.3872  #define SQLITE_FUNC_MINMAX   0x1000 /* True for min() and max() aggregates */
 12.3873  #define SQLITE_FUNC_SLOCHNG  0x2000 /* "Slow Change". Value constant during a
 12.3874                                      ** single query - might change over time */
 12.3875 +#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
 12.3876  
 12.3877  /*
 12.3878  ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
 12.3879 @@ -14132,6 +14556,7 @@
 12.3880  ** operator is NULL.  It is added to certain comparison operators to
 12.3881  ** prove that the operands are always NOT NULL.
 12.3882  */
 12.3883 +#define SQLITE_KEEPNULL     0x08  /* Used by vector == or <> */
 12.3884  #define SQLITE_JUMPIFNULL   0x10  /* jumps if either operand is NULL */
 12.3885  #define SQLITE_STOREP2      0x20  /* Store result in reg[P2] rather than jump */
 12.3886  #define SQLITE_NULLEQ       0x80  /* NULL=NULL */
 12.3887 @@ -14203,15 +14628,15 @@
 12.3888    ExprList *pCheck;    /* All CHECK constraints */
 12.3889                         /*   ... also used as column name list in a VIEW */
 12.3890    int tnum;            /* Root BTree page for this table */
 12.3891 +  u32 nTabRef;         /* Number of pointers to this Table */
 12.3892 +  u32 tabFlags;        /* Mask of TF_* values */
 12.3893    i16 iPKey;           /* If not negative, use aCol[iPKey] as the rowid */
 12.3894    i16 nCol;            /* Number of columns in this table */
 12.3895 -  u16 nRef;            /* Number of pointers to this Table */
 12.3896    LogEst nRowLogEst;   /* Estimated rows in table - from sqlite_stat1 table */
 12.3897    LogEst szTabRow;     /* Estimated size of each table row in bytes */
 12.3898  #ifdef SQLITE_ENABLE_COSTMULT
 12.3899    LogEst costMult;     /* Cost multiplier for using this table */
 12.3900  #endif
 12.3901 -  u8 tabFlags;         /* Mask of TF_* values */
 12.3902    u8 keyConf;          /* What to do in case of uniqueness conflict on iPKey */
 12.3903  #ifndef SQLITE_OMIT_ALTERTABLE
 12.3904    int addColOffset;    /* Offset in CREATE TABLE stmt to add a new column */
 12.3905 @@ -14235,15 +14660,17 @@
 12.3906  ** the TF_OOOHidden attribute would apply in this case.  Such tables require
 12.3907  ** special handling during INSERT processing.
 12.3908  */
 12.3909 -#define TF_Readonly        0x01    /* Read-only system table */
 12.3910 -#define TF_Ephemeral       0x02    /* An ephemeral table */
 12.3911 -#define TF_HasPrimaryKey   0x04    /* Table has a primary key */
 12.3912 -#define TF_Autoincrement   0x08    /* Integer primary key is autoincrement */
 12.3913 -#define TF_Virtual         0x10    /* Is a virtual table */
 12.3914 -#define TF_WithoutRowid    0x20    /* No rowid.  PRIMARY KEY is the key */
 12.3915 -#define TF_NoVisibleRowid  0x40    /* No user-visible "rowid" column */
 12.3916 -#define TF_OOOHidden       0x80    /* Out-of-Order hidden columns */
 12.3917 -
 12.3918 +#define TF_Readonly        0x0001    /* Read-only system table */
 12.3919 +#define TF_Ephemeral       0x0002    /* An ephemeral table */
 12.3920 +#define TF_HasPrimaryKey   0x0004    /* Table has a primary key */
 12.3921 +#define TF_Autoincrement   0x0008    /* Integer primary key is autoincrement */
 12.3922 +#define TF_HasStat1        0x0010    /* nRowLogEst set from sqlite_stat1 */
 12.3923 +#define TF_WithoutRowid    0x0020    /* No rowid.  PRIMARY KEY is the key */
 12.3924 +#define TF_NoVisibleRowid  0x0040    /* No user-visible "rowid" column */
 12.3925 +#define TF_OOOHidden       0x0080    /* Out-of-Order hidden columns */
 12.3926 +#define TF_StatsUsed       0x0100    /* Query planner decisions affected by
 12.3927 +                                     ** Index.aiRowLogEst[] values */
 12.3928 +#define TF_HasNotNull      0x0200    /* Contains NOT NULL constraints */
 12.3929  
 12.3930  /*
 12.3931  ** Test to see whether or not a table is a virtual table.  This is
 12.3932 @@ -14251,7 +14678,7 @@
 12.3933  ** table support is omitted from the build.
 12.3934  */
 12.3935  #ifndef SQLITE_OMIT_VIRTUALTABLE
 12.3936 -#  define IsVirtual(X)      (((X)->tabFlags & TF_Virtual)!=0)
 12.3937 +#  define IsVirtual(X)      ((X)->nModuleArg)
 12.3938  #else
 12.3939  #  define IsVirtual(X)      0
 12.3940  #endif
 12.3941 @@ -14486,6 +14913,7 @@
 12.3942    unsigned isResized:1;    /* True if resizeIndexObject() has been called */
 12.3943    unsigned isCovering:1;   /* True if this is a covering index */
 12.3944    unsigned noSkipScan:1;   /* Do not try to use skip-scan if true */
 12.3945 +  unsigned hasStat1:1;     /* aiRowLogEst values come from sqlite_stat1 */
 12.3946  #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
 12.3947    int nSample;             /* Number of elements in aSample[] */
 12.3948    int nSampleCol;          /* Size of IndexSample.anEq[] and so on */
 12.3949 @@ -14696,9 +15124,11 @@
 12.3950    int iTable;            /* TK_COLUMN: cursor number of table holding column
 12.3951                           ** TK_REGISTER: register number
 12.3952                           ** TK_TRIGGER: 1 -> new, 0 -> old
 12.3953 -                         ** EP_Unlikely:  134217728 times likelihood */
 12.3954 +                         ** EP_Unlikely:  134217728 times likelihood
 12.3955 +                         ** TK_SELECT: 1st register of result vector */
 12.3956    ynVar iColumn;         /* TK_COLUMN: column index.  -1 for rowid.
 12.3957 -                         ** TK_VARIABLE: variable number (always >= 1). */
 12.3958 +                         ** TK_VARIABLE: variable number (always >= 1).
 12.3959 +                         ** TK_SELECT_COLUMN: column of the result vector */
 12.3960    i16 iAgg;              /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
 12.3961    i16 iRightJoinTable;   /* If EP_FromJoin, the right table of the join */
 12.3962    u8 op2;                /* TK_REGISTER: original value of Expr.op
 12.3963 @@ -14734,6 +15164,7 @@
 12.3964  #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
 12.3965  #define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
 12.3966  #define EP_Alias     0x400000 /* Is an alias for a result set column */
 12.3967 +#define EP_Leaf      0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
 12.3968  
 12.3969  /*
 12.3970  ** Combinations of two or more EP_* flags
 12.3971 @@ -14792,8 +15223,9 @@
 12.3972  */
 12.3973  struct ExprList {
 12.3974    int nExpr;             /* Number of expressions on the list */
 12.3975 +  int nAlloc;            /* Number of a[] slots allocated */
 12.3976    struct ExprList_item { /* For each expression in the list */
 12.3977 -    Expr *pExpr;            /* The list of expressions */
 12.3978 +    Expr *pExpr;            /* The parse tree for this expression */
 12.3979      char *zName;            /* Token associated with this expression */
 12.3980      char *zSpan;            /* Original text of the expression */
 12.3981      u8 sortOrder;           /* 1 for DESC or 0 for ASC */
 12.3982 @@ -14807,7 +15239,7 @@
 12.3983        } x;
 12.3984        int iConstExprReg;      /* Register in which Expr value is cached */
 12.3985      } u;
 12.3986 -  } *a;                  /* Alloc a power of two greater or equal to nExpr */
 12.3987 +  } a[1];                  /* One slot for each expression in the list */
 12.3988  };
 12.3989  
 12.3990  /*
 12.3991 @@ -14902,7 +15334,7 @@
 12.3992      int regReturn;    /* Register holding return address of addrFillSub */
 12.3993      int regResult;    /* Registers holding results of a co-routine */
 12.3994      struct {
 12.3995 -      u8 jointype;      /* Type of join between this able and the previous */
 12.3996 +      u8 jointype;      /* Type of join between this table and the previous */
 12.3997        unsigned notIndexed :1;    /* True if there is a NOT INDEXED clause */
 12.3998        unsigned isIndexedBy :1;   /* True if there is an INDEXED BY clause */
 12.3999        unsigned isTabFunc :1;     /* True if table-valued-function syntax */
 12.4000 @@ -14948,19 +15380,20 @@
 12.4001  #define WHERE_ORDERBY_MIN      0x0001 /* ORDER BY processing for min() func */
 12.4002  #define WHERE_ORDERBY_MAX      0x0002 /* ORDER BY processing for max() func */
 12.4003  #define WHERE_ONEPASS_DESIRED  0x0004 /* Want to do one-pass UPDATE/DELETE */
 12.4004 -#define WHERE_DUPLICATES_OK    0x0008 /* Ok to return a row more than once */
 12.4005 -#define WHERE_OMIT_OPEN_CLOSE  0x0010 /* Table cursors are already open */
 12.4006 -#define WHERE_FORCE_TABLE      0x0020 /* Do not use an index-only search */
 12.4007 -#define WHERE_ONETABLE_ONLY    0x0040 /* Only code the 1st table in pTabList */
 12.4008 -#define WHERE_NO_AUTOINDEX     0x0080 /* Disallow automatic indexes */
 12.4009 -#define WHERE_GROUPBY          0x0100 /* pOrderBy is really a GROUP BY */
 12.4010 -#define WHERE_DISTINCTBY       0x0200 /* pOrderby is really a DISTINCT clause */
 12.4011 -#define WHERE_WANT_DISTINCT    0x0400 /* All output needs to be distinct */
 12.4012 -#define WHERE_SORTBYGROUP      0x0800 /* Support sqlite3WhereIsSorted() */
 12.4013 -#define WHERE_REOPEN_IDX       0x1000 /* Try to use OP_ReopenIdx */
 12.4014 -#define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */
 12.4015 -#define WHERE_USE_LIMIT        0x4000 /* There is a constant LIMIT clause */
 12.4016 -#define WHERE_SEEK_TABLE       0x8000 /* Do not defer seeks on main table */
 12.4017 +#define WHERE_ONEPASS_MULTIROW 0x0008 /* ONEPASS is ok with multiple rows */
 12.4018 +#define WHERE_DUPLICATES_OK    0x0010 /* Ok to return a row more than once */
 12.4019 +#define WHERE_OR_SUBCLAUSE     0x0020 /* Processing a sub-WHERE as part of
 12.4020 +                                      ** the OR optimization  */
 12.4021 +#define WHERE_GROUPBY          0x0040 /* pOrderBy is really a GROUP BY */
 12.4022 +#define WHERE_DISTINCTBY       0x0080 /* pOrderby is really a DISTINCT clause */
 12.4023 +#define WHERE_WANT_DISTINCT    0x0100 /* All output needs to be distinct */
 12.4024 +#define WHERE_SORTBYGROUP      0x0200 /* Support sqlite3WhereIsSorted() */
 12.4025 +#define WHERE_SEEK_TABLE       0x0400 /* Do not defer seeks on main table */
 12.4026 +#define WHERE_ORDERBY_LIMIT    0x0800 /* ORDERBY+LIMIT on the inner loop */
 12.4027 +#define WHERE_SEEK_UNIQ_TABLE  0x1000 /* Do not defer seeks if unique */
 12.4028 +                        /*     0x2000    not currently used */
 12.4029 +#define WHERE_USE_LIMIT        0x4000 /* Use the LIMIT in cost estimates */
 12.4030 +                        /*     0x8000    not currently used */
 12.4031  
 12.4032  /* Allowed return values from sqlite3WhereIsDistinct()
 12.4033  */
 12.4034 @@ -15178,7 +15611,7 @@
 12.4035  */
 12.4036  struct SelectDest {
 12.4037    u8 eDest;            /* How to dispose of the results.  On of SRT_* above. */
 12.4038 -  char affSdst;        /* Affinity used when eDest==SRT_Set */
 12.4039 +  char *zAffSdst;      /* Affinity used when eDest==SRT_Set */
 12.4040    int iSDParm;         /* A parameter used by the eDest disposal method */
 12.4041    int iSdst;           /* Base register where results are written */
 12.4042    int nSdst;           /* Number of registers allocated */
 12.4043 @@ -15284,36 +15717,23 @@
 12.4044    u8 okConstFactor;    /* OK to factor out constants */
 12.4045    u8 disableLookaside; /* Number of times lookaside has been disabled */
 12.4046    u8 nColCache;        /* Number of entries in aColCache[] */
 12.4047 -  int aTempReg[8];     /* Holding area for temporary registers */
 12.4048    int nRangeReg;       /* Size of the temporary register block */
 12.4049    int iRangeReg;       /* First register in temporary register block */
 12.4050    int nErr;            /* Number of errors seen */
 12.4051    int nTab;            /* Number of previously allocated VDBE cursors */
 12.4052    int nMem;            /* Number of memory cells used so far */
 12.4053 -  int nSet;            /* Number of sets used so far */
 12.4054 -  int nOnce;           /* Number of OP_Once instructions so far */
 12.4055    int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */
 12.4056    int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
 12.4057 -  int iFixedOp;        /* Never back out opcodes iFixedOp-1 or earlier */
 12.4058    int ckBase;          /* Base register of data during check constraints */
 12.4059    int iSelfTab;        /* Table of an index whose exprs are being coded */
 12.4060    int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
 12.4061    int iCacheCnt;       /* Counter used to generate aColCache[].lru values */
 12.4062    int nLabel;          /* Number of labels used */
 12.4063    int *aLabel;         /* Space to hold the labels */
 12.4064 -  struct yColCache {
 12.4065 -    int iTable;           /* Table cursor number */
 12.4066 -    i16 iColumn;          /* Table column number */
 12.4067 -    u8 tempReg;           /* iReg is a temp register that needs to be freed */
 12.4068 -    int iLevel;           /* Nesting level */
 12.4069 -    int iReg;             /* Reg with value of this column. 0 means none. */
 12.4070 -    int lru;              /* Least recently used entry has the smallest value */
 12.4071 -  } aColCache[SQLITE_N_COLCACHE];  /* One for each column cache entry */
 12.4072    ExprList *pConstExpr;/* Constant expressions */
 12.4073    Token constraintName;/* Name of the constraint currently being parsed */
 12.4074    yDbMask writeMask;   /* Start a write transaction on these databases */
 12.4075    yDbMask cookieMask;  /* Bitmask of schema verified databases */
 12.4076 -  int cookieValue[SQLITE_MAX_ATTACHED+2];  /* Values of cookies to verify */
 12.4077    int regRowid;        /* Register holding rowid of CREATE TABLE entry */
 12.4078    int regRoot;         /* Register holding root page number for new objects */
 12.4079    int nMaxArg;         /* Max args passed to user function by sub-program */
 12.4080 @@ -15326,8 +15746,6 @@
 12.4081    TableLock *aTableLock; /* Required table locks for shared-cache mode */
 12.4082  #endif
 12.4083    AutoincInfo *pAinc;  /* Information about AUTOINCREMENT counters */
 12.4084 -
 12.4085 -  /* Information used while coding trigger programs. */
 12.4086    Parse *pToplevel;    /* Parse structure for main program (or NULL) */
 12.4087    Table *pTriggerTab;  /* Table triggers are being coded for */
 12.4088    int addrCrTab;       /* Address of OP_CreateTable opcode on CREATE TABLE */
 12.4089 @@ -15338,35 +15756,50 @@
 12.4090    u8 eOrconf;          /* Default ON CONFLICT policy for trigger steps */
 12.4091    u8 disableTriggers;  /* True to disable triggers */
 12.4092  
 12.4093 +  /**************************************************************************
 12.4094 +  ** Fields above must be initialized to zero.  The fields that follow,
 12.4095 +  ** down to the beginning of the recursive section, do not need to be
 12.4096 +  ** initialized as they will be set before being used.  The boundary is
 12.4097 +  ** determined by offsetof(Parse,aColCache).
 12.4098 +  **************************************************************************/
 12.4099 +
 12.4100 +  struct yColCache {
 12.4101 +    int iTable;           /* Table cursor number */
 12.4102 +    i16 iColumn;          /* Table column number */
 12.4103 +    u8 tempReg;           /* iReg is a temp register that needs to be freed */
 12.4104 +    int iLevel;           /* Nesting level */
 12.4105 +    int iReg;             /* Reg with value of this column. 0 means none. */
 12.4106 +    int lru;              /* Least recently used entry has the smallest value */
 12.4107 +  } aColCache[SQLITE_N_COLCACHE];  /* One for each column cache entry */
 12.4108 +  int aTempReg[8];        /* Holding area for temporary registers */
 12.4109 +  Token sNameToken;       /* Token with unqualified schema object name */
 12.4110 +
 12.4111    /************************************************************************
 12.4112    ** Above is constant between recursions.  Below is reset before and after
 12.4113    ** each recursion.  The boundary between these two regions is determined
 12.4114 -  ** using offsetof(Parse,nVar) so the nVar field must be the first field
 12.4115 -  ** in the recursive region.
 12.4116 +  ** using offsetof(Parse,sLastToken) so the sLastToken field must be the
 12.4117 +  ** first field in the recursive region.
 12.4118    ************************************************************************/
 12.4119  
 12.4120 +  Token sLastToken;       /* The last token parsed */
 12.4121    ynVar nVar;               /* Number of '?' variables seen in the SQL so far */
 12.4122 -  int nzVar;                /* Number of available slots in azVar[] */
 12.4123    u8 iPkSortOrder;          /* ASC or DESC for INTEGER PRIMARY KEY */
 12.4124    u8 explain;               /* True if the EXPLAIN flag is found on the query */
 12.4125  #ifndef SQLITE_OMIT_VIRTUALTABLE
 12.4126    u8 declareVtab;           /* True if inside sqlite3_declare_vtab() */
 12.4127    int nVtabLock;            /* Number of virtual tables to lock */
 12.4128  #endif
 12.4129 -  int nAlias;               /* Number of aliased result set columns */
 12.4130    int nHeight;              /* Expression tree height of current sub-select */
 12.4131  #ifndef SQLITE_OMIT_EXPLAIN
 12.4132    int iSelectId;            /* ID of current select for EXPLAIN output */
 12.4133    int iNextSelectId;        /* Next available select ID for EXPLAIN output */
 12.4134  #endif
 12.4135 -  char **azVar;             /* Pointers to names of parameters */
 12.4136 +  VList *pVList;            /* Mapping between variable names and numbers */
 12.4137    Vdbe *pReprepare;         /* VM being reprepared (sqlite3Reprepare()) */
 12.4138    const char *zTail;        /* All SQL text past the last semicolon parsed */
 12.4139    Table *pNewTable;         /* A table being constructed by CREATE TABLE */
 12.4140    Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */
 12.4141    const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
 12.4142 -  Token sNameToken;         /* Token with unqualified schema object name */
 12.4143 -  Token sLastToken;         /* The last token parsed */
 12.4144  #ifndef SQLITE_OMIT_VIRTUALTABLE
 12.4145    Token sArg;               /* Complete text of a module argument */
 12.4146    Table **apVtabLock;       /* Pointer to virtual tables needing locking */
 12.4147 @@ -15378,6 +15811,14 @@
 12.4148  };
 12.4149  
 12.4150  /*
 12.4151 +** Sizes and pointers of various parts of the Parse object.
 12.4152 +*/
 12.4153 +#define PARSE_HDR_SZ offsetof(Parse,aColCache) /* Recursive part w/o aColCache*/
 12.4154 +#define PARSE_RECURSE_SZ offsetof(Parse,sLastToken)    /* Recursive part */
 12.4155 +#define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
 12.4156 +#define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ)  /* Pointer to tail */
 12.4157 +
 12.4158 +/*
 12.4159  ** Return true if currently inside an sqlite3_declare_vtab() call.
 12.4160  */
 12.4161  #ifdef SQLITE_OMIT_VIRTUALTABLE
 12.4162 @@ -15410,13 +15851,11 @@
 12.4163  #define OPFLAG_NCHANGE       0x01    /* OP_Insert: Set to update db->nChange */
 12.4164                                       /* Also used in P2 (not P5) of OP_Delete */
 12.4165  #define OPFLAG_EPHEM         0x01    /* OP_Column: Ephemeral output is ok */
 12.4166 -#define OPFLAG_LASTROWID     0x02    /* Set to update db->lastRowid */
 12.4167 +#define OPFLAG_LASTROWID     0x20    /* Set to update db->lastRowid */
 12.4168  #define OPFLAG_ISUPDATE      0x04    /* This OP_Insert is an sql UPDATE */
 12.4169  #define OPFLAG_APPEND        0x08    /* This is likely to be an append */
 12.4170  #define OPFLAG_USESEEKRESULT 0x10    /* Try to avoid a seek in BtreeInsert() */
 12.4171 -#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
 12.4172  #define OPFLAG_ISNOOP        0x40    /* OP_Delete does pre-update-hook only */
 12.4173 -#endif
 12.4174  #define OPFLAG_LENGTHARG     0x40    /* OP_Column only used for length() */
 12.4175  #define OPFLAG_TYPEOFARG     0x80    /* OP_Column only used for typeof() */
 12.4176  #define OPFLAG_BULKCSR       0x01    /* OP_Open** used to open bulk cursor */
 12.4177 @@ -15424,7 +15863,7 @@
 12.4178  #define OPFLAG_FORDELETE     0x08    /* OP_Open should use BTREE_FORDELETE */
 12.4179  #define OPFLAG_P2ISREG       0x10    /* P2 to OP_Open** is a register number */
 12.4180  #define OPFLAG_PERMUTE       0x01    /* OP_Compare: use the permutation */
 12.4181 -#define OPFLAG_SAVEPOSITION  0x02    /* OP_Delete: keep cursor position */
 12.4182 +#define OPFLAG_SAVEPOSITION  0x02    /* OP_Delete/Insert: save cursor pos */
 12.4183  #define OPFLAG_AUXDELETE     0x04    /* OP_Delete: index in a DELETE op */
 12.4184  
 12.4185  /*
 12.4186 @@ -15621,10 +16060,11 @@
 12.4187    void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx);  /* Callback */
 12.4188    void *pVdbeBranchArg;                                     /* 1st argument */
 12.4189  #endif
 12.4190 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.4191 +#ifndef SQLITE_UNTESTABLE
 12.4192    int (*xTestCallback)(int);        /* Invoked by sqlite3FaultSim() */
 12.4193  #endif
 12.4194    int bLocaltimeFault;              /* True to fail localtime() calls */
 12.4195 +  int iOnceResetThreshold;          /* When to reset OP_Once counters */
 12.4196  };
 12.4197  
 12.4198  /*
 12.4199 @@ -15656,13 +16096,17 @@
 12.4200    int walkerDepth;                          /* Number of subqueries */
 12.4201    u8 eCode;                                 /* A small processing code */
 12.4202    union {                                   /* Extra data for callback */
 12.4203 -    NameContext *pNC;                          /* Naming context */
 12.4204 -    int n;                                     /* A counter */
 12.4205 -    int iCur;                                  /* A cursor number */
 12.4206 -    SrcList *pSrcList;                         /* FROM clause */
 12.4207 -    struct SrcCount *pSrcCount;                /* Counting column references */
 12.4208 -    struct CCurHint *pCCurHint;                /* Used by codeCursorHint() */
 12.4209 -    int *aiCol;                                /* array of column indexes */
 12.4210 +    NameContext *pNC;                         /* Naming context */
 12.4211 +    int n;                                    /* A counter */
 12.4212 +    int iCur;                                 /* A cursor number */
 12.4213 +    SrcList *pSrcList;                        /* FROM clause */
 12.4214 +    struct SrcCount *pSrcCount;               /* Counting column references */
 12.4215 +    struct CCurHint *pCCurHint;               /* Used by codeCursorHint() */
 12.4216 +    int *aiCol;                               /* array of column indexes */
 12.4217 +    struct IdxCover *pIdxCover;               /* Check for index coverage */
 12.4218 +    struct IdxExprTrans *pIdxTrans;           /* Convert indexed expr to column */
 12.4219 +    ExprList *pGroupBy;                       /* GROUP BY clause */
 12.4220 +    struct HavingToWhereCtx *pHavingCtx;      /* HAVING to WHERE clause ctx */
 12.4221    } u;
 12.4222  };
 12.4223  
 12.4224 @@ -15816,6 +16260,7 @@
 12.4225  SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
 12.4226  SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
 12.4227  SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
 12.4228 +SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
 12.4229  SQLITE_PRIVATE int sqlite3MallocSize(void*);
 12.4230  SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
 12.4231  SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
 12.4232 @@ -15823,7 +16268,7 @@
 12.4233  SQLITE_PRIVATE void *sqlite3PageMalloc(int);
 12.4234  SQLITE_PRIVATE void sqlite3PageFree(void*);
 12.4235  SQLITE_PRIVATE void sqlite3MemSetDefault(void);
 12.4236 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.4237 +#ifndef SQLITE_UNTESTABLE
 12.4238  SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
 12.4239  #endif
 12.4240  SQLITE_PRIVATE int sqlite3HeapNearlyFull(void);
 12.4241 @@ -15846,12 +16291,16 @@
 12.4242  # define sqlite3StackFree(D,P)       sqlite3DbFree(D,P)
 12.4243  #endif
 12.4244  
 12.4245 +/* Do not allow both MEMSYS5 and MEMSYS3 to be defined together.  If they
 12.4246 +** are, disable MEMSYS3
 12.4247 +*/
 12.4248 +#ifdef SQLITE_ENABLE_MEMSYS5
 12.4249 +SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
 12.4250 +#undef SQLITE_ENABLE_MEMSYS3
 12.4251 +#endif
 12.4252  #ifdef SQLITE_ENABLE_MEMSYS3
 12.4253  SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys3(void);
 12.4254  #endif
 12.4255 -#ifdef SQLITE_ENABLE_MEMSYS5
 12.4256 -SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
 12.4257 -#endif
 12.4258  
 12.4259  
 12.4260  #ifndef SQLITE_MUTEX_OMIT
 12.4261 @@ -15905,6 +16354,7 @@
 12.4262  
 12.4263  #if defined(SQLITE_DEBUG)
 12.4264  SQLITE_PRIVATE   void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
 12.4265 +SQLITE_PRIVATE   void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
 12.4266  SQLITE_PRIVATE   void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
 12.4267  SQLITE_PRIVATE   void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
 12.4268  SQLITE_PRIVATE   void sqlite3TreeViewWith(TreeView*, const With*, u8);
 12.4269 @@ -15929,13 +16379,14 @@
 12.4270  SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
 12.4271  SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
 12.4272  SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
 12.4273 -SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
 12.4274 +SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
 12.4275  SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
 12.4276  SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
 12.4277  SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
 12.4278 -SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
 12.4279 +SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
 12.4280  SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
 12.4281  SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
 12.4282 +SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
 12.4283  SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
 12.4284  SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
 12.4285  SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
 12.4286 @@ -15944,6 +16395,9 @@
 12.4287  SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
 12.4288  SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
 12.4289  SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
 12.4290 +#ifndef SQLITE_OMIT_VIRTUALTABLE
 12.4291 +SQLITE_PRIVATE Module *sqlite3PragmaVtabRegister(sqlite3*,const char *zName);
 12.4292 +#endif
 12.4293  SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
 12.4294  SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
 12.4295  SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
 12.4296 @@ -15971,9 +16425,8 @@
 12.4297  SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
 12.4298                      sqlite3_vfs**,char**,char **);
 12.4299  SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
 12.4300 -SQLITE_PRIVATE int sqlite3CodeOnce(Parse *);
 12.4301 -
 12.4302 -#ifdef SQLITE_OMIT_BUILTIN_TEST
 12.4303 +
 12.4304 +#ifdef SQLITE_UNTESTABLE
 12.4305  # define sqlite3FaultSim(X) SQLITE_OK
 12.4306  #else
 12.4307  SQLITE_PRIVATE   int sqlite3FaultSim(int);
 12.4308 @@ -15986,7 +16439,7 @@
 12.4309  SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*);
 12.4310  SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*);
 12.4311  SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec*);
 12.4312 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.4313 +#ifndef SQLITE_UNTESTABLE
 12.4314  SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int,int*);
 12.4315  #endif
 12.4316  
 12.4317 @@ -16033,8 +16486,8 @@
 12.4318  SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
 12.4319  SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
 12.4320  SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**);
 12.4321 -SQLITE_PRIVATE Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
 12.4322 -                          Expr*, int, int);
 12.4323 +SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
 12.4324 +                          Expr*, int, int, u8);
 12.4325  SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int);
 12.4326  SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*);
 12.4327  SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList*,
 12.4328 @@ -16053,6 +16506,7 @@
 12.4329  SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
 12.4330  SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
 12.4331  SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
 12.4332 +SQLITE_PRIVATE int sqlite3WhereOrderedInnerLoop(WhereInfo*);
 12.4333  SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
 12.4334  SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
 12.4335  SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
 12.4336 @@ -16074,7 +16528,7 @@
 12.4337  SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
 12.4338  SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
 12.4339  SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
 12.4340 -SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
 12.4341 +SQLITE_PRIVATE int sqlite3ExprCodeAtInit(Parse*, Expr*, int);
 12.4342  SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
 12.4343  SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
 12.4344  SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
 12.4345 @@ -16082,26 +16536,31 @@
 12.4346  #define SQLITE_ECEL_DUP      0x01  /* Deep, not shallow copies */
 12.4347  #define SQLITE_ECEL_FACTOR   0x02  /* Factor out constant terms */
 12.4348  #define SQLITE_ECEL_REF      0x04  /* Use ExprList.u.x.iOrderByCol */
 12.4349 +#define SQLITE_ECEL_OMITREF  0x08  /* Omit if ExprList.u.x.iOrderByCol */
 12.4350  SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
 12.4351  SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
 12.4352  SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
 12.4353  SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
 12.4354 -SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
 12.4355 -SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
 12.4356 +#define LOCATE_VIEW    0x01
 12.4357 +#define LOCATE_NOERR   0x02
 12.4358 +SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
 12.4359 +SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
 12.4360  SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
 12.4361  SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
 12.4362  SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
 12.4363 -SQLITE_PRIVATE void sqlite3Vacuum(Parse*);
 12.4364 -SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*);
 12.4365 +SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*);
 12.4366 +SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int);
 12.4367  SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
 12.4368  SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int);
 12.4369 +SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
 12.4370  SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
 12.4371  SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int);
 12.4372  SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
 12.4373  SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
 12.4374 +SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
 12.4375  SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
 12.4376  SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
 12.4377 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.4378 +#ifndef SQLITE_UNTESTABLE
 12.4379  SQLITE_PRIVATE void sqlite3PrngSaveState(void);
 12.4380  SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
 12.4381  #endif
 12.4382 @@ -16117,6 +16576,7 @@
 12.4383  SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
 12.4384  SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
 12.4385  SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
 12.4386 +SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
 12.4387  SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
 12.4388  #ifdef SQLITE_ENABLE_CURSOR_HINTS
 12.4389  SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
 12.4390 @@ -16132,6 +16592,11 @@
 12.4391  SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int);
 12.4392  SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
 12.4393                                       u8,u8,int,int*,int*);
 12.4394 +#ifdef SQLITE_ENABLE_NULL_TRIM
 12.4395 +SQLITE_PRIVATE   void sqlite3SetMakeRecordP5(Vdbe*,Table*);
 12.4396 +#else
 12.4397 +# define sqlite3SetMakeRecordP5(A,B)
 12.4398 +#endif
 12.4399  SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
 12.4400  SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*);
 12.4401  SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
 12.4402 @@ -16238,6 +16703,9 @@
 12.4403      defined(SQLITE_EXPLAIN_ESTIMATED_ROWS)
 12.4404  SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst);
 12.4405  #endif
 12.4406 +SQLITE_PRIVATE VList *sqlite3VListAdd(sqlite3*,VList*,const char*,int,int);
 12.4407 +SQLITE_PRIVATE const char *sqlite3VListNumToName(VList*,int);
 12.4408 +SQLITE_PRIVATE int sqlite3VListNameToNum(VList*,const char*,int);
 12.4409  
 12.4410  /*
 12.4411  ** Routines to read and write variable-length integers.  These used to
 12.4412 @@ -16267,6 +16735,7 @@
 12.4413  SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
 12.4414  SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
 12.4415  SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
 12.4416 +SQLITE_PRIVATE char sqlite3TableColumnAffinity(Table*,int);
 12.4417  SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
 12.4418  SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
 12.4419  SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
 12.4420 @@ -16332,7 +16801,7 @@
 12.4421  SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
 12.4422  SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
 12.4423  SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*);
 12.4424 -SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *, int, int);
 12.4425 +SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr *, int, int);
 12.4426  SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
 12.4427  SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
 12.4428  SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
 12.4429 @@ -16387,19 +16856,29 @@
 12.4430  SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *);
 12.4431  SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
 12.4432  
 12.4433 +#ifndef SQLITE_OMIT_SUBQUERY
 12.4434 +SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse*, Expr*);
 12.4435 +#else
 12.4436 +# define sqlite3ExprCheckIN(x,y) SQLITE_OK
 12.4437 +#endif
 12.4438 +
 12.4439  #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
 12.4440  SQLITE_PRIVATE void sqlite3AnalyzeFunctions(void);
 12.4441 -SQLITE_PRIVATE int sqlite3Stat4ProbeSetValue(Parse*,Index*,UnpackedRecord**,Expr*,u8,int,int*);
 12.4442 +SQLITE_PRIVATE int sqlite3Stat4ProbeSetValue(
 12.4443 +    Parse*,Index*,UnpackedRecord**,Expr*,int,int,int*);
 12.4444  SQLITE_PRIVATE int sqlite3Stat4ValueFromExpr(Parse*, Expr*, u8, sqlite3_value**);
 12.4445  SQLITE_PRIVATE void sqlite3Stat4ProbeFree(UnpackedRecord*);
 12.4446  SQLITE_PRIVATE int sqlite3Stat4Column(sqlite3*, const void*, int, int, sqlite3_value**);
 12.4447 +SQLITE_PRIVATE char sqlite3IndexColumnAffinity(sqlite3*, Index*, int);
 12.4448  #endif
 12.4449  
 12.4450  /*
 12.4451  ** The interface to the LEMON-generated parser
 12.4452  */
 12.4453 -SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64));
 12.4454 -SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
 12.4455 +#ifndef SQLITE_AMALGAMATION
 12.4456 +SQLITE_PRIVATE   void *sqlite3ParserAlloc(void*(*)(u64));
 12.4457 +SQLITE_PRIVATE   void sqlite3ParserFree(void*, void(*)(void*));
 12.4458 +#endif
 12.4459  SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
 12.4460  #ifdef YYTRACKMAXSTACKDEPTH
 12.4461  SQLITE_PRIVATE   int sqlite3ParserStackPeak(void*);
 12.4462 @@ -16445,6 +16924,13 @@
 12.4463  SQLITE_PRIVATE    int sqlite3VtabSavepoint(sqlite3 *, int, int);
 12.4464  SQLITE_PRIVATE    void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
 12.4465  SQLITE_PRIVATE    VTable *sqlite3GetVTable(sqlite3*, Table*);
 12.4466 +SQLITE_PRIVATE    Module *sqlite3VtabCreateModule(
 12.4467 +     sqlite3*,
 12.4468 +     const char*,
 12.4469 +     const sqlite3_module*,
 12.4470 +     void*,
 12.4471 +     void(*)(void*)
 12.4472 +   );
 12.4473  #  define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
 12.4474  #endif
 12.4475  SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
 12.4476 @@ -16502,6 +16988,7 @@
 12.4477    #define sqlite3FkDropTable(a,b,c)
 12.4478    #define sqlite3FkOldmask(a,b)         0
 12.4479    #define sqlite3FkRequired(a,b,c,d)    0
 12.4480 +  #define sqlite3FkReferences(a)        0
 12.4481  #endif
 12.4482  #ifndef SQLITE_OMIT_FOREIGN_KEY
 12.4483  SQLITE_PRIVATE   void sqlite3FkDelete(sqlite3 *, Table*);
 12.4484 @@ -16520,10 +17007,10 @@
 12.4485  
 12.4486  /*
 12.4487  ** The interface to the code in fault.c used for identifying "benign"
 12.4488 -** malloc failures. This is only present if SQLITE_OMIT_BUILTIN_TEST
 12.4489 +** malloc failures. This is only present if SQLITE_UNTESTABLE
 12.4490  ** is not defined.
 12.4491  */
 12.4492 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.4493 +#ifndef SQLITE_UNTESTABLE
 12.4494  SQLITE_PRIVATE   void sqlite3BeginBenignMalloc(void);
 12.4495  SQLITE_PRIVATE   void sqlite3EndBenignMalloc(void);
 12.4496  #else
 12.4497 @@ -16545,7 +17032,7 @@
 12.4498  #define IN_INDEX_NOOP_OK     0x0001  /* OK to return IN_INDEX_NOOP */
 12.4499  #define IN_INDEX_MEMBERSHIP  0x0002  /* IN operator used for membership test */
 12.4500  #define IN_INDEX_LOOP        0x0004  /* IN operator used as a loop */
 12.4501 -SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*);
 12.4502 +SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*);
 12.4503  
 12.4504  SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
 12.4505  SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
 12.4506 @@ -16650,7 +17137,13 @@
 12.4507  SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3*);
 12.4508  #endif
 12.4509  
 12.4510 -#endif /* _SQLITEINT_H_ */
 12.4511 +SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr);
 12.4512 +SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr);
 12.4513 +SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr*, int);
 12.4514 +SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int);
 12.4515 +SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*);
 12.4516 +
 12.4517 +#endif /* SQLITEINT_H */
 12.4518  
 12.4519  /************** End of sqliteInt.h *******************************************/
 12.4520  /************** Begin file global.c ******************************************/
 12.4521 @@ -16735,16 +17228,13 @@
 12.4522  **
 12.4523  **   (x & ~(map[x]&0x20))
 12.4524  **
 12.4525 -** Standard function tolower() is implemented using the sqlite3UpperToLower[]
 12.4526 +** The equivalent of tolower() is implemented using the sqlite3UpperToLower[]
 12.4527  ** array. tolower() is used more often than toupper() by SQLite.
 12.4528  **
 12.4529 -** Bit 0x40 is set if the character non-alphanumeric and can be used in an 
 12.4530 +** Bit 0x40 is set if the character is non-alphanumeric and can be used in an 
 12.4531  ** SQLite identifier.  Identifiers are alphanumerics, "_", "$", and any
 12.4532  ** non-ASCII UTF character. Hence the test for whether or not a character is
 12.4533  ** part of an identifier is 0x46.
 12.4534 -**
 12.4535 -** SQLite's versions are identical to the standard versions assuming a
 12.4536 -** locale of "C". They are implemented as macros in sqliteInt.h.
 12.4537  */
 12.4538  #ifdef SQLITE_ASCII
 12.4539  SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
 12.4540 @@ -16796,9 +17286,16 @@
 12.4541  ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
 12.4542  ** disabled. The default value may be changed by compiling with the
 12.4543  ** SQLITE_USE_URI symbol defined.
 12.4544 +**
 12.4545 +** URI filenames are enabled by default if SQLITE_HAS_CODEC is
 12.4546 +** enabled.
 12.4547  */
 12.4548  #ifndef SQLITE_USE_URI
 12.4549 -# define  SQLITE_USE_URI 0
 12.4550 +# ifdef SQLITE_HAS_CODEC
 12.4551 +#  define SQLITE_USE_URI 1
 12.4552 +# else
 12.4553 +#  define SQLITE_USE_URI 0
 12.4554 +# endif
 12.4555  #endif
 12.4556  
 12.4557  /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
 12.4558 @@ -16817,7 +17314,7 @@
 12.4559  #endif
 12.4560  
 12.4561  /* Statement journals spill to disk when their size exceeds the following
 12.4562 -** threashold (in bytes). 0 means that statement journals are created and
 12.4563 +** threshold (in bytes). 0 means that statement journals are created and
 12.4564  ** written to disk immediately (the default behavior for SQLite versions
 12.4565  ** before 3.12.0).  -1 means always keep the entire statement journal in
 12.4566  ** memory.  (The statement journal is also always held entirely in memory
 12.4567 @@ -16829,6 +17326,19 @@
 12.4568  #endif
 12.4569  
 12.4570  /*
 12.4571 +** The default lookaside-configuration, the format "SZ,N".  SZ is the
 12.4572 +** number of bytes in each lookaside slot (should be a multiple of 8)
 12.4573 +** and N is the number of slots.  The lookaside-configuration can be
 12.4574 +** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
 12.4575 +** or at run-time for an individual database connection using
 12.4576 +** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
 12.4577 +*/
 12.4578 +#ifndef SQLITE_DEFAULT_LOOKASIDE
 12.4579 +# define SQLITE_DEFAULT_LOOKASIDE 1200,100
 12.4580 +#endif
 12.4581 +
 12.4582 +
 12.4583 +/*
 12.4584  ** The following singleton contains the global configuration for
 12.4585  ** the SQLite library.
 12.4586  */
 12.4587 @@ -16840,8 +17350,7 @@
 12.4588     SQLITE_ALLOW_COVERING_INDEX_SCAN,   /* bUseCis */
 12.4589     0x7ffffffe,                /* mxStrlen */
 12.4590     0,                         /* neverCorrupt */
 12.4591 -   128,                       /* szLookaside */
 12.4592 -   500,                       /* nLookaside */
 12.4593 +   SQLITE_DEFAULT_LOOKASIDE,  /* szLookaside, nLookaside */
 12.4594     SQLITE_STMTJRNL_SPILL,     /* nStmtSpill */
 12.4595     {0,0,0,0,0,0,0,0},         /* m */
 12.4596     {0,0,0,0,0,0,0,0,0},       /* mutex */
 12.4597 @@ -16878,10 +17387,11 @@
 12.4598     0,                         /* xVdbeBranch */
 12.4599     0,                         /* pVbeBranchArg */
 12.4600  #endif
 12.4601 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.4602 +#ifndef SQLITE_UNTESTABLE
 12.4603     0,                         /* xTestCallback */
 12.4604  #endif
 12.4605 -   0                          /* bLocaltimeFault */
 12.4606 +   0,                         /* bLocaltimeFault */
 12.4607 +   0x7ffffffe                 /* iOnceResetThreshold */
 12.4608  };
 12.4609  
 12.4610  /*
 12.4611 @@ -16904,7 +17414,7 @@
 12.4612  ** The value of the "pending" byte must be 0x40000000 (1 byte past the
 12.4613  ** 1-gibabyte boundary) in a compatible database.  SQLite never uses
 12.4614  ** the database page that contains the pending byte.  It never attempts
 12.4615 -** to read or write that page.  The pending byte page is set assign
 12.4616 +** to read or write that page.  The pending byte page is set aside
 12.4617  ** for use by the VFS layers as space for managing file locks.
 12.4618  **
 12.4619  ** During testing, it is often desirable to move the pending byte to
 12.4620 @@ -16985,10 +17495,19 @@
 12.4621  #if SQLITE_CHECK_PAGES
 12.4622    "CHECK_PAGES",
 12.4623  #endif
 12.4624 +#if defined(__clang__) && defined(__clang_major__)
 12.4625 +  "COMPILER=clang-" CTIMEOPT_VAL(__clang_major__) "."
 12.4626 +                    CTIMEOPT_VAL(__clang_minor__) "."
 12.4627 +                    CTIMEOPT_VAL(__clang_patchlevel__),
 12.4628 +#elif defined(_MSC_VER)
 12.4629 +  "COMPILER=msvc-" CTIMEOPT_VAL(_MSC_VER),
 12.4630 +#elif defined(__GNUC__) && defined(__VERSION__)
 12.4631 +  "COMPILER=gcc-" __VERSION__,
 12.4632 +#endif
 12.4633  #if SQLITE_COVERAGE_TEST
 12.4634    "COVERAGE_TEST",
 12.4635  #endif
 12.4636 -#if SQLITE_DEBUG
 12.4637 +#ifdef SQLITE_DEBUG
 12.4638    "DEBUG",
 12.4639  #endif
 12.4640  #if SQLITE_DEFAULT_LOCKING_MODE
 12.4641 @@ -16997,6 +17516,15 @@
 12.4642  #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc)
 12.4643    "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
 12.4644  #endif
 12.4645 +#if SQLITE_DEFAULT_SYNCHRONOUS
 12.4646 +  "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS),
 12.4647 +#endif
 12.4648 +#if SQLITE_DEFAULT_WAL_SYNCHRONOUS
 12.4649 +  "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS),
 12.4650 +#endif
 12.4651 +#if SQLITE_DIRECT_OVERFLOW_READ
 12.4652 +  "DIRECT_OVERFLOW_READ",
 12.4653 +#endif
 12.4654  #if SQLITE_DISABLE_DIRSYNC
 12.4655    "DISABLE_DIRSYNC",
 12.4656  #endif
 12.4657 @@ -17004,7 +17532,7 @@
 12.4658    "DISABLE_LFS",
 12.4659  #endif
 12.4660  #if SQLITE_ENABLE_8_3_NAMES
 12.4661 -  "ENABLE_8_3_NAMES",
 12.4662 +  "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES),
 12.4663  #endif
 12.4664  #if SQLITE_ENABLE_API_ARMOR
 12.4665    "ENABLE_API_ARMOR",
 12.4666 @@ -17083,6 +17611,9 @@
 12.4667  #if SQLITE_ENABLE_UPDATE_DELETE_LIMIT
 12.4668    "ENABLE_UPDATE_DELETE_LIMIT",
 12.4669  #endif
 12.4670 +#if defined(SQLITE_ENABLE_URI_00_ERROR)
 12.4671 +  "ENABLE_URI_00_ERROR",
 12.4672 +#endif
 12.4673  #if SQLITE_HAS_CODEC
 12.4674    "HAS_CODEC",
 12.4675  #endif
 12.4676 @@ -17158,9 +17689,6 @@
 12.4677  #if SQLITE_OMIT_BTREECOUNT
 12.4678    "OMIT_BTREECOUNT",
 12.4679  #endif
 12.4680 -#if SQLITE_OMIT_BUILTIN_TEST
 12.4681 -  "OMIT_BUILTIN_TEST",
 12.4682 -#endif
 12.4683  #if SQLITE_OMIT_CAST
 12.4684    "OMIT_CAST",
 12.4685  #endif
 12.4686 @@ -17323,6 +17851,9 @@
 12.4687  #if defined(SQLITE_THREADSAFE)
 12.4688    "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE),
 12.4689  #endif
 12.4690 +#if SQLITE_UNTESTABLE
 12.4691 +  "UNTESTABLE"
 12.4692 +#endif
 12.4693  #if SQLITE_USE_ALLOCA
 12.4694    "USE_ALLOCA",
 12.4695  #endif
 12.4696 @@ -17344,7 +17875,7 @@
 12.4697  ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
 12.4698  ** is not required for a match.
 12.4699  */
 12.4700 -SQLITE_API int SQLITE_STDCALL sqlite3_compileoption_used(const char *zOptName){
 12.4701 +SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
 12.4702    int i, n;
 12.4703  
 12.4704  #if SQLITE_ENABLE_API_ARMOR
 12.4705 @@ -17372,7 +17903,7 @@
 12.4706  ** Return the N-th compile-time option string.  If N is out of range,
 12.4707  ** return a NULL pointer.
 12.4708  */
 12.4709 -SQLITE_API const char *SQLITE_STDCALL sqlite3_compileoption_get(int N){
 12.4710 +SQLITE_API const char *sqlite3_compileoption_get(int N){
 12.4711    if( N>=0 && N<ArraySize(azCompileOpt) ){
 12.4712      return azCompileOpt[N];
 12.4713    }
 12.4714 @@ -17418,8 +17949,8 @@
 12.4715  ** 6000 lines long) it was split up into several smaller files and
 12.4716  ** this header information was factored out.
 12.4717  */
 12.4718 -#ifndef _VDBEINT_H_
 12.4719 -#define _VDBEINT_H_
 12.4720 +#ifndef SQLITE_VDBEINT_H
 12.4721 +#define SQLITE_VDBEINT_H
 12.4722  
 12.4723  /*
 12.4724  ** The maximum number of times that a statement will try to reparse
 12.4725 @@ -17455,9 +17986,6 @@
 12.4726  /* Opaque type used by code in vdbesort.c */
 12.4727  typedef struct VdbeSorter VdbeSorter;
 12.4728  
 12.4729 -/* Opaque type used by the explainer */
 12.4730 -typedef struct Explain Explain;
 12.4731 -
 12.4732  /* Elements of the linked list at Vdbe.pAuxData */
 12.4733  typedef struct AuxData AuxData;
 12.4734  
 12.4735 @@ -17479,58 +18007,67 @@
 12.4736  */
 12.4737  typedef struct VdbeCursor VdbeCursor;
 12.4738  struct VdbeCursor {
 12.4739 -  u8 eCurType;          /* One of the CURTYPE_* values above */
 12.4740 -  i8 iDb;               /* Index of cursor database in db->aDb[] (or -1) */
 12.4741 -  u8 nullRow;           /* True if pointing to a row with no data */
 12.4742 -  u8 deferredMoveto;    /* A call to sqlite3BtreeMoveto() is needed */
 12.4743 -  u8 isTable;           /* True for rowid tables.  False for indexes */
 12.4744 +  u8 eCurType;            /* One of the CURTYPE_* values above */
 12.4745 +  i8 iDb;                 /* Index of cursor database in db->aDb[] (or -1) */
 12.4746 +  u8 nullRow;             /* True if pointing to a row with no data */
 12.4747 +  u8 deferredMoveto;      /* A call to sqlite3BtreeMoveto() is needed */
 12.4748 +  u8 isTable;             /* True for rowid tables.  False for indexes */
 12.4749  #ifdef SQLITE_DEBUG
 12.4750 -  u8 seekOp;            /* Most recent seek operation on this cursor */
 12.4751 -  u8 wrFlag;            /* The wrFlag argument to sqlite3BtreeCursor() */
 12.4752 -#endif
 12.4753 -  Bool isEphemeral:1;   /* True for an ephemeral table */
 12.4754 -  Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
 12.4755 -  Bool isOrdered:1;     /* True if the table is not BTREE_UNORDERED */
 12.4756 -  Pgno pgnoRoot;        /* Root page of the open btree cursor */
 12.4757 -  i16 nField;           /* Number of fields in the header */
 12.4758 -  u16 nHdrParsed;       /* Number of header fields parsed so far */
 12.4759 +  u8 seekOp;              /* Most recent seek operation on this cursor */
 12.4760 +  u8 wrFlag;              /* The wrFlag argument to sqlite3BtreeCursor() */
 12.4761 +#endif
 12.4762 +  Bool isEphemeral:1;     /* True for an ephemeral table */
 12.4763 +  Bool useRandomRowid:1;  /* Generate new record numbers semi-randomly */
 12.4764 +  Bool isOrdered:1;       /* True if the table is not BTREE_UNORDERED */
 12.4765 +  Btree *pBtx;            /* Separate file holding temporary table */
 12.4766 +  i64 seqCount;           /* Sequence counter */
 12.4767 +  int *aAltMap;           /* Mapping from table to index column numbers */
 12.4768 +
 12.4769 +  /* Cached OP_Column parse information is only valid if cacheStatus matches
 12.4770 +  ** Vdbe.cacheCtr.  Vdbe.cacheCtr will never take on the value of
 12.4771 +  ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
 12.4772 +  ** the cache is out of date. */
 12.4773 +  u32 cacheStatus;        /* Cache is valid if this matches Vdbe.cacheCtr */
 12.4774 +  int seekResult;         /* Result of previous sqlite3BtreeMoveto() or 0
 12.4775 +                          ** if there have been no prior seeks on the cursor. */
 12.4776 +  /* NB: seekResult does not distinguish between "no seeks have ever occurred
 12.4777 +  ** on this cursor" and "the most recent seek was an exact match". */
 12.4778 +
 12.4779 +  /* When a new VdbeCursor is allocated, only the fields above are zeroed.
 12.4780 +  ** The fields that follow are uninitialized, and must be individually
 12.4781 +  ** initialized prior to first use. */
 12.4782 +  VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
 12.4783    union {
 12.4784      BtCursor *pCursor;          /* CURTYPE_BTREE.  Btree cursor */
 12.4785      sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB.   Vtab cursor */
 12.4786      int pseudoTableReg;         /* CURTYPE_PSEUDO. Reg holding content. */
 12.4787      VdbeSorter *pSorter;        /* CURTYPE_SORTER. Sorter object */
 12.4788    } uc;
 12.4789 -  Btree *pBt;           /* Separate file holding temporary table */
 12.4790 -  KeyInfo *pKeyInfo;    /* Info about index keys needed by index cursors */
 12.4791 -  int seekResult;       /* Result of previous sqlite3BtreeMoveto() */
 12.4792 -  i64 seqCount;         /* Sequence counter */
 12.4793 -  i64 movetoTarget;     /* Argument to the deferred sqlite3BtreeMoveto() */
 12.4794 -  VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
 12.4795 -  int *aAltMap;           /* Mapping from table to index column numbers */
 12.4796 +  KeyInfo *pKeyInfo;      /* Info about index keys needed by index cursors */
 12.4797 +  u32 iHdrOffset;         /* Offset to next unparsed byte of the header */
 12.4798 +  Pgno pgnoRoot;          /* Root page of the open btree cursor */
 12.4799 +  i16 nField;             /* Number of fields in the header */
 12.4800 +  u16 nHdrParsed;         /* Number of header fields parsed so far */
 12.4801 +  i64 movetoTarget;       /* Argument to the deferred sqlite3BtreeMoveto() */
 12.4802 +  u32 *aOffset;           /* Pointer to aType[nField] */
 12.4803 +  const u8 *aRow;         /* Data for the current row, if all on one page */
 12.4804 +  u32 payloadSize;        /* Total number of bytes in the record */
 12.4805 +  u32 szRow;              /* Byte available in aRow */
 12.4806  #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
 12.4807 -  u64 maskUsed;         /* Mask of columns used by this cursor */
 12.4808 -#endif
 12.4809 -
 12.4810 -  /* Cached information about the header for the data record that the
 12.4811 -  ** cursor is currently pointing to.  Only valid if cacheStatus matches
 12.4812 -  ** Vdbe.cacheCtr.  Vdbe.cacheCtr will never take on the value of
 12.4813 -  ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
 12.4814 -  ** the cache is out of date.
 12.4815 -  **
 12.4816 -  ** aRow might point to (ephemeral) data for the current row, or it might
 12.4817 -  ** be NULL.
 12.4818 -  */
 12.4819 -  u32 cacheStatus;      /* Cache is valid if this matches Vdbe.cacheCtr */
 12.4820 -  u32 payloadSize;      /* Total number of bytes in the record */
 12.4821 -  u32 szRow;            /* Byte available in aRow */
 12.4822 -  u32 iHdrOffset;       /* Offset to next unparsed byte of the header */
 12.4823 -  const u8 *aRow;       /* Data for the current row, if all on one page */
 12.4824 -  u32 *aOffset;         /* Pointer to aType[nField] */
 12.4825 -  u32 aType[1];         /* Type values for all entries in the record */
 12.4826 +  u64 maskUsed;           /* Mask of columns used by this cursor */
 12.4827 +#endif
 12.4828 +
 12.4829    /* 2*nField extra array elements allocated for aType[], beyond the one
 12.4830    ** static element declared in the structure.  nField total array slots for
 12.4831    ** aType[] and nField+1 array slots for aOffset[] */
 12.4832 -};
 12.4833 +  u32 aType[1];           /* Type values record decode.  MUST BE LAST */
 12.4834 +};
 12.4835 +
 12.4836 +
 12.4837 +/*
 12.4838 +** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
 12.4839 +*/
 12.4840 +#define CACHE_STALE 0
 12.4841  
 12.4842  /*
 12.4843  ** When a sub-program is executed (OP_Program), a structure of this type
 12.4844 @@ -17560,8 +18097,8 @@
 12.4845    Op *aOp;                /* Program instructions for parent frame */
 12.4846    i64 *anExec;            /* Event counters from parent frame */
 12.4847    Mem *aMem;              /* Array of memory cells for parent frame */
 12.4848 -  u8 *aOnceFlag;          /* Array of OP_Once flags for parent frame */
 12.4849    VdbeCursor **apCsr;     /* Array of Vdbe cursors for parent frame */
 12.4850 +  u8 *aOnce;              /* Bitmask used by OP_Once */
 12.4851    void *token;            /* Copy of SubProgram.token */
 12.4852    i64 lastRowid;          /* Last insert rowid (sqlite3.lastRowid) */
 12.4853    AuxData *pAuxData;      /* Linked list of auxdata allocations */
 12.4854 @@ -17569,7 +18106,6 @@
 12.4855    int pc;                 /* Program Counter in parent (calling) frame */
 12.4856    int nOp;                /* Size of aOp array */
 12.4857    int nMem;               /* Number of entries in aMem */
 12.4858 -  int nOnceFlag;          /* Number of entries in aOnceFlag */
 12.4859    int nChildMem;          /* Number of memory cells for child frame */
 12.4860    int nChildCsr;          /* Number of cursors for child frame */
 12.4861    int nChange;            /* Statement changes (Vdbe.nChange)     */
 12.4862 @@ -17579,16 +18115,11 @@
 12.4863  #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
 12.4864  
 12.4865  /*
 12.4866 -** A value for VdbeCursor.cacheValid that means the cache is always invalid.
 12.4867 -*/
 12.4868 -#define CACHE_STALE 0
 12.4869 -
 12.4870 -/*
 12.4871  ** Internally, the vdbe manipulates nearly all SQL values as Mem
 12.4872  ** structures. Each Mem struct may cache multiple representations (string,
 12.4873  ** integer etc.) of the same value.
 12.4874  */
 12.4875 -struct Mem {
 12.4876 +struct sqlite3_value {
 12.4877    union MemValue {
 12.4878      double r;           /* Real value used when MEM_Real is set in flags */
 12.4879      i64 i;              /* Integer value used when MEM_Int is set in flags */
 12.4880 @@ -17690,11 +18221,11 @@
 12.4881  ** when the VM is halted (if not before).
 12.4882  */
 12.4883  struct AuxData {
 12.4884 -  int iOp;                        /* Instruction number of OP_Function opcode */
 12.4885 -  int iArg;                       /* Index of function argument. */
 12.4886 +  int iAuxOp;                     /* Instruction number of OP_Function opcode */
 12.4887 +  int iAuxArg;                    /* Index of function argument. */
 12.4888    void *pAux;                     /* Aux data pointer */
 12.4889 -  void (*xDelete)(void *);        /* Destructor for the aux data */
 12.4890 -  AuxData *pNext;                 /* Next element in list */
 12.4891 +  void (*xDeleteAux)(void*);      /* Destructor for the aux data */
 12.4892 +  AuxData *pNextAux;              /* Next element in list */
 12.4893  };
 12.4894  
 12.4895  /*
 12.4896 @@ -17723,18 +18254,6 @@
 12.4897    sqlite3_value *argv[1]; /* Argument set */
 12.4898  };
 12.4899  
 12.4900 -/*
 12.4901 -** An Explain object accumulates indented output which is helpful
 12.4902 -** in describing recursive data structures.
 12.4903 -*/
 12.4904 -struct Explain {
 12.4905 -  Vdbe *pVdbe;       /* Attach the explanation to this Vdbe */
 12.4906 -  StrAccum str;      /* The string being accumulated */
 12.4907 -  int nIndent;       /* Number of elements in aIndent */
 12.4908 -  u16 aIndent[100];  /* Levels of indentation */
 12.4909 -  char zBase[100];   /* Initial space */
 12.4910 -};
 12.4911 -
 12.4912  /* A bitfield type for use inside of structures.  Always follow with :N where
 12.4913  ** N is the number of bits.
 12.4914  */
 12.4915 @@ -17759,34 +18278,46 @@
 12.4916  */
 12.4917  struct Vdbe {
 12.4918    sqlite3 *db;            /* The database connection that owns this statement */
 12.4919 +  Vdbe *pPrev,*pNext;     /* Linked list of VDBEs with the same Vdbe.db */
 12.4920 +  Parse *pParse;          /* Parsing context used to create this Vdbe */
 12.4921 +  ynVar nVar;             /* Number of entries in aVar[] */
 12.4922 +  u32 magic;              /* Magic number for sanity checking */
 12.4923 +  int nMem;               /* Number of memory locations currently allocated */
 12.4924 +  int nCursor;            /* Number of slots in apCsr[] */
 12.4925 +  u32 cacheCtr;           /* VdbeCursor row cache generation counter */
 12.4926 +  int pc;                 /* The program counter */
 12.4927 +  int rc;                 /* Value to return */
 12.4928 +  int nChange;            /* Number of db changes made since last reset */
 12.4929 +  int iStatement;         /* Statement number (or 0 if has not opened stmt) */
 12.4930 +  i64 iCurrentTime;       /* Value of julianday('now') for this statement */
 12.4931 +  i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
 12.4932 +  i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
 12.4933 +  i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */
 12.4934 +
 12.4935 +  /* When allocating a new Vdbe object, all of the fields below should be
 12.4936 +  ** initialized to zero or NULL */
 12.4937 +
 12.4938    Op *aOp;                /* Space to hold the virtual machine's program */
 12.4939    Mem *aMem;              /* The memory locations */
 12.4940    Mem **apArg;            /* Arguments to currently executing user function */
 12.4941    Mem *aColName;          /* Column names to return */
 12.4942    Mem *pResultSet;        /* Pointer to an array of results */
 12.4943 -  Parse *pParse;          /* Parsing context used to create this Vdbe */
 12.4944 -  int nMem;               /* Number of memory locations currently allocated */
 12.4945 -  int nOp;                /* Number of instructions in the program */
 12.4946 -  int nCursor;            /* Number of slots in apCsr[] */
 12.4947 -  u32 magic;              /* Magic number for sanity checking */
 12.4948    char *zErrMsg;          /* Error message written here */
 12.4949 -  Vdbe *pPrev,*pNext;     /* Linked list of VDBEs with the same Vdbe.db */
 12.4950    VdbeCursor **apCsr;     /* One element of this array for each open cursor */
 12.4951    Mem *aVar;              /* Values for the OP_Variable opcode. */
 12.4952 -  char **azVar;           /* Name of variables */
 12.4953 -  ynVar nVar;             /* Number of entries in aVar[] */
 12.4954 -  ynVar nzVar;            /* Number of entries in azVar[] */
 12.4955 -  u32 cacheCtr;           /* VdbeCursor row cache generation counter */
 12.4956 -  int pc;                 /* The program counter */
 12.4957 -  int rc;                 /* Value to return */
 12.4958 +  VList *pVList;          /* Name of variables */
 12.4959 +#ifndef SQLITE_OMIT_TRACE
 12.4960 +  i64 startTime;          /* Time when query started - used for profiling */
 12.4961 +#endif
 12.4962 +  int nOp;                /* Number of instructions in the program */
 12.4963  #ifdef SQLITE_DEBUG
 12.4964    int rcApp;              /* errcode set by sqlite3_result_error_code() */
 12.4965  #endif
 12.4966    u16 nResColumn;         /* Number of columns in one row of the result set */
 12.4967    u8 errorAction;         /* Recovery action to do in case of an error */
 12.4968 +  u8 minWriteFileFormat;  /* Minimum file format for writable database files */
 12.4969    bft expired:1;          /* True if the VM needs to be recompiled */
 12.4970    bft doingRerun:1;       /* True if rerunning after an auto-reprepare */
 12.4971 -  u8 minWriteFileFormat;  /* Minimum file format for writable database files */
 12.4972    bft explain:2;          /* True if EXPLAIN present on SQL command */
 12.4973    bft changeCntOn:1;      /* True to update the change-counter */
 12.4974    bft runOnlyOnce:1;      /* Automatically expire on reset */
 12.4975 @@ -17794,18 +18325,9 @@
 12.4976    bft readOnly:1;         /* True for statements that do not write */
 12.4977    bft bIsReader:1;        /* True for statements that read */
 12.4978    bft isPrepareV2:1;      /* True if prepared with prepare_v2() */
 12.4979 -  int nChange;            /* Number of db changes made since last reset */
 12.4980    yDbMask btreeMask;      /* Bitmask of db->aDb[] entries referenced */
 12.4981    yDbMask lockMask;       /* Subset of btreeMask that requires a lock */
 12.4982 -  int iStatement;         /* Statement number (or 0 if has not opened stmt) */
 12.4983    u32 aCounter[5];        /* Counters used by sqlite3_stmt_status() */
 12.4984 -#ifndef SQLITE_OMIT_TRACE
 12.4985 -  i64 startTime;          /* Time when query started - used for profiling */
 12.4986 -#endif
 12.4987 -  i64 iCurrentTime;       /* Value of julianday('now') for this statement */
 12.4988 -  i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
 12.4989 -  i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
 12.4990 -  i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */
 12.4991    char *zSql;             /* Text of the SQL statement that generated this */
 12.4992    void *pFree;            /* Free this when deleting the vdbe */
 12.4993    VdbeFrame *pFrame;      /* Parent frame */
 12.4994 @@ -17813,8 +18335,6 @@
 12.4995    int nFrame;             /* Number of frames in pFrame list */
 12.4996    u32 expmask;            /* Binding to these vars invalidates VM */
 12.4997    SubProgram *pProgram;   /* Linked list of all sub-programs used by VM */
 12.4998 -  int nOnceFlag;          /* Size of array aOnceFlag[] */
 12.4999 -  u8 *aOnceFlag;          /* Flags for OP_Once */
 12.5000    AuxData *pAuxData;      /* Linked list of auxdata allocations */
 12.5001  #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
 12.5002    i64 *anExec;            /* Number of times each op has been executed */
 12.5003 @@ -17826,10 +18346,11 @@
 12.5004  /*
 12.5005  ** The following are allowed values for Vdbe.magic
 12.5006  */
 12.5007 -#define VDBE_MAGIC_INIT     0x26bceaa5    /* Building a VDBE program */
 12.5008 -#define VDBE_MAGIC_RUN      0xbdf20da3    /* VDBE is ready to execute */
 12.5009 -#define VDBE_MAGIC_HALT     0x519c2973    /* VDBE has completed execution */
 12.5010 -#define VDBE_MAGIC_DEAD     0xb606c3c8    /* The VDBE has been deallocated */
 12.5011 +#define VDBE_MAGIC_INIT     0x16bceaa5    /* Building a VDBE program */
 12.5012 +#define VDBE_MAGIC_RUN      0x2df20da3    /* VDBE is ready to execute */
 12.5013 +#define VDBE_MAGIC_HALT     0x319c2973    /* VDBE has completed execution */
 12.5014 +#define VDBE_MAGIC_RESET    0x48fa9f76    /* Reset and ready to run again */
 12.5015 +#define VDBE_MAGIC_DEAD     0x5606c3c8    /* The VDBE has been deallocated */
 12.5016  
 12.5017  /*
 12.5018  ** Structure used to store the context required by the 
 12.5019 @@ -17846,8 +18367,9 @@
 12.5020    int iNewReg;                    /* Register for new.* values */
 12.5021    i64 iKey1;                      /* First key value passed to hook */
 12.5022    i64 iKey2;                      /* Second key value passed to hook */
 12.5023 -  int iPKey;                      /* If not negative index of IPK column */
 12.5024    Mem *aNew;                      /* Array of new.* values */
 12.5025 +  Table *pTab;                    /* Schema object being upated */          
 12.5026 +  Index *pPk;                     /* PK index if pTab is WITHOUT ROWID */
 12.5027  };
 12.5028  
 12.5029  /*
 12.5030 @@ -17900,7 +18422,7 @@
 12.5031  SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
 12.5032  SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
 12.5033  SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8);
 12.5034 -SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
 12.5035 +SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
 12.5036  SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
 12.5037  SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
 12.5038  SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
 12.5039 @@ -17961,7 +18483,7 @@
 12.5040    #define ExpandBlob(P) SQLITE_OK
 12.5041  #endif
 12.5042  
 12.5043 -#endif /* !defined(_VDBEINT_H_) */
 12.5044 +#endif /* !defined(SQLITE_VDBEINT_H) */
 12.5045  
 12.5046  /************** End of vdbeInt.h *********************************************/
 12.5047  /************** Continuing where we left off in status.c *********************/
 12.5048 @@ -18082,7 +18604,7 @@
 12.5049  /*
 12.5050  ** Query status information.
 12.5051  */
 12.5052 -SQLITE_API int SQLITE_STDCALL sqlite3_status64(
 12.5053 +SQLITE_API int sqlite3_status64(
 12.5054    int op,
 12.5055    sqlite3_int64 *pCurrent,
 12.5056    sqlite3_int64 *pHighwater,
 12.5057 @@ -18107,8 +18629,8 @@
 12.5058    (void)pMutex;  /* Prevent warning when SQLITE_THREADSAFE=0 */
 12.5059    return SQLITE_OK;
 12.5060  }
 12.5061 -SQLITE_API int SQLITE_STDCALL sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
 12.5062 -  sqlite3_int64 iCur, iHwtr;
 12.5063 +SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
 12.5064 +  sqlite3_int64 iCur = 0, iHwtr = 0;
 12.5065    int rc;
 12.5066  #ifdef SQLITE_ENABLE_API_ARMOR
 12.5067    if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
 12.5068 @@ -18124,7 +18646,7 @@
 12.5069  /*
 12.5070  ** Query status information for a single database connection
 12.5071  */
 12.5072 -SQLITE_API int SQLITE_STDCALL sqlite3_db_status(
 12.5073 +SQLITE_API int sqlite3_db_status(
 12.5074    sqlite3 *db,          /* The database connection whose status is desired */
 12.5075    int op,               /* Status verb */
 12.5076    int *pCurrent,        /* Write current value here */
 12.5077 @@ -18169,6 +18691,7 @@
 12.5078      ** by all pagers associated with the given database connection.  The
 12.5079      ** highwater mark is meaningless and is returned as zero.
 12.5080      */
 12.5081 +    case SQLITE_DBSTATUS_CACHE_USED_SHARED:
 12.5082      case SQLITE_DBSTATUS_CACHE_USED: {
 12.5083        int totalUsed = 0;
 12.5084        int i;
 12.5085 @@ -18177,7 +18700,11 @@
 12.5086          Btree *pBt = db->aDb[i].pBt;
 12.5087          if( pBt ){
 12.5088            Pager *pPager = sqlite3BtreePager(pBt);
 12.5089 -          totalUsed += sqlite3PagerMemUsed(pPager);
 12.5090 +          int nByte = sqlite3PagerMemUsed(pPager);
 12.5091 +          if( op==SQLITE_DBSTATUS_CACHE_USED_SHARED ){
 12.5092 +            nByte = nByte / sqlite3BtreeConnectionCount(pBt);
 12.5093 +          }
 12.5094 +          totalUsed += nByte;
 12.5095          }
 12.5096        }
 12.5097        sqlite3BtreeLeaveAll(db);
 12.5098 @@ -18364,16 +18891,18 @@
 12.5099  */
 12.5100  typedef struct DateTime DateTime;
 12.5101  struct DateTime {
 12.5102 -  sqlite3_int64 iJD; /* The julian day number times 86400000 */
 12.5103 -  int Y, M, D;       /* Year, month, and day */
 12.5104 -  int h, m;          /* Hour and minutes */
 12.5105 -  int tz;            /* Timezone offset in minutes */
 12.5106 -  double s;          /* Seconds */
 12.5107 -  char validYMD;     /* True (1) if Y,M,D are valid */
 12.5108 -  char validHMS;     /* True (1) if h,m,s are valid */
 12.5109 -  char validJD;      /* True (1) if iJD is valid */
 12.5110 -  char validTZ;      /* True (1) if tz is valid */
 12.5111 -  char tzSet;        /* Timezone was set explicitly */
 12.5112 +  sqlite3_int64 iJD;  /* The julian day number times 86400000 */
 12.5113 +  int Y, M, D;        /* Year, month, and day */
 12.5114 +  int h, m;           /* Hour and minutes */
 12.5115 +  int tz;             /* Timezone offset in minutes */
 12.5116 +  double s;           /* Seconds */
 12.5117 +  char validJD;       /* True (1) if iJD is valid */
 12.5118 +  char rawS;          /* Raw numeric value stored in s */
 12.5119 +  char validYMD;      /* True (1) if Y,M,D are valid */
 12.5120 +  char validHMS;      /* True (1) if h,m,s are valid */
 12.5121 +  char validTZ;       /* True (1) if tz is valid */
 12.5122 +  char tzSet;         /* Timezone was set explicitly */
 12.5123 +  char isError;       /* An overflow has occurred */
 12.5124  };
 12.5125  
 12.5126  
 12.5127 @@ -18521,6 +19050,7 @@
 12.5128      s = 0;
 12.5129    }
 12.5130    p->validJD = 0;
 12.5131 +  p->rawS = 0;
 12.5132    p->validHMS = 1;
 12.5133    p->h = h;
 12.5134    p->m = m;
 12.5135 @@ -18531,6 +19061,14 @@
 12.5136  }
 12.5137  
 12.5138  /*
 12.5139 +** Put the DateTime object into its error state.
 12.5140 +*/
 12.5141 +static void datetimeError(DateTime *p){
 12.5142 +  memset(p, 0, sizeof(*p));
 12.5143 +  p->isError = 1;
 12.5144 +}
 12.5145 +
 12.5146 +/*
 12.5147  ** Convert from YYYY-MM-DD HH:MM:SS to julian day.  We always assume
 12.5148  ** that the YYYY-MM-DD is according to the Gregorian calendar.
 12.5149  **
 12.5150 @@ -18549,6 +19087,10 @@
 12.5151      M = 1;
 12.5152      D = 1;
 12.5153    }
 12.5154 +  if( Y<-4713 || Y>9999 || p->rawS ){
 12.5155 +    datetimeError(p);
 12.5156 +    return;
 12.5157 +  }
 12.5158    if( M<=2 ){
 12.5159      Y--;
 12.5160      M += 12;
 12.5161 @@ -18630,6 +19172,21 @@
 12.5162  }
 12.5163  
 12.5164  /*
 12.5165 +** Input "r" is a numeric quantity which might be a julian day number,
 12.5166 +** or the number of seconds since 1970.  If the value if r is within
 12.5167 +** range of a julian day number, install it as such and set validJD.
 12.5168 +** If the value is a valid unix timestamp, put it in p->s and set p->rawS.
 12.5169 +*/
 12.5170 +static void setRawDateNumber(DateTime *p, double r){
 12.5171 +  p->s = r;
 12.5172 +  p->rawS = 1;
 12.5173 +  if( r>=0.0 && r<5373484.5 ){
 12.5174 +    p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
 12.5175 +    p->validJD = 1;
 12.5176 +  }
 12.5177 +}
 12.5178 +
 12.5179 +/*
 12.5180  ** Attempt to parse the given string into a julian day number.  Return
 12.5181  ** the number of errors.
 12.5182  **
 12.5183 @@ -18658,13 +19215,30 @@
 12.5184    }else if( sqlite3StrICmp(zDate,"now")==0){
 12.5185      return setDateTimeToCurrent(context, p);
 12.5186    }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
 12.5187 -    p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
 12.5188 -    p->validJD = 1;
 12.5189 +    setRawDateNumber(p, r);
 12.5190      return 0;
 12.5191    }
 12.5192    return 1;
 12.5193  }
 12.5194  
 12.5195 +/* The julian day number for 9999-12-31 23:59:59.999 is 5373484.4999999.
 12.5196 +** Multiplying this by 86400000 gives 464269060799999 as the maximum value
 12.5197 +** for DateTime.iJD.
 12.5198 +**
 12.5199 +** But some older compilers (ex: gcc 4.2.1 on older Macs) cannot deal with 
 12.5200 +** such a large integer literal, so we have to encode it.
 12.5201 +*/
 12.5202 +#define INT_464269060799999  ((((i64)0x1a640)<<32)|0x1072fdff)
 12.5203 +
 12.5204 +/*
 12.5205 +** Return TRUE if the given julian day number is within range.
 12.5206 +**
 12.5207 +** The input is the JulianDay times 86400000.
 12.5208 +*/
 12.5209 +static int validJulianDay(sqlite3_int64 iJD){
 12.5210 +  return iJD>=0 && iJD<=INT_464269060799999;
 12.5211 +}
 12.5212 +
 12.5213  /*
 12.5214  ** Compute the Year, Month, and Day from the julian day number.
 12.5215  */
 12.5216 @@ -18675,6 +19249,9 @@
 12.5217      p->Y = 2000;
 12.5218      p->M = 1;
 12.5219      p->D = 1;
 12.5220 +  }else if( !validJulianDay(p->iJD) ){
 12.5221 +    datetimeError(p);
 12.5222 +    return;
 12.5223    }else{
 12.5224      Z = (int)((p->iJD + 43200000)/86400000);
 12.5225      A = (int)((Z - 1867216.25)/36524.25);
 12.5226 @@ -18706,6 +19283,7 @@
 12.5227    s -= p->h*3600;
 12.5228    p->m = s/60;
 12.5229    p->s += s - p->m*60;
 12.5230 +  p->rawS = 0;
 12.5231    p->validHMS = 1;
 12.5232  }
 12.5233  
 12.5234 @@ -18767,14 +19345,14 @@
 12.5235  #endif
 12.5236    sqlite3_mutex_enter(mutex);
 12.5237    pX = localtime(t);
 12.5238 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.5239 +#ifndef SQLITE_UNTESTABLE
 12.5240    if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
 12.5241  #endif
 12.5242    if( pX ) *pTm = *pX;
 12.5243    sqlite3_mutex_leave(mutex);
 12.5244    rc = pX==0;
 12.5245  #else
 12.5246 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.5247 +#ifndef SQLITE_UNTESTABLE
 12.5248    if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
 12.5249  #endif
 12.5250  #if HAVE_LOCALTIME_R
 12.5251 @@ -18845,7 +19423,9 @@
 12.5252    y.validYMD = 1;
 12.5253    y.validHMS = 1;
 12.5254    y.validJD = 0;
 12.5255 +  y.rawS = 0;
 12.5256    y.validTZ = 0;
 12.5257 +  y.isError = 0;
 12.5258    computeJD(&y);
 12.5259    *pRc = SQLITE_OK;
 12.5260    return y.iJD - x.iJD;
 12.5261 @@ -18853,6 +19433,29 @@
 12.5262  #endif /* SQLITE_OMIT_LOCALTIME */
 12.5263  
 12.5264  /*
 12.5265 +** The following table defines various date transformations of the form
 12.5266 +**
 12.5267 +**            'NNN days'
 12.5268 +**
 12.5269 +** Where NNN is an arbitrary floating-point number and "days" can be one
 12.5270 +** of several units of time.
 12.5271 +*/
 12.5272 +static const struct {
 12.5273 +  u8 eType;           /* Transformation type code */
 12.5274 +  u8 nName;           /* Length of th name */
 12.5275 +  char *zName;        /* Name of the transformation */
 12.5276 +  double rLimit;      /* Maximum NNN value for this transform */
 12.5277 +  double rXform;      /* Constant used for this transform */
 12.5278 +} aXformType[] = {
 12.5279 +  { 0, 6, "second", 464269060800.0, 86400000.0/(24.0*60.0*60.0) },
 12.5280 +  { 0, 6, "minute", 7737817680.0,   86400000.0/(24.0*60.0)      },
 12.5281 +  { 0, 4, "hour",   128963628.0,    86400000.0/24.0             },
 12.5282 +  { 0, 3, "day",    5373485.0,      86400000.0                  },
 12.5283 +  { 1, 5, "month",  176546.0,       30.0*86400000.0             },
 12.5284 +  { 2, 4, "year",   14713.0,        365.0*86400000.0            },
 12.5285 +};
 12.5286 +
 12.5287 +/*
 12.5288  ** Process a modifier to a date-time stamp.  The modifiers are
 12.5289  ** as follows:
 12.5290  **
 12.5291 @@ -18876,17 +19479,15 @@
 12.5292  ** to context pCtx. If the error is an unrecognized modifier, no error is
 12.5293  ** written to pCtx.
 12.5294  */
 12.5295 -static int parseModifier(sqlite3_context *pCtx, const char *zMod, DateTime *p){
 12.5296 +static int parseModifier(
 12.5297 +  sqlite3_context *pCtx,      /* Function context */
 12.5298 +  const char *z,              /* The text of the modifier */
 12.5299 +  int n,                      /* Length of zMod in bytes */
 12.5300 +  DateTime *p                 /* The date/time value to be modified */
 12.5301 +){
 12.5302    int rc = 1;
 12.5303 -  int n;
 12.5304    double r;
 12.5305 -  char *z, zBuf[30];
 12.5306 -  z = zBuf;
 12.5307 -  for(n=0; n<ArraySize(zBuf)-1 && zMod[n]; n++){
 12.5308 -    z[n] = (char)sqlite3UpperToLower[(u8)zMod[n]];
 12.5309 -  }
 12.5310 -  z[n] = 0;
 12.5311 -  switch( z[0] ){
 12.5312 +  switch(sqlite3UpperToLower[(u8)z[0]] ){
 12.5313  #ifndef SQLITE_OMIT_LOCALTIME
 12.5314      case 'l': {
 12.5315        /*    localtime
 12.5316 @@ -18894,7 +19495,7 @@
 12.5317        ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
 12.5318        ** show local time.
 12.5319        */
 12.5320 -      if( strcmp(z, "localtime")==0 ){
 12.5321 +      if( sqlite3_stricmp(z, "localtime")==0 ){
 12.5322          computeJD(p);
 12.5323          p->iJD += localtimeOffset(p, pCtx, &rc);
 12.5324          clearYMD_HMS_TZ(p);
 12.5325 @@ -18906,16 +19507,21 @@
 12.5326        /*
 12.5327        **    unixepoch
 12.5328        **
 12.5329 -      ** Treat the current value of p->iJD as the number of
 12.5330 +      ** Treat the current value of p->s as the number of
 12.5331        ** seconds since 1970.  Convert to a real julian day number.
 12.5332        */
 12.5333 -      if( strcmp(z, "unixepoch")==0 && p->validJD ){
 12.5334 -        p->iJD = (p->iJD + 43200)/86400 + 21086676*(i64)10000000;
 12.5335 -        clearYMD_HMS_TZ(p);
 12.5336 -        rc = 0;
 12.5337 +      if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
 12.5338 +        r = p->s*1000.0 + 210866760000000.0;
 12.5339 +        if( r>=0.0 && r<464269060800000.0 ){
 12.5340 +          clearYMD_HMS_TZ(p);
 12.5341 +          p->iJD = (sqlite3_int64)r;
 12.5342 +          p->validJD = 1;
 12.5343 +          p->rawS = 0;
 12.5344 +          rc = 0;
 12.5345 +        }
 12.5346        }
 12.5347  #ifndef SQLITE_OMIT_LOCALTIME
 12.5348 -      else if( strcmp(z, "utc")==0 ){
 12.5349 +      else if( sqlite3_stricmp(z, "utc")==0 ){
 12.5350          if( p->tzSet==0 ){
 12.5351            sqlite3_int64 c1;
 12.5352            computeJD(p);
 12.5353 @@ -18941,7 +19547,7 @@
 12.5354        ** weekday N where 0==Sunday, 1==Monday, and so forth.  If the
 12.5355        ** date is already on the appropriate weekday, this is a no-op.
 12.5356        */
 12.5357 -      if( strncmp(z, "weekday ", 8)==0
 12.5358 +      if( sqlite3_strnicmp(z, "weekday ", 8)==0
 12.5359                 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)
 12.5360                 && (n=(int)r)==r && n>=0 && r<7 ){
 12.5361          sqlite3_int64 Z;
 12.5362 @@ -18964,23 +19570,24 @@
 12.5363        ** Move the date backwards to the beginning of the current day,
 12.5364        ** or month or year.
 12.5365        */
 12.5366 -      if( strncmp(z, "start of ", 9)!=0 ) break;
 12.5367 +      if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break;
 12.5368 +      if( !p->validJD && !p->validYMD && !p->validHMS ) break;
 12.5369        z += 9;
 12.5370        computeYMD(p);
 12.5371        p->validHMS = 1;
 12.5372        p->h = p->m = 0;
 12.5373        p->s = 0.0;
 12.5374 +      p->rawS = 0;
 12.5375        p->validTZ = 0;
 12.5376        p->validJD = 0;
 12.5377 -      if( strcmp(z,"month")==0 ){
 12.5378 +      if( sqlite3_stricmp(z,"month")==0 ){
 12.5379          p->D = 1;
 12.5380          rc = 0;
 12.5381 -      }else if( strcmp(z,"year")==0 ){
 12.5382 -        computeYMD(p);
 12.5383 +      }else if( sqlite3_stricmp(z,"year")==0 ){
 12.5384          p->M = 1;
 12.5385          p->D = 1;
 12.5386          rc = 0;
 12.5387 -      }else if( strcmp(z,"day")==0 ){
 12.5388 +      }else if( sqlite3_stricmp(z,"day")==0 ){
 12.5389          rc = 0;
 12.5390        }
 12.5391        break;
 12.5392 @@ -18998,6 +19605,7 @@
 12.5393      case '8':
 12.5394      case '9': {
 12.5395        double rRounder;
 12.5396 +      int i;
 12.5397        for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
 12.5398        if( !sqlite3AtoF(z, &r, n, SQLITE_UTF8) ){
 12.5399          rc = 1;
 12.5400 @@ -19026,46 +19634,48 @@
 12.5401          rc = 0;
 12.5402          break;
 12.5403        }
 12.5404 +
 12.5405 +      /* If control reaches this point, it means the transformation is
 12.5406 +      ** one of the forms like "+NNN days".  */
 12.5407        z += n;
 12.5408        while( sqlite3Isspace(*z) ) z++;
 12.5409        n = sqlite3Strlen30(z);
 12.5410        if( n>10 || n<3 ) break;
 12.5411 -      if( z[n-1]=='s' ){ z[n-1] = 0; n--; }
 12.5412 +      if( sqlite3UpperToLower[(u8)z[n-1]]=='s' ) n--;
 12.5413        computeJD(p);
 12.5414 -      rc = 0;
 12.5415 +      rc = 1;
 12.5416        rRounder = r<0 ? -0.5 : +0.5;
 12.5417 -      if( n==3 && strcmp(z,"day")==0 ){
 12.5418 -        p->iJD += (sqlite3_int64)(r*86400000.0 + rRounder);
 12.5419 -      }else if( n==4 && strcmp(z,"hour")==0 ){
 12.5420 -        p->iJD += (sqlite3_int64)(r*(86400000.0/24.0) + rRounder);
 12.5421 -      }else if( n==6 && strcmp(z,"minute")==0 ){
 12.5422 -        p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0)) + rRounder);
 12.5423 -      }else if( n==6 && strcmp(z,"second")==0 ){
 12.5424 -        p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0*60.0)) + rRounder);
 12.5425 -      }else if( n==5 && strcmp(z,"month")==0 ){
 12.5426 -        int x, y;
 12.5427 -        computeYMD_HMS(p);
 12.5428 -        p->M += (int)r;
 12.5429 -        x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
 12.5430 -        p->Y += x;
 12.5431 -        p->M -= x*12;
 12.5432 -        p->validJD = 0;
 12.5433 -        computeJD(p);
 12.5434 -        y = (int)r;
 12.5435 -        if( y!=r ){
 12.5436 -          p->iJD += (sqlite3_int64)((r - y)*30.0*86400000.0 + rRounder);
 12.5437 -        }
 12.5438 -      }else if( n==4 && strcmp(z,"year")==0 ){
 12.5439 -        int y = (int)r;
 12.5440 -        computeYMD_HMS(p);
 12.5441 -        p->Y += y;
 12.5442 -        p->validJD = 0;
 12.5443 -        computeJD(p);
 12.5444 -        if( y!=r ){
 12.5445 -          p->iJD += (sqlite3_int64)((r - y)*365.0*86400000.0 + rRounder);
 12.5446 -        }
 12.5447 -      }else{
 12.5448 -        rc = 1;
 12.5449 +      for(i=0; i<ArraySize(aXformType); i++){
 12.5450 +        if( aXformType[i].nName==n
 12.5451 +         && sqlite3_strnicmp(aXformType[i].zName, z, n)==0
 12.5452 +         && r>-aXformType[i].rLimit && r<aXformType[i].rLimit
 12.5453 +        ){
 12.5454 +          switch( aXformType[i].eType ){
 12.5455 +            case 1: { /* Special processing to add months */
 12.5456 +              int x;
 12.5457 +              computeYMD_HMS(p);
 12.5458 +              p->M += (int)r;
 12.5459 +              x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
 12.5460 +              p->Y += x;
 12.5461 +              p->M -= x*12;
 12.5462 +              p->validJD = 0;
 12.5463 +              r -= (int)r;
 12.5464 +              break;
 12.5465 +            }
 12.5466 +            case 2: { /* Special processing to add years */
 12.5467 +              int y = (int)r;
 12.5468 +              computeYMD_HMS(p);
 12.5469 +              p->Y += y;
 12.5470 +              p->validJD = 0;
 12.5471 +              r -= (int)r;
 12.5472 +              break;
 12.5473 +            }
 12.5474 +          }
 12.5475 +          computeJD(p);
 12.5476 +          p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder);
 12.5477 +          rc = 0;
 12.5478 +          break;
 12.5479 +        }
 12.5480        }
 12.5481        clearYMD_HMS_TZ(p);
 12.5482        break;
 12.5483 @@ -19092,7 +19702,7 @@
 12.5484    sqlite3_value **argv, 
 12.5485    DateTime *p
 12.5486  ){
 12.5487 -  int i;
 12.5488 +  int i, n;
 12.5489    const unsigned char *z;
 12.5490    int eType;
 12.5491    memset(p, 0, sizeof(*p));
 12.5492 @@ -19101,8 +19711,7 @@
 12.5493    }
 12.5494    if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
 12.5495                     || eType==SQLITE_INTEGER ){
 12.5496 -    p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
 12.5497 -    p->validJD = 1;
 12.5498 +    setRawDateNumber(p, sqlite3_value_double(argv[0]));
 12.5499    }else{
 12.5500      z = sqlite3_value_text(argv[0]);
 12.5501      if( !z || parseDateOrTime(context, (char*)z, p) ){
 12.5502 @@ -19111,8 +19720,11 @@
 12.5503    }
 12.5504    for(i=1; i<argc; i++){
 12.5505      z = sqlite3_value_text(argv[i]);
 12.5506 -    if( z==0 || parseModifier(context, (char*)z, p) ) return 1;
 12.5507 -  }
 12.5508 +    n = sqlite3_value_bytes(argv[i]);
 12.5509 +    if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1;
 12.5510 +  }
 12.5511 +  computeJD(p);
 12.5512 +  if( p->isError || !validJulianDay(p->iJD) ) return 1;
 12.5513    return 0;
 12.5514  }
 12.5515  
 12.5516 @@ -19411,7 +20023,6 @@
 12.5517  ){
 12.5518    time_t t;
 12.5519    char *zFormat = (char *)sqlite3_user_data(context);
 12.5520 -  sqlite3 *db;
 12.5521    sqlite3_int64 iT;
 12.5522    struct tm *pTm;
 12.5523    struct tm sNow;
 12.5524 @@ -19480,9 +20091,7 @@
 12.5525  ** This file contains OS interface code that is common to all
 12.5526  ** architectures.
 12.5527  */
 12.5528 -#define _SQLITE_OS_C_ 1
 12.5529  /* #include "sqliteInt.h" */
 12.5530 -#undef _SQLITE_OS_C_
 12.5531  
 12.5532  /*
 12.5533  ** If we compile with the SQLITE_TEST macro set, then the following block
 12.5534 @@ -19799,7 +20408,7 @@
 12.5535  ** Locate a VFS by name.  If no name is given, simply return the
 12.5536  ** first VFS on the list.
 12.5537  */
 12.5538 -SQLITE_API sqlite3_vfs *SQLITE_STDCALL sqlite3_vfs_find(const char *zVfs){
 12.5539 +SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfs){
 12.5540    sqlite3_vfs *pVfs = 0;
 12.5541  #if SQLITE_THREADSAFE
 12.5542    sqlite3_mutex *mutex;
 12.5543 @@ -19845,7 +20454,7 @@
 12.5544  ** VFS multiple times.  The new VFS becomes the default if makeDflt is
 12.5545  ** true.
 12.5546  */
 12.5547 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
 12.5548 +SQLITE_API int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
 12.5549    MUTEX_LOGIC(sqlite3_mutex *mutex;)
 12.5550  #ifndef SQLITE_OMIT_AUTOINIT
 12.5551    int rc = sqlite3_initialize();
 12.5552 @@ -19873,7 +20482,7 @@
 12.5553  /*
 12.5554  ** Unregister a VFS so that it is no longer accessible.
 12.5555  */
 12.5556 -SQLITE_API int SQLITE_STDCALL sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
 12.5557 +SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
 12.5558  #if SQLITE_THREADSAFE
 12.5559    sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 12.5560  #endif
 12.5561 @@ -19913,7 +20522,7 @@
 12.5562  
 12.5563  /* #include "sqliteInt.h" */
 12.5564  
 12.5565 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.5566 +#ifndef SQLITE_UNTESTABLE
 12.5567  
 12.5568  /*
 12.5569  ** Global variables.
 12.5570 @@ -19971,7 +20580,7 @@
 12.5571    }
 12.5572  }
 12.5573  
 12.5574 -#endif   /* #ifndef SQLITE_OMIT_BUILTIN_TEST */
 12.5575 +#endif   /* #ifndef SQLITE_UNTESTABLE */
 12.5576  
 12.5577  /************** End of fault.c ***********************************************/
 12.5578  /************** Begin file mem0.c ********************************************/
 12.5579 @@ -20096,7 +20705,9 @@
 12.5580  */
 12.5581  #include <sys/sysctl.h>
 12.5582  #include <malloc/malloc.h>
 12.5583 +#ifdef SQLITE_MIGHT_BE_SINGLE_CORE
 12.5584  #include <libkern/OSAtomic.h>
 12.5585 +#endif /* SQLITE_MIGHT_BE_SINGLE_CORE */
 12.5586  static malloc_zone_t* _sqliteZone_;
 12.5587  #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x))
 12.5588  #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x));
 12.5589 @@ -20164,7 +20775,9 @@
 12.5590  */
 12.5591  static void *sqlite3MemMalloc(int nByte){
 12.5592  #ifdef SQLITE_MALLOCSIZE
 12.5593 -  void *p = SQLITE_MALLOC( nByte );
 12.5594 +  void *p;
 12.5595 +  testcase( ROUND8(nByte)==nByte );
 12.5596 +  p = SQLITE_MALLOC( nByte );
 12.5597    if( p==0 ){
 12.5598      testcase( sqlite3GlobalConfig.xLog!=0 );
 12.5599      sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes of memory", nByte);
 12.5600 @@ -20173,7 +20786,7 @@
 12.5601  #else
 12.5602    sqlite3_int64 *p;
 12.5603    assert( nByte>0 );
 12.5604 -  nByte = ROUND8(nByte);
 12.5605 +  testcase( ROUND8(nByte)!=nByte );
 12.5606    p = SQLITE_MALLOC( nByte+8 );
 12.5607    if( p ){
 12.5608      p[0] = nByte;
 12.5609 @@ -20287,19 +20900,10 @@
 12.5610    }else{
 12.5611      /* only 1 core, use our own zone to contention over global locks, 
 12.5612      ** e.g. we have our own dedicated locks */
 12.5613 -    bool success;
 12.5614 -    malloc_zone_t* newzone = malloc_create_zone(4096, 0);
 12.5615 -    malloc_set_zone_name(newzone, "Sqlite_Heap");
 12.5616 -    do{
 12.5617 -      success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, 
 12.5618 -                                 (void * volatile *)&_sqliteZone_);
 12.5619 -    }while(!_sqliteZone_);
 12.5620 -    if( !success ){
 12.5621 -      /* somebody registered a zone first */
 12.5622 -      malloc_destroy_zone(newzone);
 12.5623 -    }
 12.5624 -  }
 12.5625 -#endif
 12.5626 +    _sqliteZone_ = malloc_create_zone(4096, 0);
 12.5627 +    malloc_set_zone_name(_sqliteZone_, "Sqlite_Heap");
 12.5628 +  }
 12.5629 +#endif /*  defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) */
 12.5630    UNUSED_PARAMETER(NotUsed);
 12.5631    return SQLITE_OK;
 12.5632  }
 12.5633 @@ -22224,7 +22828,7 @@
 12.5634  /*
 12.5635  ** Retrieve a pointer to a static mutex or allocate a new dynamic one.
 12.5636  */
 12.5637 -SQLITE_API sqlite3_mutex *SQLITE_STDCALL sqlite3_mutex_alloc(int id){
 12.5638 +SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
 12.5639  #ifndef SQLITE_OMIT_AUTOINIT
 12.5640    if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
 12.5641    if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0;
 12.5642 @@ -22245,7 +22849,7 @@
 12.5643  /*
 12.5644  ** Free a dynamic mutex.
 12.5645  */
 12.5646 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_free(sqlite3_mutex *p){
 12.5647 +SQLITE_API void sqlite3_mutex_free(sqlite3_mutex *p){
 12.5648    if( p ){
 12.5649      assert( sqlite3GlobalConfig.mutex.xMutexFree );
 12.5650      sqlite3GlobalConfig.mutex.xMutexFree(p);
 12.5651 @@ -22256,7 +22860,7 @@
 12.5652  ** Obtain the mutex p. If some other thread already has the mutex, block
 12.5653  ** until it can be obtained.
 12.5654  */
 12.5655 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_enter(sqlite3_mutex *p){
 12.5656 +SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex *p){
 12.5657    if( p ){
 12.5658      assert( sqlite3GlobalConfig.mutex.xMutexEnter );
 12.5659      sqlite3GlobalConfig.mutex.xMutexEnter(p);
 12.5660 @@ -22267,7 +22871,7 @@
 12.5661  ** Obtain the mutex p. If successful, return SQLITE_OK. Otherwise, if another
 12.5662  ** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY.
 12.5663  */
 12.5664 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_try(sqlite3_mutex *p){
 12.5665 +SQLITE_API int sqlite3_mutex_try(sqlite3_mutex *p){
 12.5666    int rc = SQLITE_OK;
 12.5667    if( p ){
 12.5668      assert( sqlite3GlobalConfig.mutex.xMutexTry );
 12.5669 @@ -22282,7 +22886,7 @@
 12.5670  ** is not currently entered. If a NULL pointer is passed as an argument
 12.5671  ** this function is a no-op.
 12.5672  */
 12.5673 -SQLITE_API void SQLITE_STDCALL sqlite3_mutex_leave(sqlite3_mutex *p){
 12.5674 +SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex *p){
 12.5675    if( p ){
 12.5676      assert( sqlite3GlobalConfig.mutex.xMutexLeave );
 12.5677      sqlite3GlobalConfig.mutex.xMutexLeave(p);
 12.5678 @@ -22294,11 +22898,11 @@
 12.5679  ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
 12.5680  ** intended for use inside assert() statements.
 12.5681  */
 12.5682 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_held(sqlite3_mutex *p){
 12.5683 +SQLITE_API int sqlite3_mutex_held(sqlite3_mutex *p){
 12.5684    assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld );
 12.5685    return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p);
 12.5686  }
 12.5687 -SQLITE_API int SQLITE_STDCALL sqlite3_mutex_notheld(sqlite3_mutex *p){
 12.5688 +SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex *p){
 12.5689    assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld );
 12.5690    return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
 12.5691  }
 12.5692 @@ -22995,8 +23599,8 @@
 12.5693  ** This file contains inline asm code for retrieving "high-performance"
 12.5694  ** counters for x86 class CPUs.
 12.5695  */
 12.5696 -#ifndef _HWTIME_H_
 12.5697 -#define _HWTIME_H_
 12.5698 +#ifndef SQLITE_HWTIME_H
 12.5699 +#define SQLITE_HWTIME_H
 12.5700  
 12.5701  /*
 12.5702  ** The following routine only works on pentium-class (or newer) processors.
 12.5703 @@ -23064,7 +23668,7 @@
 12.5704  
 12.5705  #endif
 12.5706  
 12.5707 -#endif /* !defined(_HWTIME_H_) */
 12.5708 +#endif /* !defined(SQLITE_HWTIME_H) */
 12.5709  
 12.5710  /************** End of hwtime.h **********************************************/
 12.5711  /************** Continuing where we left off in os_common.h ******************/
 12.5712 @@ -23154,8 +23758,8 @@
 12.5713  **
 12.5714  ** This file contains code that is specific to Windows.
 12.5715  */
 12.5716 -#ifndef _OS_WIN_H_
 12.5717 -#define _OS_WIN_H_
 12.5718 +#ifndef SQLITE_OS_WIN_H
 12.5719 +#define SQLITE_OS_WIN_H
 12.5720  
 12.5721  /*
 12.5722  ** Include the primary Windows SDK header file.
 12.5723 @@ -23227,7 +23831,7 @@
 12.5724  # define SQLITE_OS_WIN_THREADS 0
 12.5725  #endif
 12.5726  
 12.5727 -#endif /* _OS_WIN_H_ */
 12.5728 +#endif /* SQLITE_OS_WIN_H */
 12.5729  
 12.5730  /************** End of os_win.h **********************************************/
 12.5731  /************** Continuing where we left off in mutex_w32.c ******************/
 12.5732 @@ -23295,8 +23899,7 @@
 12.5733    SQLITE_MEMORY_BARRIER;
 12.5734  #elif defined(__GNUC__)
 12.5735    __sync_synchronize();
 12.5736 -#elif !defined(SQLITE_DISABLE_INTRINSIC) && \
 12.5737 -      defined(_MSC_VER) && _MSC_VER>=1300
 12.5738 +#elif MSVC_VERSION>=1300
 12.5739    _ReadWriteBarrier();
 12.5740  #elif defined(MemoryBarrier)
 12.5741    MemoryBarrier();
 12.5742 @@ -23330,8 +23933,8 @@
 12.5743  */
 12.5744  static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0;
 12.5745  
 12.5746 -SQLITE_API int SQLITE_STDCALL sqlite3_win32_is_nt(void); /* os_win.c */
 12.5747 -SQLITE_API void SQLITE_STDCALL sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
 12.5748 +SQLITE_API int sqlite3_win32_is_nt(void); /* os_win.c */
 12.5749 +SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
 12.5750  
 12.5751  static int winMutexInit(void){
 12.5752    /* The first to increment to 1 does actual initialization */
 12.5753 @@ -23507,8 +24110,8 @@
 12.5754    p->owner = tid;
 12.5755    p->nRef++;
 12.5756    if( p->trace ){
 12.5757 -    OSTRACE(("ENTER-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
 12.5758 -             tid, p, p->trace, p->nRef));
 12.5759 +    OSTRACE(("ENTER-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
 12.5760 +             tid, p->id, p, p->trace, p->nRef));
 12.5761    }
 12.5762  #endif
 12.5763  }
 12.5764 @@ -23550,8 +24153,8 @@
 12.5765  #endif
 12.5766  #ifdef SQLITE_DEBUG
 12.5767    if( p->trace ){
 12.5768 -    OSTRACE(("TRY-MUTEX tid=%lu, mutex=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
 12.5769 -             tid, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
 12.5770 +    OSTRACE(("TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
 12.5771 +             tid, p->id, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
 12.5772    }
 12.5773  #endif
 12.5774    return rc;
 12.5775 @@ -23579,8 +24182,8 @@
 12.5776    LeaveCriticalSection(&p->mutex);
 12.5777  #ifdef SQLITE_DEBUG
 12.5778    if( p->trace ){
 12.5779 -    OSTRACE(("LEAVE-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n",
 12.5780 -             tid, p, p->trace, p->nRef));
 12.5781 +    OSTRACE(("LEAVE-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
 12.5782 +             tid, p->id, p, p->trace, p->nRef));
 12.5783    }
 12.5784  #endif
 12.5785  }
 12.5786 @@ -23631,7 +24234,7 @@
 12.5787  ** held by SQLite. An example of non-essential memory is memory used to
 12.5788  ** cache database pages that are not currently in use.
 12.5789  */
 12.5790 -SQLITE_API int SQLITE_STDCALL sqlite3_release_memory(int n){
 12.5791 +SQLITE_API int sqlite3_release_memory(int n){
 12.5792  #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
 12.5793    return sqlite3PcacheReleaseMemory(n);
 12.5794  #else
 12.5795 @@ -23690,7 +24293,7 @@
 12.5796  ** that was invoked when memory usage grew too large.  Now it is a
 12.5797  ** no-op.
 12.5798  */
 12.5799 -SQLITE_API int SQLITE_STDCALL sqlite3_memory_alarm(
 12.5800 +SQLITE_API int sqlite3_memory_alarm(
 12.5801    void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
 12.5802    void *pArg,
 12.5803    sqlite3_int64 iThreshold
 12.5804 @@ -23706,7 +24309,7 @@
 12.5805  ** Set the soft heap-size limit for the library. Passing a zero or 
 12.5806  ** negative value indicates no limit.
 12.5807  */
 12.5808 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 n){
 12.5809 +SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){
 12.5810    sqlite3_int64 priorLimit;
 12.5811    sqlite3_int64 excess;
 12.5812    sqlite3_int64 nUsed;
 12.5813 @@ -23728,7 +24331,7 @@
 12.5814    if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
 12.5815    return priorLimit;
 12.5816  }
 12.5817 -SQLITE_API void SQLITE_STDCALL sqlite3_soft_heap_limit(int n){
 12.5818 +SQLITE_API void sqlite3_soft_heap_limit(int n){
 12.5819    if( n<0 ) n = 0;
 12.5820    sqlite3_soft_heap_limit64(n);
 12.5821  }
 12.5822 @@ -23797,7 +24400,7 @@
 12.5823  /*
 12.5824  ** Return the amount of memory currently checked out.
 12.5825  */
 12.5826 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_used(void){
 12.5827 +SQLITE_API sqlite3_int64 sqlite3_memory_used(void){
 12.5828    sqlite3_int64 res, mx;
 12.5829    sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, 0);
 12.5830    return res;
 12.5831 @@ -23808,7 +24411,7 @@
 12.5832  ** checked out since either the beginning of this process
 12.5833  ** or since the most recent reset.
 12.5834  */
 12.5835 -SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_memory_highwater(int resetFlag){
 12.5836 +SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag){
 12.5837    sqlite3_int64 res, mx;
 12.5838    sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &res, &mx, resetFlag);
 12.5839    return mx;
 12.5840 @@ -23828,11 +24431,26 @@
 12.5841  ** Do a memory allocation with statistics and alarms.  Assume the
 12.5842  ** lock is already held.
 12.5843  */
 12.5844 -static int mallocWithAlarm(int n, void **pp){
 12.5845 +static void mallocWithAlarm(int n, void **pp){
 12.5846 +  void *p;
 12.5847    int nFull;
 12.5848 -  void *p;
 12.5849    assert( sqlite3_mutex_held(mem0.mutex) );
 12.5850 +  assert( n>0 );
 12.5851 +
 12.5852 +  /* In Firefox (circa 2017-02-08), xRoundup() is remapped to an internal
 12.5853 +  ** implementation of malloc_good_size(), which must be called in debug
 12.5854 +  ** mode and specifically when the DMD "Dark Matter Detector" is enabled
 12.5855 +  ** or else a crash results.  Hence, do not attempt to optimize out the
 12.5856 +  ** following xRoundup() call. */
 12.5857    nFull = sqlite3GlobalConfig.m.xRoundup(n);
 12.5858 +
 12.5859 +#ifdef SQLITE_MAX_MEMORY
 12.5860 +  if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nFull>SQLITE_MAX_MEMORY ){
 12.5861 +    *pp = 0;
 12.5862 +    return;
 12.5863 +  }
 12.5864 +#endif
 12.5865 +
 12.5866    sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
 12.5867    if( mem0.alarmThreshold>0 ){
 12.5868      sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
 12.5869 @@ -23856,7 +24474,6 @@
 12.5870      sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
 12.5871    }
 12.5872    *pp = p;
 12.5873 -  return nFull;
 12.5874  }
 12.5875  
 12.5876  /*
 12.5877 @@ -23888,13 +24505,13 @@
 12.5878  ** First make sure the memory subsystem is initialized, then do the
 12.5879  ** allocation.
 12.5880  */
 12.5881 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc(int n){
 12.5882 +SQLITE_API void *sqlite3_malloc(int n){
 12.5883  #ifndef SQLITE_OMIT_AUTOINIT
 12.5884    if( sqlite3_initialize() ) return 0;
 12.5885  #endif
 12.5886    return n<=0 ? 0 : sqlite3Malloc(n);
 12.5887  }
 12.5888 -SQLITE_API void *SQLITE_STDCALL sqlite3_malloc64(sqlite3_uint64 n){
 12.5889 +SQLITE_API void *sqlite3_malloc64(sqlite3_uint64 n){
 12.5890  #ifndef SQLITE_OMIT_AUTOINIT
 12.5891    if( sqlite3_initialize() ) return 0;
 12.5892  #endif
 12.5893 @@ -24022,7 +24639,7 @@
 12.5894  SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
 12.5895    assert( p!=0 );
 12.5896    if( db==0 || !isLookaside(db,p) ){
 12.5897 -#if SQLITE_DEBUG
 12.5898 +#ifdef SQLITE_DEBUG
 12.5899      if( db==0 ){
 12.5900        assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
 12.5901        assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 12.5902 @@ -24037,7 +24654,7 @@
 12.5903      return db->lookaside.sz;
 12.5904    }
 12.5905  }
 12.5906 -SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void *p){
 12.5907 +SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
 12.5908    assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
 12.5909    assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 12.5910    return p ? sqlite3GlobalConfig.m.xSize(p) : 0;
 12.5911 @@ -24046,7 +24663,7 @@
 12.5912  /*
 12.5913  ** Free memory previously obtained from sqlite3Malloc().
 12.5914  */
 12.5915 -SQLITE_API void SQLITE_STDCALL sqlite3_free(void *p){
 12.5916 +SQLITE_API void sqlite3_free(void *p){
 12.5917    if( p==0 ) return;  /* IMP: R-49053-54554 */
 12.5918    assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 12.5919    assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
 12.5920 @@ -24071,11 +24688,12 @@
 12.5921  
 12.5922  /*
 12.5923  ** Free memory that might be associated with a particular database
 12.5924 -** connection.
 12.5925 -*/
 12.5926 -SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
 12.5927 +** connection.  Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
 12.5928 +** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
 12.5929 +*/
 12.5930 +SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
 12.5931    assert( db==0 || sqlite3_mutex_held(db->mutex) );
 12.5932 -  if( p==0 ) return;
 12.5933 +  assert( p!=0 );
 12.5934    if( db ){
 12.5935      if( db->pnBytesFreed ){
 12.5936        measureAllocationSize(db, p);
 12.5937 @@ -24083,7 +24701,7 @@
 12.5938      }
 12.5939      if( isLookaside(db, p) ){
 12.5940        LookasideSlot *pBuf = (LookasideSlot*)p;
 12.5941 -#if SQLITE_DEBUG
 12.5942 +#ifdef SQLITE_DEBUG
 12.5943        /* Trash all content in the buffer being freed */
 12.5944        memset(p, 0xaa, db->lookaside.sz);
 12.5945  #endif
 12.5946 @@ -24099,6 +24717,10 @@
 12.5947    sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
 12.5948    sqlite3_free(p);
 12.5949  }
 12.5950 +SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
 12.5951 +  assert( db==0 || sqlite3_mutex_held(db->mutex) );
 12.5952 +  if( p ) sqlite3DbFreeNN(db, p);
 12.5953 +}
 12.5954  
 12.5955  /*
 12.5956  ** Change the size of an existing memory allocation
 12.5957 @@ -24130,7 +24752,7 @@
 12.5958      sqlite3_mutex_enter(mem0.mutex);
 12.5959      sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
 12.5960      nDiff = nNew - nOld;
 12.5961 -    if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 
 12.5962 +    if( nDiff>0 && sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 
 12.5963            mem0.alarmThreshold-nDiff ){
 12.5964        sqlite3MallocAlarm(nDiff);
 12.5965      }
 12.5966 @@ -24155,14 +24777,14 @@
 12.5967  ** The public interface to sqlite3Realloc.  Make sure that the memory
 12.5968  ** subsystem is initialized prior to invoking sqliteRealloc.
 12.5969  */
 12.5970 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc(void *pOld, int n){
 12.5971 +SQLITE_API void *sqlite3_realloc(void *pOld, int n){
 12.5972  #ifndef SQLITE_OMIT_AUTOINIT
 12.5973    if( sqlite3_initialize() ) return 0;
 12.5974  #endif
 12.5975    if( n<0 ) n = 0;  /* IMP: R-26507-47431 */
 12.5976    return sqlite3Realloc(pOld, n);
 12.5977  }
 12.5978 -SQLITE_API void *SQLITE_STDCALL sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
 12.5979 +SQLITE_API void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
 12.5980  #ifndef SQLITE_OMIT_AUTOINIT
 12.5981    if( sqlite3_initialize() ) return 0;
 12.5982  #endif
 12.5983 @@ -24337,9 +24959,8 @@
 12.5984    if( z==0 ){
 12.5985      return 0;
 12.5986    }
 12.5987 -  n = sqlite3Strlen30(z) + 1;
 12.5988 -  assert( (n&0x7fffffff)==n );
 12.5989 -  zNew = sqlite3DbMallocRaw(db, (int)n);
 12.5990 +  n = strlen(z) + 1;
 12.5991 +  zNew = sqlite3DbMallocRaw(db, n);
 12.5992    if( zNew ){
 12.5993      memcpy(zNew, z, n);
 12.5994    }
 12.5995 @@ -24453,7 +25074,7 @@
 12.5996  ** Conversion types fall into various categories as defined by the
 12.5997  ** following enumeration.
 12.5998  */
 12.5999 -#define etRADIX       0 /* Integer types.  %d, %x, %o, and so forth */
 12.6000 +#define etRADIX       0 /* non-decimal integer types.  %x %o */
 12.6001  #define etFLOAT       1 /* Floating point.  %f */
 12.6002  #define etEXP         2 /* Exponentional notation. %e and %E */
 12.6003  #define etGENERIC     3 /* Floating or exponential, depending on exponent. %g */
 12.6004 @@ -24471,8 +25092,9 @@
 12.6005  #define etPOINTER    13 /* The %p conversion */
 12.6006  #define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
 12.6007  #define etORDINAL    15 /* %r -> 1st, 2nd, 3rd, 4th, etc.  English only */
 12.6008 -
 12.6009 -#define etINVALID    16 /* Any unrecognized conversion type */
 12.6010 +#define etDECIMAL    16 /* %d or %u, but not %x, %o */
 12.6011 +
 12.6012 +#define etINVALID    17 /* Any unrecognized conversion type */
 12.6013  
 12.6014  
 12.6015  /*
 12.6016 @@ -24496,9 +25118,8 @@
 12.6017  /*
 12.6018  ** Allowed values for et_info.flags
 12.6019  */
 12.6020 -#define FLAG_SIGNED  1     /* True if the value to convert is signed */
 12.6021 -#define FLAG_INTERN  2     /* True if for internal use only */
 12.6022 -#define FLAG_STRING  4     /* Allow infinity precision */
 12.6023 +#define FLAG_SIGNED    1     /* True if the value to convert is signed */
 12.6024 +#define FLAG_STRING    4     /* Allow infinite precision */
 12.6025  
 12.6026  
 12.6027  /*
 12.6028 @@ -24508,7 +25129,7 @@
 12.6029  static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
 12.6030  static const char aPrefix[] = "-x0\000X0";
 12.6031  static const et_info fmtinfo[] = {
 12.6032 -  {  'd', 10, 1, etRADIX,      0,  0 },
 12.6033 +  {  'd', 10, 1, etDECIMAL,    0,  0 },
 12.6034    {  's',  0, 4, etSTRING,     0,  0 },
 12.6035    {  'g',  0, 1, etGENERIC,    30, 0 },
 12.6036    {  'z',  0, 4, etDYNSTRING,  0,  0 },
 12.6037 @@ -24517,7 +25138,7 @@
 12.6038    {  'w',  0, 4, etSQLESCAPE3, 0,  0 },
 12.6039    {  'c',  0, 0, etCHARX,      0,  0 },
 12.6040    {  'o',  8, 0, etRADIX,      0,  2 },
 12.6041 -  {  'u', 10, 0, etRADIX,      0,  0 },
 12.6042 +  {  'u', 10, 0, etDECIMAL,    0,  0 },
 12.6043    {  'x', 16, 0, etRADIX,      16, 1 },
 12.6044    {  'X', 16, 0, etRADIX,      0,  4 },
 12.6045  #ifndef SQLITE_OMIT_FLOATING_POINT
 12.6046 @@ -24526,16 +25147,15 @@
 12.6047    {  'E',  0, 1, etEXP,        14, 0 },
 12.6048    {  'G',  0, 1, etGENERIC,    14, 0 },
 12.6049  #endif
 12.6050 -  {  'i', 10, 1, etRADIX,      0,  0 },
 12.6051 +  {  'i', 10, 1, etDECIMAL,    0,  0 },
 12.6052    {  'n',  0, 0, etSIZE,       0,  0 },
 12.6053    {  '%',  0, 0, etPERCENT,    0,  0 },
 12.6054    {  'p', 16, 0, etPOINTER,    0,  1 },
 12.6055  
 12.6056 -/* All the rest have the FLAG_INTERN bit set and are thus for internal
 12.6057 -** use only */
 12.6058 -  {  'T',  0, 2, etTOKEN,      0,  0 },
 12.6059 -  {  'S',  0, 2, etSRCLIST,    0,  0 },
 12.6060 -  {  'r', 10, 3, etORDINAL,    0,  0 },
 12.6061 +  /* All the rest are undocumented and are for internal use only */
 12.6062 +  {  'T',  0, 0, etTOKEN,      0,  0 },
 12.6063 +  {  'S',  0, 0, etSRCLIST,    0,  0 },
 12.6064 +  {  'r', 10, 1, etORDINAL,    0,  0 },
 12.6065  };
 12.6066  
 12.6067  /*
 12.6068 @@ -24619,17 +25239,15 @@
 12.6069    int idx;                   /* A general purpose loop counter */
 12.6070    int width;                 /* Width of the current field */
 12.6071    etByte flag_leftjustify;   /* True if "-" flag is present */
 12.6072 -  etByte flag_plussign;      /* True if "+" flag is present */
 12.6073 -  etByte flag_blanksign;     /* True if " " flag is present */
 12.6074 +  etByte flag_prefix;        /* '+' or ' ' or 0 for prefix */
 12.6075    etByte flag_alternateform; /* True if "#" flag is present */
 12.6076    etByte flag_altform2;      /* True if "!" flag is present */
 12.6077    etByte flag_zeropad;       /* True if field width constant starts with zero */
 12.6078 -  etByte flag_long;          /* True if "l" flag is present */
 12.6079 -  etByte flag_longlong;      /* True if the "ll" flag is present */
 12.6080 +  etByte flag_long;          /* 1 for the "l" flag, 2 for "ll", 0 by default */
 12.6081    etByte done;               /* Loop termination flag */
 12.6082 +  etByte cThousand;          /* Thousands separator for %d and %u */
 12.6083    etByte xtype = etINVALID;  /* Conversion paradigm */
 12.6084    u8 bArgList;               /* True for SQLITE_PRINTF_SQLFUNC */
 12.6085 -  u8 useIntern;              /* Ok to use internal conversions (ex: %T) */
 12.6086    char prefix;               /* Prefix character.  "+" or "-" or " " or '\0'. */
 12.6087    sqlite_uint64 longvalue;   /* Value for integer types */
 12.6088    LONGDOUBLE_TYPE realvalue; /* Value for real types */
 12.6089 @@ -24648,13 +25266,11 @@
 12.6090    char buf[etBUFSIZE];       /* Conversion buffer */
 12.6091  
 12.6092    bufpt = 0;
 12.6093 -  if( pAccum->printfFlags ){
 12.6094 -    if( (bArgList = (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
 12.6095 -      pArgList = va_arg(ap, PrintfArguments*);
 12.6096 -    }
 12.6097 -    useIntern = pAccum->printfFlags & SQLITE_PRINTF_INTERNAL;
 12.6098 -  }else{
 12.6099 -    bArgList = useIntern = 0;
 12.6100 +  if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){
 12.6101 +    pArgList = va_arg(ap, PrintfArguments*);
 12.6102 +    bArgList = 1;
 12.6103 +  }else{
 12.6104 +    bArgList = 0;
 12.6105    }
 12.6106    for(; (c=(*fmt))!=0; ++fmt){
 12.6107      if( c!='%' ){
 12.6108 @@ -24672,17 +25288,18 @@
 12.6109        break;
 12.6110      }
 12.6111      /* Find out what flags are present */
 12.6112 -    flag_leftjustify = flag_plussign = flag_blanksign = 
 12.6113 +    flag_leftjustify = flag_prefix = cThousand =
 12.6114       flag_alternateform = flag_altform2 = flag_zeropad = 0;
 12.6115      done = 0;
 12.6116      do{
 12.6117        switch( c ){
 12.6118          case '-':   flag_leftjustify = 1;     break;
 12.6119 -        case '+':   flag_plussign = 1;        break;
 12.6120 -        case ' ':   flag_blanksign = 1;       break;
 12.6121 +        case '+':   flag_prefix = '+';        break;
 12.6122 +        case ' ':   flag_prefix = ' ';        break;
 12.6123          case '#':   flag_alternateform = 1;   break;
 12.6124          case '!':   flag_altform2 = 1;        break;
 12.6125          case '0':   flag_zeropad = 1;         break;
 12.6126 +        case ',':   cThousand = ',';          break;
 12.6127          default:    done = 1;                 break;
 12.6128        }
 12.6129      }while( !done && (c=(*++fmt))!=0 );
 12.6130 @@ -24752,13 +25369,11 @@
 12.6131        flag_long = 1;
 12.6132        c = *++fmt;
 12.6133        if( c=='l' ){
 12.6134 -        flag_longlong = 1;
 12.6135 +        flag_long = 2;
 12.6136          c = *++fmt;
 12.6137 -      }else{
 12.6138 -        flag_longlong = 0;
 12.6139 -      }
 12.6140 -    }else{
 12.6141 -      flag_long = flag_longlong = 0;
 12.6142 +      }
 12.6143 +    }else{
 12.6144 +      flag_long = 0;
 12.6145      }
 12.6146      /* Fetch the info entry for the field */
 12.6147      infop = &fmtinfo[0];
 12.6148 @@ -24766,11 +25381,7 @@
 12.6149      for(idx=0; idx<ArraySize(fmtinfo); idx++){
 12.6150        if( c==fmtinfo[idx].fmttype ){
 12.6151          infop = &fmtinfo[idx];
 12.6152 -        if( useIntern || (infop->flags & FLAG_INTERN)==0 ){
 12.6153 -          xtype = infop->type;
 12.6154 -        }else{
 12.6155 -          return;
 12.6156 -        }
 12.6157 +        xtype = infop->type;
 12.6158          break;
 12.6159        }
 12.6160      }
 12.6161 @@ -24780,15 +25391,11 @@
 12.6162      **
 12.6163      **   flag_alternateform          TRUE if a '#' is present.
 12.6164      **   flag_altform2               TRUE if a '!' is present.
 12.6165 -    **   flag_plussign               TRUE if a '+' is present.
 12.6166 +    **   flag_prefix                 '+' or ' ' or zero
 12.6167      **   flag_leftjustify            TRUE if a '-' is present or if the
 12.6168      **                               field width was negative.
 12.6169      **   flag_zeropad                TRUE if the width began with 0.
 12.6170 -    **   flag_long                   TRUE if the letter 'l' (ell) prefixed
 12.6171 -    **                               the conversion character.
 12.6172 -    **   flag_longlong               TRUE if the letter 'll' (ell ell) prefixed
 12.6173 -    **                               the conversion character.
 12.6174 -    **   flag_blanksign              TRUE if a ' ' is present.
 12.6175 +    **   flag_long                   1 for "l", 2 for "ll"
 12.6176      **   width                       The specified field width.  This is
 12.6177      **                               always non-negative.  Zero is the default.
 12.6178      **   precision                   The specified precision.  The default
 12.6179 @@ -24798,19 +25405,24 @@
 12.6180      */
 12.6181      switch( xtype ){
 12.6182        case etPOINTER:
 12.6183 -        flag_longlong = sizeof(char*)==sizeof(i64);
 12.6184 -        flag_long = sizeof(char*)==sizeof(long int);
 12.6185 +        flag_long = sizeof(char*)==sizeof(i64) ? 2 :
 12.6186 +                     sizeof(char*)==sizeof(long int) ? 1 : 0;
 12.6187          /* Fall through into the next case */
 12.6188        case etORDINAL:
 12.6189 -      case etRADIX:
 12.6190 +      case etRADIX:      
 12.6191 +        cThousand = 0;
 12.6192 +        /* Fall through into the next case */
 12.6193 +      case etDECIMAL:
 12.6194          if( infop->flags & FLAG_SIGNED ){
 12.6195            i64 v;
 12.6196            if( bArgList ){
 12.6197              v = getIntArg(pArgList);
 12.6198 -          }else if( flag_longlong ){
 12.6199 -            v = va_arg(ap,i64);
 12.6200            }else if( flag_long ){
 12.6201 -            v = va_arg(ap,long int);
 12.6202 +            if( flag_long==2 ){
 12.6203 +              v = va_arg(ap,i64) ;
 12.6204 +            }else{
 12.6205 +              v = va_arg(ap,long int);
 12.6206 +            }
 12.6207            }else{
 12.6208              v = va_arg(ap,int);
 12.6209            }
 12.6210 @@ -24823,17 +25435,17 @@
 12.6211              prefix = '-';
 12.6212            }else{
 12.6213              longvalue = v;
 12.6214 -            if( flag_plussign )        prefix = '+';
 12.6215 -            else if( flag_blanksign )  prefix = ' ';
 12.6216 -            else                       prefix = 0;
 12.6217 +            prefix = flag_prefix;
 12.6218            }
 12.6219          }else{
 12.6220            if( bArgList ){
 12.6221              longvalue = (u64)getIntArg(pArgList);
 12.6222 -          }else if( flag_longlong ){
 12.6223 -            longvalue = va_arg(ap,u64);
 12.6224            }else if( flag_long ){
 12.6225 -            longvalue = va_arg(ap,unsigned long int);
 12.6226 +            if( flag_long==2 ){
 12.6227 +              longvalue = va_arg(ap,u64);
 12.6228 +            }else{
 12.6229 +              longvalue = va_arg(ap,unsigned long int);
 12.6230 +            }
 12.6231            }else{
 12.6232              longvalue = va_arg(ap,unsigned int);
 12.6233            }
 12.6234 @@ -24843,16 +25455,17 @@
 12.6235          if( flag_zeropad && precision<width-(prefix!=0) ){
 12.6236            precision = width-(prefix!=0);
 12.6237          }
 12.6238 -        if( precision<etBUFSIZE-10 ){
 12.6239 +        if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
 12.6240            nOut = etBUFSIZE;
 12.6241            zOut = buf;
 12.6242          }else{
 12.6243 -          nOut = precision + 10;
 12.6244 -          zOut = zExtra = sqlite3Malloc( nOut );
 12.6245 +          u64 n = (u64)precision + 10 + precision/3;
 12.6246 +          zOut = zExtra = sqlite3Malloc( n );
 12.6247            if( zOut==0 ){
 12.6248              setStrAccumError(pAccum, STRACCUM_NOMEM);
 12.6249              return;
 12.6250            }
 12.6251 +          nOut = (int)n;
 12.6252          }
 12.6253          bufpt = &zOut[nOut-1];
 12.6254          if( xtype==etORDINAL ){
 12.6255 @@ -24873,8 +25486,23 @@
 12.6256            }while( longvalue>0 );
 12.6257          }
 12.6258          length = (int)(&zOut[nOut-1]-bufpt);
 12.6259 -        for(idx=precision-length; idx>0; idx--){
 12.6260 +        while( precision>length ){
 12.6261            *(--bufpt) = '0';                             /* Zero pad */
 12.6262 +          length++;
 12.6263 +        }
 12.6264 +        if( cThousand ){
 12.6265 +          int nn = (length - 1)/3;  /* Number of "," to insert */
 12.6266 +          int ix = (length - 1)%3 + 1;
 12.6267 +          bufpt -= nn;
 12.6268 +          for(idx=0; nn>0; idx++){
 12.6269 +            bufpt[idx] = bufpt[idx+nn];
 12.6270 +            ix--;
 12.6271 +            if( ix==0 ){
 12.6272 +              bufpt[++idx] = cThousand;
 12.6273 +              nn--;
 12.6274 +              ix = 3;
 12.6275 +            }
 12.6276 +          }
 12.6277          }
 12.6278          if( prefix ) *(--bufpt) = prefix;               /* Add sign */
 12.6279          if( flag_alternateform && infop->prefix ){      /* Add "0" or "0x" */
 12.6280 @@ -24901,9 +25529,7 @@
 12.6281            realvalue = -realvalue;
 12.6282            prefix = '-';
 12.6283          }else{
 12.6284 -          if( flag_plussign )          prefix = '+';
 12.6285 -          else if( flag_blanksign )    prefix = ' ';
 12.6286 -          else                         prefix = 0;
 12.6287 +          prefix = flag_prefix;
 12.6288          }
 12.6289          if( xtype==etGENERIC && precision>0 ) precision--;
 12.6290          testcase( precision>0xfff );
 12.6291 @@ -25139,7 +25765,9 @@
 12.6292          break;
 12.6293        }
 12.6294        case etTOKEN: {
 12.6295 -        Token *pToken = va_arg(ap, Token*);
 12.6296 +        Token *pToken;
 12.6297 +        if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
 12.6298 +        pToken = va_arg(ap, Token*);
 12.6299          assert( bArgList==0 );
 12.6300          if( pToken && pToken->n ){
 12.6301            sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
 12.6302 @@ -25148,9 +25776,13 @@
 12.6303          break;
 12.6304        }
 12.6305        case etSRCLIST: {
 12.6306 -        SrcList *pSrc = va_arg(ap, SrcList*);
 12.6307 -        int k = va_arg(ap, int);
 12.6308 -        struct SrcList_item *pItem = &pSrc->a[k];
 12.6309 +        SrcList *pSrc;
 12.6310 +        int k;
 12.6311 +        struct SrcList_item *pItem;
 12.6312 +        if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
 12.6313 +        pSrc = va_arg(ap, SrcList*);
 12.6314 +        k = va_arg(ap, int);
 12.6315 +        pItem = &pSrc->a[k];
 12.6316          assert( bArgList==0 );
 12.6317          assert( k>=0 && k<pSrc->nSrc );
 12.6318          if( pItem->zDatabase ){
 12.6319 @@ -25172,9 +25804,13 @@
 12.6320      ** the output.
 12.6321      */
 12.6322      width -= length;
 12.6323 -    if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
 12.6324 -    sqlite3StrAccumAppend(pAccum, bufpt, length);
 12.6325 -    if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
 12.6326 +    if( width>0 ){
 12.6327 +      if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
 12.6328 +      sqlite3StrAccumAppend(pAccum, bufpt, length);
 12.6329 +      if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
 12.6330 +    }else{
 12.6331 +      sqlite3StrAccumAppend(pAccum, bufpt, length);
 12.6332 +    }
 12.6333  
 12.6334      if( zExtra ){
 12.6335        sqlite3DbFree(pAccum->db, zExtra);
 12.6336 @@ -25279,7 +25915,7 @@
 12.6337    assert( p->accError==0 || p->nAlloc==0 );
 12.6338    if( p->nChar+N >= p->nAlloc ){
 12.6339      enlargeAndAppend(p,z,N);
 12.6340 -  }else{
 12.6341 +  }else if( N ){
 12.6342      assert( p->zText );
 12.6343      p->nChar += N;
 12.6344      memcpy(&p->zText[p->nChar-N], z, N);
 12.6345 @@ -25299,18 +25935,23 @@
 12.6346  ** Return a pointer to the resulting string.  Return a NULL
 12.6347  ** pointer if any kind of error was encountered.
 12.6348  */
 12.6349 +static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
 12.6350 +  assert( p->mxAlloc>0 && !isMalloced(p) );
 12.6351 +  p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
 12.6352 +  if( p->zText ){
 12.6353 +    memcpy(p->zText, p->zBase, p->nChar+1);
 12.6354 +    p->printfFlags |= SQLITE_PRINTF_MALLOCED;
 12.6355 +  }else{
 12.6356 +    setStrAccumError(p, STRACCUM_NOMEM);
 12.6357 +  }
 12.6358 +  return p->zText;
 12.6359 +}
 12.6360  SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
 12.6361    if( p->zText ){
 12.6362      assert( (p->zText==p->zBase)==!isMalloced(p) );
 12.6363      p->zText[p->nChar] = 0;
 12.6364      if( p->mxAlloc>0 && !isMalloced(p) ){
 12.6365 -      p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
 12.6366 -      if( p->zText ){
 12.6367 -        memcpy(p->zText, p->zBase, p->nChar+1);
 12.6368 -        p->printfFlags |= SQLITE_PRINTF_MALLOCED;
 12.6369 -      }else{
 12.6370 -        setStrAccumError(p, STRACCUM_NOMEM);
 12.6371 -      }
 12.6372 +      return strAccumFinishRealloc(p);
 12.6373      }
 12.6374    }
 12.6375    return p->zText;
 12.6376 @@ -25389,7 +26030,7 @@
 12.6377  ** Print into memory obtained from sqlite3_malloc().  Omit the internal
 12.6378  ** %-conversion extensions.
 12.6379  */
 12.6380 -SQLITE_API char *SQLITE_STDCALL sqlite3_vmprintf(const char *zFormat, va_list ap){
 12.6381 +SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){
 12.6382    char *z;
 12.6383    char zBase[SQLITE_PRINT_BUF_SIZE];
 12.6384    StrAccum acc;
 12.6385 @@ -25413,7 +26054,7 @@
 12.6386  ** Print into memory obtained from sqlite3_malloc()().  Omit the internal
 12.6387  ** %-conversion extensions.
 12.6388  */
 12.6389 -SQLITE_API char *SQLITE_CDECL sqlite3_mprintf(const char *zFormat, ...){
 12.6390 +SQLITE_API char *sqlite3_mprintf(const char *zFormat, ...){
 12.6391    va_list ap;
 12.6392    char *z;
 12.6393  #ifndef SQLITE_OMIT_AUTOINIT
 12.6394 @@ -25438,7 +26079,7 @@
 12.6395  **
 12.6396  ** sqlite3_vsnprintf() is the varargs version.
 12.6397  */
 12.6398 -SQLITE_API char *SQLITE_STDCALL sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
 12.6399 +SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
 12.6400    StrAccum acc;
 12.6401    if( n<=0 ) return zBuf;
 12.6402  #ifdef SQLITE_ENABLE_API_ARMOR
 12.6403 @@ -25450,9 +26091,10 @@
 12.6404  #endif
 12.6405    sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
 12.6406    sqlite3VXPrintf(&acc, zFormat, ap);
 12.6407 -  return sqlite3StrAccumFinish(&acc);
 12.6408 -}
 12.6409 -SQLITE_API char *SQLITE_CDECL sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
 12.6410 +  zBuf[acc.nChar] = 0;
 12.6411 +  return zBuf;
 12.6412 +}
 12.6413 +SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
 12.6414    char *z;
 12.6415    va_list ap;
 12.6416    va_start(ap,zFormat);
 12.6417 @@ -25488,7 +26130,7 @@
 12.6418  /*
 12.6419  ** Format and write a message to the log if logging is enabled.
 12.6420  */
 12.6421 -SQLITE_API void SQLITE_CDECL sqlite3_log(int iErrCode, const char *zFormat, ...){
 12.6422 +SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...){
 12.6423    va_list ap;                             /* Vararg list */
 12.6424    if( sqlite3GlobalConfig.xLog ){
 12.6425      va_start(ap, zFormat);
 12.6426 @@ -25598,6 +26240,7 @@
 12.6427    va_start(ap, zFormat);
 12.6428    sqlite3VXPrintf(&acc, zFormat, ap);
 12.6429    va_end(ap);
 12.6430 +  assert( acc.nChar>0 );
 12.6431    if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1);
 12.6432    sqlite3StrAccumFinish(&acc);
 12.6433    fprintf(stdout,"%s", zBuf);
 12.6434 @@ -25653,11 +26296,15 @@
 12.6435  
 12.6436  
 12.6437  /*
 12.6438 -** Generate a human-readable description of a the Select object.
 12.6439 +** Generate a human-readable description of a Select object.
 12.6440  */
 12.6441  SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
 12.6442    int n = 0;
 12.6443    int cnt = 0;
 12.6444 +  if( p==0 ){
 12.6445 +    sqlite3TreeViewLine(pView, "nil-SELECT");
 12.6446 +    return;
 12.6447 +  } 
 12.6448    pView = sqlite3TreeViewPush(pView, moreToFollow);
 12.6449    if( p->pWith ){
 12.6450      sqlite3TreeViewWith(pView, p->pWith, 1);
 12.6451 @@ -25766,7 +26413,7 @@
 12.6452  SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
 12.6453    const char *zBinOp = 0;   /* Binary operator */
 12.6454    const char *zUniOp = 0;   /* Unary operator */
 12.6455 -  char zFlgs[30];
 12.6456 +  char zFlgs[60];
 12.6457    pView = sqlite3TreeViewPush(pView, moreToFollow);
 12.6458    if( pExpr==0 ){
 12.6459      sqlite3TreeViewLine(pView, "nil");
 12.6460 @@ -25774,7 +26421,12 @@
 12.6461      return;
 12.6462    }
 12.6463    if( pExpr->flags ){
 12.6464 -    sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x",pExpr->flags);
 12.6465 +    if( ExprHasProperty(pExpr, EP_FromJoin) ){
 12.6466 +      sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x iRJT=%d",
 12.6467 +                       pExpr->flags, pExpr->iRightJoinTable);
 12.6468 +    }else{
 12.6469 +      sqlite3_snprintf(sizeof(zFlgs),zFlgs,"  flags=0x%x",pExpr->flags);
 12.6470 +    }
 12.6471    }else{
 12.6472      zFlgs[0] = 0;
 12.6473    }
 12.6474 @@ -25978,6 +26630,26 @@
 12.6475        break;
 12.6476      }
 12.6477  #endif
 12.6478 +    case TK_MATCH: {
 12.6479 +      sqlite3TreeViewLine(pView, "MATCH {%d:%d}%s",
 12.6480 +                          pExpr->iTable, pExpr->iColumn, zFlgs);
 12.6481 +      sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
 12.6482 +      break;
 12.6483 +    }
 12.6484 +    case TK_VECTOR: {
 12.6485 +      sqlite3TreeViewBareExprList(pView, pExpr->x.pList, "VECTOR");
 12.6486 +      break;
 12.6487 +    }
 12.6488 +    case TK_SELECT_COLUMN: {
 12.6489 +      sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
 12.6490 +      sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
 12.6491 +      break;
 12.6492 +    }
 12.6493 +    case TK_IF_NULL_ROW: {
 12.6494 +      sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
 12.6495 +      sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
 12.6496 +      break;
 12.6497 +    }
 12.6498      default: {
 12.6499        sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
 12.6500        break;
 12.6501 @@ -25994,21 +26666,20 @@
 12.6502    sqlite3TreeViewPop(pView);
 12.6503  }
 12.6504  
 12.6505 +
 12.6506  /*
 12.6507  ** Generate a human-readable explanation of an expression list.
 12.6508  */
 12.6509 -SQLITE_PRIVATE void sqlite3TreeViewExprList(
 12.6510 +SQLITE_PRIVATE void sqlite3TreeViewBareExprList(
 12.6511    TreeView *pView,
 12.6512    const ExprList *pList,
 12.6513 -  u8 moreToFollow,
 12.6514    const char *zLabel
 12.6515  ){
 12.6516 -  int i;
 12.6517 -  pView = sqlite3TreeViewPush(pView, moreToFollow);
 12.6518    if( zLabel==0 || zLabel[0]==0 ) zLabel = "LIST";
 12.6519    if( pList==0 ){
 12.6520      sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
 12.6521    }else{
 12.6522 +    int i;
 12.6523      sqlite3TreeViewLine(pView, "%s", zLabel);
 12.6524      for(i=0; i<pList->nExpr; i++){
 12.6525        int j = pList->a[i].u.x.iOrderByCol;
 12.6526 @@ -26020,6 +26691,15 @@
 12.6527        if( j ) sqlite3TreeViewPop(pView);
 12.6528      }
 12.6529    }
 12.6530 +}
 12.6531 +SQLITE_PRIVATE void sqlite3TreeViewExprList(
 12.6532 +  TreeView *pView,
 12.6533 +  const ExprList *pList,
 12.6534 +  u8 moreToFollow,
 12.6535 +  const char *zLabel
 12.6536 +){
 12.6537 +  pView = sqlite3TreeViewPush(pView, moreToFollow);
 12.6538 +  sqlite3TreeViewBareExprList(pView, pList, zLabel);
 12.6539    sqlite3TreeViewPop(pView);
 12.6540  }
 12.6541  
 12.6542 @@ -26059,7 +26739,7 @@
 12.6543  /*
 12.6544  ** Return N random bytes.
 12.6545  */
 12.6546 -SQLITE_API void SQLITE_STDCALL sqlite3_randomness(int N, void *pBuf){
 12.6547 +SQLITE_API void sqlite3_randomness(int N, void *pBuf){
 12.6548    unsigned char t;
 12.6549    unsigned char *zBuf = pBuf;
 12.6550  
 12.6551 @@ -26135,7 +26815,7 @@
 12.6552    sqlite3_mutex_leave(mutex);
 12.6553  }
 12.6554  
 12.6555 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.6556 +#ifndef SQLITE_UNTESTABLE
 12.6557  /*
 12.6558  ** For testing purposes, we sometimes want to preserve the state of
 12.6559  ** PRNG and restore the PRNG to its saved state at a later time, or
 12.6560 @@ -26160,7 +26840,7 @@
 12.6561      sizeof(sqlite3Prng)
 12.6562    );
 12.6563  }
 12.6564 -#endif /* SQLITE_OMIT_BUILTIN_TEST */
 12.6565 +#endif /* SQLITE_UNTESTABLE */
 12.6566  
 12.6567  /************** End of random.c **********************************************/
 12.6568  /************** Begin file threads.c *****************************************/
 12.6569 @@ -27018,7 +27698,7 @@
 12.6570  ** Return whatever integer value the test callback returns, or return
 12.6571  ** SQLITE_OK if no test callback is installed.
 12.6572  */
 12.6573 -#ifndef SQLITE_OMIT_BUILTIN_TEST
 12.6574 +#ifndef SQLITE_UNTESTABLE
 12.6575  SQLITE_PRIVATE int sqlite3FaultSim(int iTest){
 12.6576    int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback;
 12.6577    return xCallback ? xCallback(iTest) : SQLITE_OK;
 12.6578 @@ -27262,7 +27942,7 @@
 12.6579  ** case-independent fashion, using the same definition of "case
 12.6580  ** independence" that SQLite uses internally when comparing identifiers.
 12.6581  */
 12.6582 -SQLITE_API int SQLITE_STDCALL sqlite3_stricmp(const char *zLeft, const char *zRight){
 12.6583 +SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){
 12.6584    if( zLeft==0 ){
 12.6585      return zRight ? -1 : 0;
 12.6586    }else if( zRight==0 ){
 12.6587 @@ -27283,7 +27963,7 @@
 12.6588    }
 12.6589    return c;
 12.6590  }
 12.6591 -SQLITE_API int SQLITE_STDCALL sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
 12.6592 +SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
 12.6593    register unsigned char *a, *b;
 12.6594    if( zLeft==0 ){
 12.6595      return zRight ? -1 : 0;
 12.6596 @@ -27689,6 +28369,7 @@
 12.6597      }
 12.6598    }
 12.6599  #endif
 12.6600 +  if( !sqlite3Isdigit(zNum[0]) ) return 0;
 12.6601    while( zNum[0]=='0' ) zNum++;
 12.6602    for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
 12.6603      v = v*10 + c;
 12.6604 @@ -28116,13 +28797,11 @@
 12.6605    u32 x;
 12.6606    memcpy(&x,p,4);
 12.6607    return x;
 12.6608 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
 12.6609 -    && defined(__GNUC__) && GCC_VERSION>=4003000
 12.6610 +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
 12.6611    u32 x;
 12.6612    memcpy(&x,p,4);
 12.6613    return __builtin_bswap32(x);
 12.6614 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
 12.6615 -    && defined(_MSC_VER) && _MSC_VER>=1300
 12.6616 +#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
 12.6617    u32 x;
 12.6618    memcpy(&x,p,4);
 12.6619    return _byteswap_ulong(x);
 12.6620 @@ -28134,12 +28813,10 @@
 12.6621  SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){
 12.6622  #if SQLITE_BYTEORDER==4321
 12.6623    memcpy(p,&v,4);
 12.6624 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
 12.6625 -    && defined(__GNUC__) && GCC_VERSION>=4003000
 12.6626 +#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
 12.6627    u32 x = __builtin_bswap32(v);
 12.6628    memcpy(p,&x,4);
 12.6629 -#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
 12.6630 -    && defined(_MSC_VER) && _MSC_VER>=1300
 12.6631 +#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
 12.6632    u32 x = _byteswap_ulong(v);
 12.6633    memcpy(p,&x,4);
 12.6634  #else
 12.6635 @@ -28255,6 +28932,9 @@
 12.6636  ** overflow, leave *pA unchanged and return 1.
 12.6637  */
 12.6638  SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
 12.6639 +#if GCC_VERSION>=5004000
 12.6640 +  return __builtin_add_overflow(*pA, iB, pA);
 12.6641 +#else
 12.6642    i64 iA = *pA;
 12.6643    testcase( iA==0 ); testcase( iA==1 );
 12.6644    testcase( iB==-1 ); testcase( iB==0 );
 12.6645 @@ -28269,8 +28949,12 @@
 12.6646    }
 12.6647    *pA += iB;
 12.6648    return 0; 
 12.6649 +#endif
 12.6650  }
 12.6651  SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
 12.6652 +#if GCC_VERSION>=5004000
 12.6653 +  return __builtin_sub_overflow(*pA, iB, pA);
 12.6654 +#else
 12.6655    testcase( iB==SMALLEST_INT64+1 );
 12.6656    if( iB==SMALLEST_INT64 ){
 12.6657      testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
 12.6658 @@ -28280,38 +28964,28 @@
 12.6659    }else{
 12.6660      return sqlite3AddInt64(pA, -iB);
 12.6661    }
 12.6662 -}
 12.6663 -#define TWOPOWER32 (((i64)1)<<32)
 12.6664 -#define TWOPOWER31 (((i64)1)<<31)
 12.6665 +#endif
 12.6666 +}
 12.6667  SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){
 12.6668 +#if GCC_VERSION>=5004000
 12.6669 +  return __builtin_mul_overflow(*pA, iB, pA);
 12.6670 +#else
 12.6671    i64 iA = *pA;
 12.6672 -  i64 iA1, iA0, iB1, iB0, r;
 12.6673 -
 12.6674 -  iA1 = iA/TWOPOWER32;
 12.6675 -  iA0 = iA % TWOPOWER32;
 12.6676 -  iB1 = iB/TWOPOWER32;
 12.6677 -  iB0 = iB % TWOPOWER32;
 12.6678 -  if( iA1==0 ){
 12.6679 -    if( iB1==0 ){
 12.6680 -      *pA *= iB;
 12.6681 -      return 0;
 12.6682 -    }
 12.6683 -    r = iA0*iB1;
 12.6684 -  }else if( iB1==0 ){
 12.6685 -    r = iA1*iB0;
 12.6686 -  }else{
 12.6687 -    /* If both iA1 and iB1 are non-zero, overflow will result */
 12.6688 -    return 1;
 12.6689 -  }
 12.6690 -  testcase( r==(-TWOPOWER31)-1 );
 12.6691 -  testcase( r==(-TWOPOWER31) );
 12.6692 -  testcase( r==TWOPOWER31 );
 12.6693 -  testcase( r==TWOPOWER31-1 );
 12.6694 -  if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
 12.6695 -  r *= TWOPOWER32;
 12.6696 -  if( sqlite3AddInt64(&r, iA0*iB0) ) return 1;
 12.6697 -  *pA = r;
 12.6698 +  if( iB>0 ){
 12.6699 +    if( iA>LARGEST_INT64/iB ) return 1;
 12.6700 +    if( iA<SMALLEST_INT64/iB ) return 1;
 12.6701 +  }else if( iB<0 ){
 12.6702 +    if( iA>0 ){
 12.6703 +      if( iB<SMALLEST_INT64/iA ) return 1;
 12.6704 +    }else if( iA<0 ){
 12.6705 +      if( iB==SMALLEST_INT64 ) return 1;
 12.6706 +      if( iA==SMALLEST_INT64 ) return 1;
 12.6707 +      if( -iA>LARGEST_INT64/-iB ) return 1;
 12.6708 +    }
 12.6709 +  }
 12.6710 +  *pA = iA*iB;
 12.6711    return 0;
 12.6712 +#endif
 12.6713  }
 12.6714  
 12.6715  /*
 12.6716 @@ -28445,6 +29119,109 @@
 12.6717  }
 12.6718  #endif /* defined SCANSTAT or STAT4 or ESTIMATED_ROWS */
 12.6719  
 12.6720 +/*
 12.6721 +** Add a new name/number pair to a VList.  This might require that the
 12.6722 +** VList object be reallocated, so return the new VList.  If an OOM
 12.6723 +** error occurs, the original VList returned and the
 12.6724 +** db->mallocFailed flag is set.
 12.6725 +**
 12.6726 +** A VList is really just an array of integers.  To destroy a VList,
 12.6727 +** simply pass it to sqlite3DbFree().
 12.6728 +**
 12.6729 +** The first integer is the number of integers allocated for the whole
 12.6730 +** VList.  The second integer is the number of integers actually used.
 12.6731 +** Each name/number pair is encoded by subsequent groups of 3 or more
 12.6732 +** integers.
 12.6733 +**
 12.6734 +** Each name/number pair starts with two integers which are the numeric
 12.6735 +** value for the pair and the size of the name/number pair, respectively.
 12.6736 +** The text name overlays one or more following integers.  The text name
 12.6737 +** is always zero-terminated.
 12.6738 +**
 12.6739 +** Conceptually:
 12.6740 +**
 12.6741 +**    struct VList {
 12.6742 +**      int nAlloc;   // Number of allocated slots 
 12.6743 +**      int nUsed;    // Number of used slots 
 12.6744 +**      struct VListEntry {
 12.6745 +**        int iValue;    // Value for this entry
 12.6746 +**        int nSlot;     // Slots used by this entry
 12.6747 +**        // ... variable name goes here
 12.6748 +**      } a[0];
 12.6749 +**    }
 12.6750 +**
 12.6751 +** During code generation, pointers to the variable names within the
 12.6752 +** VList are taken.  When that happens, nAlloc is set to zero as an 
 12.6753 +** indication that the VList may never again be enlarged, since the
 12.6754 +** accompanying realloc() would invalidate the pointers.
 12.6755 +*/
 12.6756 +SQLITE_PRIVATE VList *sqlite3VListAdd(
 12.6757 +  sqlite3 *db,           /* The database connection used for malloc() */
 12.6758 +  VList *pIn,            /* The input VList.  Might be NULL */
 12.6759 +  const char *zName,     /* Name of symbol to add */
 12.6760 +  int nName,             /* Bytes of text in zName */
 12.6761 +  int iVal               /* Value to associate with zName */
 12.6762 +){
 12.6763 +  int nInt;              /* number of sizeof(int) objects needed for zName */
 12.6764 +  char *z;               /* Pointer to where zName will be stored */
 12.6765 +  int i;                 /* Index in pIn[] where zName is stored */
 12.6766 +
 12.6767 +  nInt = nName/4 + 3;
 12.6768 +  assert( pIn==0 || pIn[0]>=3 );  /* Verify ok to add new elements */
 12.6769 +  if( pIn==0 || pIn[1]+nInt > pIn[0] ){
 12.6770 +    /* Enlarge the allocation */
 12.6771 +    int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt;
 12.6772 +    VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
 12.6773 +    if( pOut==0 ) return pIn;
 12.6774 +    if( pIn==0 ) pOut[1] = 2;
 12.6775 +    pIn = pOut;
 12.6776 +    pIn[0] = nAlloc;
 12.6777 +  }
 12.6778 +  i = pIn[1];
 12.6779 +  pIn[i] = iVal;
 12.6780 +  pIn[i+1] = nInt;
 12.6781 +  z = (char*)&pIn[i+2];
 12.6782 +  pIn[1] = i+nInt;
 12.6783 +  assert( pIn[1]<=pIn[0] );
 12.6784 +  memcpy(z, zName, nName);
 12.6785 +  z[nName] = 0;
 12.6786 +  return pIn;
 12.6787 +}
 12.6788 +
 12.6789 +/*
 12.6790 +** Return a pointer to the name of a variable in the given VList that
 12.6791 +** has the value iVal.  Or return a NULL if there is no such variable in
 12.6792 +** the list
 12.6793 +*/
 12.6794 +SQLITE_PRIVATE const char *sqlite3VListNumToName(VList *pIn, int iVal){
 12.6795 +  int i, mx;
 12.6796 +  if( pIn==0 ) return 0;
 12.6797 +  mx = pIn[1];
 12.6798 +  i = 2;
 12.6799 +  do{
 12.6800 +    if( pIn[i]==iVal ) return (char*)&pIn[i+2];
 12.6801 +    i += pIn[i+1];
 12.6802 +  }while( i<mx );
 12.6803 +  return 0;
 12.6804 +}
 12.6805 +
 12.6806 +/*
 12.6807 +** Return the number of the variable named zName, if it is in VList.
 12.6808 +** or return 0 if there is no such variable.
 12.6809 +*/
 12.6810 +SQLITE_PRIVATE int sqlite3VListNameToNum(VList *pIn, const char *zName, int nName){
 12.6811 +  int i, mx;
 12.6812 +  if( pIn==0 ) return 0;
 12.6813 +  mx = pIn[1];
 12.6814 +  i = 2;
 12.6815 +  do{
 12.6816 +    const char *z = (const char*)&pIn[i+2];
 12.6817 +    if( strncmp(z,zName,nName)==0 && z[nName]==0 ) return pIn[i];
 12.6818 +    i += pIn[i+1];
 12.6819 +  }while( i<mx );
 12.6820 +  return 0;
 12.6821 +}
 12.6822 +
 12.6823  /************** End of util.c ************************************************/
 12.6824  /************** Begin file hash.c ********************************************/
 12.6825  /*
 12.6826 @@ -28505,7 +29282,11 @@
 12.6827    unsigned int h = 0;
 12.6828    unsigned char c;
 12.6829    while( (c = (unsigned char)*z++)!=0 ){     /*OPTIMIZATION-IF-TRUE*/
 12.6830 -    h = (h<<3) ^ h ^ sqlite3UpperToLower[c];
 12.6831 +    /* Knuth multiplicative hashing.  (Sorting & Searching, p. 510).
 12.6832 +    ** 0x9e3779b1 is 2654435761 which is the closest prime number to
 12.6833 +    ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2. */
 12.6834 +    h += sqlite3UpperToLower[c];
 12.6835 +    h *= 0x9e3779b1;
 12.6836    }
 12.6837    return h;
 12.6838  }
 12.6839 @@ -28752,144 +29533,149 @@
 12.6840      /*  20 */ "Once"             OpHelp(""),
 12.6841      /*  21 */ "If"               OpHelp(""),
 12.6842      /*  22 */ "IfNot"            OpHelp(""),
 12.6843 -    /*  23 */ "SeekLT"           OpHelp("key=r[P3@P4]"),
 12.6844 -    /*  24 */ "SeekLE"           OpHelp("key=r[P3@P4]"),
 12.6845 -    /*  25 */ "SeekGE"           OpHelp("key=r[P3@P4]"),
 12.6846 -    /*  26 */ "SeekGT"           OpHelp("key=r[P3@P4]"),
 12.6847 -    /*  27 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
 12.6848 -    /*  28 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
 12.6849 -    /*  29 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
 12.6850 -    /*  30 */ "NotFound"         OpHelp("key=r[P3@P4]"),
 12.6851 -    /*  31 */ "Found"            OpHelp("key=r[P3@P4]"),
 12.6852 +    /*  23 */ "IfNullRow"        OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
 12.6853 +    /*  24 */ "SeekLT"           OpHelp("key=r[P3@P4]"),
 12.6854 +    /*  25 */ "SeekLE"           OpHelp("key=r[P3@P4]"),
 12.6855 +    /*  26 */ "SeekGE"           OpHelp("key=r[P3@P4]"),
 12.6856 +    /*  27 */ "SeekGT"           OpHelp("key=r[P3@P4]"),
 12.6857 +    /*  28 */ "NoConflict"       OpHelp("key=r[P3@P4]"),
 12.6858 +    /*  29 */ "NotFound"         OpHelp("key=r[P3@P4]"),
 12.6859 +    /*  30 */ "Found"            OpHelp("key=r[P3@P4]"),
 12.6860 +    /*  31 */ "SeekRowid"        OpHelp("intkey=r[P3]"),
 12.6861      /*  32 */ "NotExists"        OpHelp("intkey=r[P3]"),
 12.6862      /*  33 */ "Last"             OpHelp(""),
 12.6863 -    /*  34 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
 12.6864 -    /*  35 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
 12.6865 -    /*  36 */ "Ne"               OpHelp("if r[P1]!=r[P3] goto P2"),
 12.6866 -    /*  37 */ "Eq"               OpHelp("if r[P1]==r[P3] goto P2"),
 12.6867 -    /*  38 */ "Gt"               OpHelp("if r[P1]>r[P3] goto P2"),
 12.6868 -    /*  39 */ "Le"               OpHelp("if r[P1]<=r[P3] goto P2"),
 12.6869 -    /*  40 */ "Lt"               OpHelp("if r[P1]<r[P3] goto P2"),
 12.6870 -    /*  41 */ "Ge"               OpHelp("if r[P1]>=r[P3] goto P2"),
 12.6871 -    /*  42 */ "SorterSort"       OpHelp(""),
 12.6872 -    /*  43 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
 12.6873 -    /*  44 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
 12.6874 -    /*  45 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
 12.6875 -    /*  46 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
 12.6876 -    /*  47 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
 12.6877 -    /*  48 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
 12.6878 -    /*  49 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
 12.6879 -    /*  50 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
 12.6880 -    /*  51 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
 12.6881 -    /*  52 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
 12.6882 -    /*  53 */ "Sort"             OpHelp(""),
 12.6883 -    /*  54 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
 12.6884 -    /*  55 */ "Rewind"           OpHelp(""),
 12.6885 -    /*  56 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
 12.6886 -    /*  57 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
 12.6887 -    /*  58 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
 12.6888 -    /*  59 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
 12.6889 -    /*  60 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
 12.6890 -    /*  61 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
 12.6891 -    /*  62 */ "Program"          OpHelp(""),
 12.6892 -    /*  63 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
 12.6893 -    /*  64 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
 12.6894 -    /*  65 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
 12.6895 -    /*  66 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
 12.6896 -    /*  67 */ "IncrVacuum"       OpHelp(""),
 12.6897 -    /*  68 */ "VNext"            OpHelp(""),
 12.6898 -    /*  69 */ "Init"             OpHelp("Start at P2"),
 12.6899 -    /*  70 */ "Return"           OpHelp(""),
 12.6900 -    /*  71 */ "EndCoroutine"     OpHelp(""),
 12.6901 -    /*  72 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
 12.6902 -    /*  73 */ "Halt"             OpHelp(""),
 12.6903 -    /*  74 */ "Integer"          OpHelp("r[P2]=P1"),
 12.6904 -    /*  75 */ "Int64"            OpHelp("r[P2]=P4"),
 12.6905 -    /*  76 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
 12.6906 -    /*  77 */ "Null"             OpHelp("r[P2..P3]=NULL"),
 12.6907 -    /*  78 */ "SoftNull"         OpHelp("r[P1]=NULL"),
 12.6908 -    /*  79 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
 12.6909 -    /*  80 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
 12.6910 -    /*  81 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
 12.6911 -    /*  82 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
 12.6912 -    /*  83 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
 12.6913 -    /*  84 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
 12.6914 -    /*  85 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
 12.6915 -    /*  86 */ "CollSeq"          OpHelp(""),
 12.6916 -    /*  87 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
 12.6917 -    /*  88 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
 12.6918 -    /*  89 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
 12.6919 -    /*  90 */ "RealAffinity"     OpHelp(""),
 12.6920 -    /*  91 */ "Cast"             OpHelp("affinity(r[P1])"),
 12.6921 -    /*  92 */ "Permutation"      OpHelp(""),
 12.6922 -    /*  93 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
 12.6923 -    /*  94 */ "Column"           OpHelp("r[P3]=PX"),
 12.6924 -    /*  95 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
 12.6925 -    /*  96 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
 12.6926 +    /*  34 */ "IfSmaller"        OpHelp(""),
 12.6927 +    /*  35 */ "SorterSort"       OpHelp(""),
 12.6928 +    /*  36 */ "Sort"             OpHelp(""),
 12.6929 +    /*  37 */ "Rewind"           OpHelp(""),
 12.6930 +    /*  38 */ "IdxLE"            OpHelp("key=r[P3@P4]"),
 12.6931 +    /*  39 */ "IdxGT"            OpHelp("key=r[P3@P4]"),
 12.6932 +    /*  40 */ "IdxLT"            OpHelp("key=r[P3@P4]"),
 12.6933 +    /*  41 */ "IdxGE"            OpHelp("key=r[P3@P4]"),
 12.6934 +    /*  42 */ "RowSetRead"       OpHelp("r[P3]=rowset(P1)"),
 12.6935 +    /*  43 */ "RowSetTest"       OpHelp("if r[P3] in rowset(P1) goto P2"),
 12.6936 +    /*  44 */ "Program"          OpHelp(""),
 12.6937 +    /*  45 */ "FkIfZero"         OpHelp("if fkctr[P1]==0 goto P2"),
 12.6938 +    /*  46 */ "IfPos"            OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
 12.6939 +    /*  47 */ "IfNotZero"        OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
 12.6940 +    /*  48 */ "DecrJumpZero"     OpHelp("if (--r[P1])==0 goto P2"),
 12.6941 +    /*  49 */ "IncrVacuum"       OpHelp(""),
 12.6942 +    /*  50 */ "VNext"            OpHelp(""),
 12.6943 +    /*  51 */ "Init"             OpHelp("Start at P2"),
 12.6944 +    /*  52 */ "Return"           OpHelp(""),
 12.6945 +    /*  53 */ "EndCoroutine"     OpHelp(""),
 12.6946 +    /*  54 */ "HaltIfNull"       OpHelp("if r[P3]=null halt"),
 12.6947 +    /*  55 */ "Halt"             OpHelp(""),
 12.6948 +    /*  56 */ "Integer"          OpHelp("r[P2]=P1"),
 12.6949 +    /*  57 */ "Int64"            OpHelp("r[P2]=P4"),
 12.6950 +    /*  58 */ "String"           OpHelp("r[P2]='P4' (len=P1)"),
 12.6951 +    /*  59 */ "Null"             OpHelp("r[P2..P3]=NULL"),
 12.6952 +    /*  60 */ "SoftNull"         OpHelp("r[P1]=NULL"),
 12.6953 +    /*  61 */ "Blob"             OpHelp("r[P2]=P4 (len=P1)"),
 12.6954 +    /*  62 */ "Variable"         OpHelp("r[P2]=parameter(P1,P4)"),
 12.6955 +    /*  63 */ "Move"             OpHelp("r[P2@P3]=r[P1@P3]"),
 12.6956 +    /*  64 */ "Copy"             OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
 12.6957 +    /*  65 */ "SCopy"            OpHelp("r[P2]=r[P1]"),
 12.6958 +    /*  66 */ "IntCopy"          OpHelp("r[P2]=r[P1]"),
 12.6959 +    /*  67 */ "ResultRow"        OpHelp("output=r[P1@P2]"),
 12.6960 +    /*  68 */ "CollSeq"          OpHelp(""),
 12.6961 +    /*  69 */ "Function0"        OpHelp("r[P3]=func(r[P2@P5])"),
 12.6962 +    /*  70 */ "Or"               OpHelp("r[P3]=(r[P1] || r[P2])"),
 12.6963 +    /*  71 */ "And"              OpHelp("r[P3]=(r[P1] && r[P2])"),
 12.6964 +    /*  72 */ "Function"         OpHelp("r[P3]=func(r[P2@P5])"),
 12.6965 +    /*  73 */ "AddImm"           OpHelp("r[P1]=r[P1]+P2"),
 12.6966 +    /*  74 */ "RealAffinity"     OpHelp(""),
 12.6967 +    /*  75 */ "IsNull"           OpHelp("if r[P1]==NULL goto P2"),
 12.6968 +    /*  76 */ "NotNull"          OpHelp("if r[P1]!=NULL goto P2"),
 12.6969 +    /*  77 */ "Ne"               OpHelp("IF r[P3]!=r[P1]"),
 12.6970 +    /*  78 */ "Eq"               OpHelp("IF r[P3]==r[P1]"),
 12.6971 +    /*  79 */ "Gt"               OpHelp("IF r[P3]>r[P1]"),
 12.6972 +    /*  80 */ "Le"               OpHelp("IF r[P3]<=r[P1]"),
 12.6973 +    /*  81 */ "Lt"               OpHelp("IF r[P3]<r[P1]"),
 12.6974 +    /*  82 */ "Ge"               OpHelp("IF r[P3]>=r[P1]"),
 12.6975 +    /*  83 */ "ElseNotEq"        OpHelp(""),
 12.6976 +    /*  84 */ "BitAnd"           OpHelp("r[P3]=r[P1]&r[P2]"),
 12.6977 +    /*  85 */ "BitOr"            OpHelp("r[P3]=r[P1]|r[P2]"),
 12.6978 +    /*  86 */ "ShiftLeft"        OpHelp("r[P3]=r[P2]<<r[P1]"),
 12.6979 +    /*  87 */ "ShiftRight"       OpHelp("r[P3]=r[P2]>>r[P1]"),
 12.6980 +    /*  88 */ "Add"              OpHelp("r[P3]=r[P1]+r[P2]"),
 12.6981 +    /*  89 */ "Subtract"         OpHelp("r[P3]=r[P2]-r[P1]"),
 12.6982 +    /*  90 */ "Multiply"         OpHelp("r[P3]=r[P1]*r[P2]"),
 12.6983 +    /*  91 */ "Divide"           OpHelp("r[P3]=r[P2]/r[P1]"),
 12.6984 +    /*  92 */ "Remainder"        OpHelp("r[P3]=r[P2]%r[P1]"),
 12.6985 +    /*  93 */ "Concat"           OpHelp("r[P3]=r[P2]+r[P1]"),
 12.6986 +    /*  94 */ "Cast"             OpHelp("affinity(r[P1])"),
 12.6987 +    /*  95 */ "BitNot"           OpHelp("r[P1]= ~r[P1]"),
 12.6988 +    /*  96 */ "Permutation"      OpHelp(""),
 12.6989      /*  97 */ "String8"          OpHelp("r[P2]='P4'"),
 12.6990 -    /*  98 */ "Count"            OpHelp("r[P2]=count()"),
 12.6991 -    /*  99 */ "ReadCookie"       OpHelp(""),
 12.6992 -    /* 100 */ "SetCookie"        OpHelp(""),
 12.6993 -    /* 101 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
 12.6994 -    /* 102 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
 12.6995 -    /* 103 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
 12.6996 -    /* 104 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
 12.6997 -    /* 105 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
 12.6998 -    /* 106 */ "SorterOpen"       OpHelp(""),
 12.6999 -    /* 107 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
 12.7000 -    /* 108 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
 12.7001 -    /* 109 */ "Close"            OpHelp(""),
 12.7002 -    /* 110 */ "ColumnsUsed"      OpHelp(""),
 12.7003 -    /* 111 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
 12.7004 -    /* 112 */ "NewRowid"         OpHelp("r[P2]=rowid"),
 12.7005 -    /* 113 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
 12.7006 -    /* 114 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
 12.7007 -    /* 115 */ "Delete"           OpHelp(""),
 12.7008 -    /* 116 */ "ResetCount"       OpHelp(""),
 12.7009 -    /* 117 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
 12.7010 -    /* 118 */ "SorterData"       OpHelp("r[P2]=data"),
 12.7011 -    /* 119 */ "RowKey"           OpHelp("r[P2]=key"),
 12.7012 -    /* 120 */ "RowData"          OpHelp("r[P2]=data"),
 12.7013 -    /* 121 */ "Rowid"            OpHelp("r[P2]=rowid"),
 12.7014 -    /* 122 */ "NullRow"          OpHelp(""),
 12.7015 -    /* 123 */ "SorterInsert"     OpHelp(""),
 12.7016 -    /* 124 */ "IdxInsert"        OpHelp("key=r[P2]"),
 12.7017 -    /* 125 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
 12.7018 -    /* 126 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
 12.7019 -    /* 127 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
 12.7020 -    /* 128 */ "Destroy"          OpHelp(""),
 12.7021 -    /* 129 */ "Clear"            OpHelp(""),
 12.7022 -    /* 130 */ "ResetSorter"      OpHelp(""),
 12.7023 -    /* 131 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
 12.7024 -    /* 132 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
 12.7025 -    /* 133 */ "Real"             OpHelp("r[P2]=P4"),
 12.7026 -    /* 134 */ "ParseSchema"      OpHelp(""),
 12.7027 -    /* 135 */ "LoadAnalysis"     OpHelp(""),
 12.7028 -    /* 136 */ "DropTable"        OpHelp(""),
 12.7029 -    /* 137 */ "DropIndex"        OpHelp(""),
 12.7030 -    /* 138 */ "DropTrigger"      OpHelp(""),
 12.7031 -    /* 139 */ "IntegrityCk"      OpHelp(""),
 12.7032 -    /* 140 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
 12.7033 -    /* 141 */ "Param"            OpHelp(""),
 12.7034 -    /* 142 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
 12.7035 -    /* 143 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
 12.7036 -    /* 144 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
 12.7037 -    /* 145 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
 12.7038 -    /* 146 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
 12.7039 -    /* 147 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
 12.7040 -    /* 148 */ "Expire"           OpHelp(""),
 12.7041 -    /* 149 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
 12.7042 -    /* 150 */ "VBegin"           OpHelp(""),
 12.7043 -    /* 151 */ "VCreate"          OpHelp(""),
 12.7044 -    /* 152 */ "VDestroy"         OpHelp(""),
 12.7045 -    /* 153 */ "VOpen"            OpHelp(""),
 12.7046 -    /* 154 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
 12.7047 -    /* 155 */ "VRename"          OpHelp(""),
 12.7048 -    /* 156 */ "Pagecount"        OpHelp(""),
 12.7049 -    /* 157 */ "MaxPgcnt"         OpHelp(""),
 12.7050 -    /* 158 */ "CursorHint"       OpHelp(""),
 12.7051 -    /* 159 */ "Noop"             OpHelp(""),
 12.7052 -    /* 160 */ "Explain"          OpHelp(""),
 12.7053 +    /*  98 */ "Compare"          OpHelp("r[P1@P3] <-> r[P2@P3]"),
 12.7054 +    /*  99 */ "Column"           OpHelp("r[P3]=PX"),
 12.7055 +    /* 100 */ "Affinity"         OpHelp("affinity(r[P1@P2])"),
 12.7056 +    /* 101 */ "MakeRecord"       OpHelp("r[P3]=mkrec(r[P1@P2])"),
 12.7057 +    /* 102 */ "Count"            OpHelp("r[P2]=count()"),
 12.7058 +    /* 103 */ "ReadCookie"       OpHelp(""),
 12.7059 +    /* 104 */ "SetCookie"        OpHelp(""),
 12.7060 +    /* 105 */ "ReopenIdx"        OpHelp("root=P2 iDb=P3"),
 12.7061 +    /* 106 */ "OpenRead"         OpHelp("root=P2 iDb=P3"),
 12.7062 +    /* 107 */ "OpenWrite"        OpHelp("root=P2 iDb=P3"),
 12.7063 +    /* 108 */ "OpenDup"          OpHelp(""),
 12.7064 +    /* 109 */ "OpenAutoindex"    OpHelp("nColumn=P2"),
 12.7065 +    /* 110 */ "OpenEphemeral"    OpHelp("nColumn=P2"),
 12.7066 +    /* 111 */ "SorterOpen"       OpHelp(""),
 12.7067 +    /* 112 */ "SequenceTest"     OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
 12.7068 +    /* 113 */ "OpenPseudo"       OpHelp("P3 columns in r[P2]"),
 12.7069 +    /* 114 */ "Close"            OpHelp(""),
 12.7070 +    /* 115 */ "ColumnsUsed"      OpHelp(""),
 12.7071 +    /* 116 */ "Sequence"         OpHelp("r[P2]=cursor[P1].ctr++"),
 12.7072 +    /* 117 */ "NewRowid"         OpHelp("r[P2]=rowid"),
 12.7073 +    /* 118 */ "Insert"           OpHelp("intkey=r[P3] data=r[P2]"),
 12.7074 +    /* 119 */ "InsertInt"        OpHelp("intkey=P3 data=r[P2]"),
 12.7075 +    /* 120 */ "Delete"           OpHelp(""),
 12.7076 +    /* 121 */ "ResetCount"       OpHelp(""),
 12.7077 +    /* 122 */ "SorterCompare"    OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
 12.7078 +    /* 123 */ "SorterData"       OpHelp("r[P2]=data"),
 12.7079 +    /* 124 */ "RowData"          OpHelp("r[P2]=data"),
 12.7080 +    /* 125 */ "Rowid"            OpHelp("r[P2]=rowid"),
 12.7081 +    /* 126 */ "NullRow"          OpHelp(""),
 12.7082 +    /* 127 */ "SorterInsert"     OpHelp("key=r[P2]"),
 12.7083 +    /* 128 */ "IdxInsert"        OpHelp("key=r[P2]"),
 12.7084 +    /* 129 */ "IdxDelete"        OpHelp("key=r[P2@P3]"),
 12.7085 +    /* 130 */ "Seek"             OpHelp("Move P3 to P1.rowid"),
 12.7086 +    /* 131 */ "IdxRowid"         OpHelp("r[P2]=rowid"),
 12.7087 +    /* 132 */ "Real"             OpHelp("r[P2]=P4"),
 12.7088 +    /* 133 */ "Destroy"          OpHelp(""),
 12.7089 +    /* 134 */ "Clear"            OpHelp(""),
 12.7090 +    /* 135 */ "ResetSorter"      OpHelp(""),
 12.7091 +    /* 136 */ "CreateIndex"      OpHelp("r[P2]=root iDb=P1"),
 12.7092 +    /* 137 */ "CreateTable"      OpHelp("r[P2]=root iDb=P1"),
 12.7093 +    /* 138 */ "SqlExec"          OpHelp(""),
 12.7094 +    /* 139 */ "ParseSchema"      OpHelp(""),
 12.7095 +    /* 140 */ "LoadAnalysis"     OpHelp(""),
 12.7096 +    /* 141 */ "DropTable"        OpHelp(""),
 12.7097 +    /* 142 */ "DropIndex"        OpHelp(""),
 12.7098 +    /* 143 */ "DropTrigger"      OpHelp(""),
 12.7099 +    /* 144 */ "IntegrityCk"      OpHelp(""),
 12.7100 +    /* 145 */ "RowSetAdd"        OpHelp("rowset(P1)=r[P2]"),
 12.7101 +    /* 146 */ "Param"            OpHelp(""),
 12.7102 +    /* 147 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
 12.7103 +    /* 148 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
 12.7104 +    /* 149 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
 12.7105 +    /* 150 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2@P5])"),
 12.7106 +    /* 151 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2@P5])"),
 12.7107 +    /* 152 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
 12.7108 +    /* 153 */ "Expire"           OpHelp(""),
 12.7109 +    /* 154 */ "TableLock"        OpHelp("iDb=P1 root=P2 write=P3"),
 12.7110 +    /* 155 */ "VBegin"           OpHelp(""),
 12.7111 +    /* 156 */ "VCreate"          OpHelp(""),
 12.7112 +    /* 157 */ "VDestroy"         OpHelp(""),
 12.7113 +    /* 158 */ "VOpen"            OpHelp(""),
 12.7114 +    /* 159 */ "VColumn"          OpHelp("r[P3]=vcolumn(P2)"),
 12.7115 +    /* 160 */ "VRename"          OpHelp(""),
 12.7116 +    /* 161 */ "Pagecount"        OpHelp(""),
 12.7117 +    /* 162 */ "MaxPgcnt"         OpHelp(""),
 12.7118 +    /* 163 */ "CursorHint"       OpHelp(""),
 12.7119 +    /* 164 */ "Noop"             OpHelp(""),
 12.7120 +    /* 165 */ "Explain"          OpHelp(""),
 12.7121    };
 12.7122    return azName[i];
 12.7123  }
 12.7124 @@ -29239,8 +30025,8 @@
 12.7125  ** This file contains inline asm code for retrieving "high-performance"
 12.7126  ** counters for x86 class CPUs.
 12.7127  */
 12.7128 -#ifndef _HWTIME_H_
 12.7129 -#define _HWTIME_H_
 12.7130 +#ifndef SQLITE_HWTIME_H
 12.7131 +#define SQLITE_HWTIME_H
 12.7132  
 12.7133  /*
 12.7134  ** The following routine only works on pentium-class (or newer) processors.
 12.7135 @@ -29308,7 +30094,7 @@
 12.7136  
 12.7137  #endif
 12.7138  
 12.7139 -#endif /* !defined(_HWTIME_H_) */
 12.7140 +#endif /* !defined(SQLITE_HWTIME_H) */
 12.7141  
 12.7142  /************** End of hwtime.h **********************************************/
 12.7143  /************** Continuing where we left off in os_common.h ******************/
 12.7144 @@ -30158,7 +30944,14 @@
 12.7145  #if OS_VXWORKS
 12.7146    struct vxworksFileId *pId;  /* Unique file ID for vxworks. */
 12.7147  #else
 12.7148 -  ino_t ino;                  /* Inode number */
 12.7149 +  /* We are told that some versions of Android contain a bug that
 12.7150 +  ** sizes ino_t at only 32-bits instead of 64-bits. (See
 12.7151 +  ** https://android-review.googlesource.com/#/c/115351/3/dist/sqlite3.c)
 12.7152 +  ** To work around this, always allocate 64-bits for the inode number.  
 12.7153 +  ** On small machines that only have 3