Fossil

Check-in [f7f168c3]
Login

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

Overview
Comment:Update SQLite to the latest 3.22.0 alpha. This might fix reported build problems on MinGW.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f7f168c36d493f82c93321ae1e3e7f8a0e5d4edb7aaf2e75c4c769b51fb4bd24
User & Date: drh 2018-01-09 00:55:11.664
Context
2018-01-09
00:55
Merge the latest Ardoise-skin enhancements. ... (check-in: 218aa6cb user: drh tags: trunk)
00:55
Update SQLite to the latest 3.22.0 alpha. This might fix reported build problems on MinGW. ... (check-in: f7f168c3 user: drh tags: trunk)
2018-01-07
23:45
Remove varargs C-preprocessor macros from linenoise.c, since some older C compilers (ex: gcc on a circa-2000 iBook) are unable to deal with them. ... (check-in: 24c2b99d user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/shell.c.
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

#if !defined(_WIN32) && !defined(WIN32)
# include <signal.h>
# if !defined(__RTP__) && !defined(_WRS_KERNEL)
#  include <pwd.h>
# endif
#endif
#if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW_H)
# include <unistd.h>
# include <dirent.h>
# if defined(__MINGW_H)
#  define DIRENT dirent
#  ifndef S_ISLNK
#   define S_ISLNK(mode) (0)
#  endif
# endif
#endif
#include <sys/types.h>







|


|







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

#if !defined(_WIN32) && !defined(WIN32)
# include <signal.h>
# if !defined(__RTP__) && !defined(_WRS_KERNEL)
#  include <pwd.h>
# endif
#endif
#if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW32__)
# include <unistd.h>
# include <dirent.h>
# if defined(__MINGW32__)
#  define DIRENT dirent
#  ifndef S_ISLNK
#   define S_ISLNK(mode) (0)
#  endif
# endif
#endif
#include <sys/types.h>
816
817
818
819
820
821
822
823
824

825
826
827
828
829
830
831
  sqlite3_context *pCtx,
  int nVal,
  sqlite3_value **apVal
){
  const char *zName = (const char*)sqlite3_value_text(apVal[0]);
  char *zFake = shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName);
  if( zFake ){
    sqlite3_result_text(pCtx, sqlite3_mprintf("/* %z */", zFake),
                        -1, sqlite3_free);

  }
}

/*
** SQL function:  shell_add_schema(S,X)
**
** Add the schema name X to the CREATE statement in S and return the result.







|

>







816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
  sqlite3_context *pCtx,
  int nVal,
  sqlite3_value **apVal
){
  const char *zName = (const char*)sqlite3_value_text(apVal[0]);
  char *zFake = shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName);
  if( zFake ){
    sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake),
                        -1, sqlite3_free);
    free(zFake);
  }
}

/*
** SQL function:  shell_add_schema(S,X)
**
** Add the schema name X to the CREATE statement in S and return the result.
877
878
879
880
881
882
883
884
885
886
887

888
889
890
891
892
893
894
          }
        }
        if( zName
         && aPrefix[i][0]=='V'
         && (zFake = shellFakeSchema(db, zSchema, zName))!=0
        ){
          if( z==0 ){
            z = sqlite3_mprintf("%s\n/* %z */", zIn, zFake);
          }else{
            z = sqlite3_mprintf("%z\n/* %z */", z, zFake);
          }

        }
        if( z ){
          sqlite3_result_text(pCtx, z, -1, sqlite3_free);
          return;
        }
      }
    }







|

|

>







878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
          }
        }
        if( zName
         && aPrefix[i][0]=='V'
         && (zFake = shellFakeSchema(db, zSchema, zName))!=0
        ){
          if( z==0 ){
            z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake);
          }else{
            z = sqlite3_mprintf("%z\n/* %s */", z, zFake);
          }
          free(zFake);
        }
        if( z ){
          sqlite3_result_text(pCtx, z, -1, sqlite3_free);
          return;
        }
      }
    }
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
#  include <utime.h>
#else
#  include "windows.h"
#  include <io.h>
#  include <direct.h>
/* #  include "test_windirent.h" */
#  define dirent DIRENT
#  define timespec TIMESPEC
#  define stat _stat
#  define mkdir(path,mode) _mkdir(path)
#  define lstat(path,buf) _stat(path,buf)
#endif
#include <time.h>
#include <errno.h>








<







2068
2069
2070
2071
2072
2073
2074

2075
2076
2077
2078
2079
2080
2081
#  include <utime.h>
#else
#  include "windows.h"
#  include <io.h>
#  include <direct.h>
/* #  include "test_windirent.h" */
#  define dirent DIRENT

#  define stat _stat
#  define mkdir(path,mode) _mkdir(path)
#  define lstat(path,buf) _stat(path,buf)
#endif
#include <time.h>
#include <errno.h>

3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894

3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
/* typedef sqlite3_int64 i64; */
/* typedef unsigned char u8; */
typedef unsigned short u16;
typedef unsigned long u32;
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#endif

#define ZIPFILE_SCHEMA "CREATE TABLE y("                           \
  "name,      /* Name of file in zip archive */"                   \
  "mode,      /* POSIX mode for file */"                           \
  "mtime,     /* Last modification time in seconds since epoch */" \
  "sz,        /* Size of object */"                                \

  "data,      /* Data stored in zip file (possibly compressed) */" \
  "method,    /* Compression method (integer) */"                  \
  "f HIDDEN   /* Name of zip file */"                              \
");"

#define ZIPFILE_F_COLUMN_IDX 6    /* Index of column "f" in the above */
#define ZIPFILE_BUFFER_SIZE (64*1024)


/*
** Magic numbers used to read and write zip files.
**
** ZIPFILE_NEWENTRY_MADEBY:







|
|
|
|
|
>
|
|
|


|







3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
/* typedef sqlite3_int64 i64; */
/* typedef unsigned char u8; */
typedef unsigned short u16;
typedef unsigned long u32;
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#endif

#define ZIPFILE_SCHEMA "CREATE TABLE y("                              \
  "name,      /* 0: Name of file in zip archive */"                   \
  "mode,      /* 1: POSIX mode for file */"                           \
  "mtime,     /* 2: Last modification time in seconds since epoch */" \
  "sz,        /* 3: Size of object */"                                \
  "rawdata,   /* 4: Raw data */"                                      \
  "data,      /* 5: Uncompressed data */"                             \
  "method,    /* 6: Compression method (integer) */"                  \
  "file HIDDEN   /* Name of zip file */"                              \
");"

#define ZIPFILE_F_COLUMN_IDX 7    /* Index of column "f" in the above */
#define ZIPFILE_BUFFER_SIZE (64*1024)


/*
** Magic numbers used to read and write zip files.
**
** ZIPFILE_NEWENTRY_MADEBY:
4511
4512
4513
4514
4515
4516
4517










































































4518
4519
4520
4521
4522
4523
4524
    (res.tm_hour << 11));

  pCds->mDate = (u16)(
    (res.tm_mday-1) +
    ((res.tm_mon+1) << 5) +
    ((res.tm_year-80) << 9));
}











































































/*
** Return values of columns for the row at which the series_cursor
** is currently pointing.
*/
static int zipfileColumn(
  sqlite3_vtab_cursor *cur,   /* The cursor */







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
    (res.tm_hour << 11));

  pCds->mDate = (u16)(
    (res.tm_mday-1) +
    ((res.tm_mon+1) << 5) +
    ((res.tm_year-80) << 9));
}

static void zipfileInflate(
  sqlite3_context *pCtx,          /* Store error here, if any */
  const u8 *aIn,                  /* Compressed data */
  int nIn,                        /* Size of buffer aIn[] in bytes */
  int nOut                        /* Expected output size */
){
  u8 *aRes = sqlite3_malloc(nOut);
  if( aRes==0 ){
    sqlite3_result_error_nomem(pCtx);
  }else{
    int err;
    z_stream str;
    memset(&str, 0, sizeof(str));

    str.next_in = (Byte*)aIn;
    str.avail_in = nIn;
    str.next_out = (Byte*)aRes;
    str.avail_out = nOut;

    err = inflateInit2(&str, -15);
    if( err!=Z_OK ){
      zipfileCtxErrorMsg(pCtx, "inflateInit2() failed (%d)", err);
    }else{
      err = inflate(&str, Z_NO_FLUSH);
      if( err!=Z_STREAM_END ){
        zipfileCtxErrorMsg(pCtx, "inflate() failed (%d)", err);
      }else{
        sqlite3_result_blob(pCtx, aRes, nOut, SQLITE_TRANSIENT);
      }
    }
    sqlite3_free(aRes);
    inflateEnd(&str);
  }
}

static int zipfileDeflate(
  ZipfileTab *pTab,               /* Set error message here */
  const u8 *aIn, int nIn,         /* Input */
  u8 **ppOut, int *pnOut          /* Output */
){
  int nAlloc = (int)compressBound(nIn);
  u8 *aOut;
  int rc = SQLITE_OK;

  aOut = (u8*)sqlite3_malloc(nAlloc);
  if( aOut==0 ){
    rc = SQLITE_NOMEM;
  }else{
    int res;
    z_stream str;
    memset(&str, 0, sizeof(str));
    str.next_in = (z_const Bytef*)aIn;
    str.avail_in = nIn;
    str.next_out = aOut;
    str.avail_out = nAlloc;

    deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
    res = deflate(&str, Z_FINISH);

    if( res==Z_STREAM_END ){
      *ppOut = aOut;
      *pnOut = (int)str.total_out;
    }else{
      sqlite3_free(aOut);
      pTab->base.zErrMsg = sqlite3_mprintf("zipfile: deflate() error");
      rc = SQLITE_ERROR;
    }
    deflateEnd(&str);
  }

  return rc;
}


/*
** Return values of columns for the row at which the series_cursor
** is currently pointing.
*/
static int zipfileColumn(
  sqlite3_vtab_cursor *cur,   /* The cursor */
4544
4545
4546
4547
4548
4549
4550

4551

4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563



4564

4565
4566
4567

4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
      }
      break;
    }
    case 3: { /* sz */
      sqlite3_result_int64(ctx, pCsr->cds.szUncompressed);
      break;
    }

    case 4: { /* data */

      int sz = pCsr->cds.szCompressed;
      if( sz>0 ){
        u8 *aBuf = sqlite3_malloc(sz);
        if( aBuf==0 ){
          rc = SQLITE_NOMEM;
        }else{
          FILE *pFile = zipfileGetFd(pCsr);
          rc = zipfileReadData(pFile, aBuf, sz, pCsr->iDataOff,
              &pCsr->base.pVtab->zErrMsg
          );
        }
        if( rc==SQLITE_OK ){



          sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT);

          sqlite3_free(aBuf);
        }
      }

      break;
    }
    case 5:   /* method */
      sqlite3_result_int(ctx, pCsr->cds.iCompression);
      break;
  }

  return SQLITE_OK;
}








>
|
>
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
|
>
|
|
|
>


|







4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
      }
      break;
    }
    case 3: { /* sz */
      sqlite3_result_int64(ctx, pCsr->cds.szUncompressed);
      break;
    }
    case 4:   /* rawdata */
    case 5: { /* data */
      if( i==4 || pCsr->cds.iCompression==0 || pCsr->cds.iCompression==8 ){
        int sz = pCsr->cds.szCompressed;
        if( sz>0 ){
          u8 *aBuf = sqlite3_malloc(sz);
          if( aBuf==0 ){
            rc = SQLITE_NOMEM;
          }else{
            FILE *pFile = zipfileGetFd(pCsr);
            rc = zipfileReadData(pFile, aBuf, sz, pCsr->iDataOff,
                &pCsr->base.pVtab->zErrMsg
            );
          }
          if( rc==SQLITE_OK ){
            if( i==5 && pCsr->cds.iCompression ){
              zipfileInflate(ctx, aBuf, sz, pCsr->cds.szUncompressed);
            }else{
              sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT);
            }
            sqlite3_free(aBuf);
          }
        }
      }
      break;
    }
    case 6:   /* method */
      sqlite3_result_int(ctx, pCsr->cds.iCompression);
      break;
  }

  return SQLITE_OK;
}

4914
4915
4916
4917
4918
4919
4920
4921


4922
4923
4924
4925
4926
4927
4928

  return rc;
}

static int zipfileGetMode(ZipfileTab *pTab, sqlite3_value *pVal, int *pMode){
  const char *z = (const char*)sqlite3_value_text(pVal);
  int mode = 0;
  if( z==0 || (z[0]>=0 && z[0]<=9) ){


    mode = sqlite3_value_int(pVal);
  }else{
    const char zTemplate[11] = "-rwxrwxrwx";
    int i;
    if( strlen(z)!=10 ) goto parse_error;
    switch( z[0] ){
      case '-': mode |= S_IFREG; break;







|
>
>







4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013

  return rc;
}

static int zipfileGetMode(ZipfileTab *pTab, sqlite3_value *pVal, int *pMode){
  const char *z = (const char*)sqlite3_value_text(pVal);
  int mode = 0;
  if( z==0 ){
    mode = 33188;                 /* -rw-r--r-- */
  }else if( z[0]>=0 && z[0]<=9 ){
    mode = sqlite3_value_int(pVal);
  }else{
    const char zTemplate[11] = "-rwxrwxrwx";
    int i;
    if( strlen(z)!=10 ) goto parse_error;
    switch( z[0] ){
      case '-': mode |= S_IFREG; break;
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
){
  ZipfileTab *pTab = (ZipfileTab*)pVtab;
  int rc = SQLITE_OK;             /* Return Code */
  ZipfileEntry *pNew = 0;         /* New in-memory CDS entry */

  int mode;                       /* Mode for new entry */
  i64 mTime;                      /* Modification time for new entry */
  i64 sz;                         /* Uncompressed size */
  const char *zPath;              /* Path for new entry */
  int nPath;                      /* strlen(zPath) */
  const u8 *pData;                /* Pointer to buffer containing content */
  int nData;                      /* Size of pData buffer in bytes */
  int iMethod = 0;                /* Compression method for new entry */
  u8 *pFree = 0;                  /* Free this */
  ZipfileCDS cds;                 /* New Central Directory Structure entry */

  assert( pTab->zFile );
  assert( pTab->pWriteFd );








|


|
|







5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
){
  ZipfileTab *pTab = (ZipfileTab*)pVtab;
  int rc = SQLITE_OK;             /* Return Code */
  ZipfileEntry *pNew = 0;         /* New in-memory CDS entry */

  int mode;                       /* Mode for new entry */
  i64 mTime;                      /* Modification time for new entry */
  i64 sz = 0;                     /* Uncompressed size */
  const char *zPath;              /* Path for new entry */
  int nPath;                      /* strlen(zPath) */
  const u8 *pData = 0;            /* Pointer to buffer containing content */
  int nData = 0;                  /* Size of pData buffer in bytes */
  int iMethod = 0;                /* Compression method for new entry */
  u8 *pFree = 0;                  /* Free this */
  ZipfileCDS cds;                 /* New Central Directory Structure entry */

  assert( pTab->zFile );
  assert( pTab->pWriteFd );

4984
4985
4986
4987
4988
4989
4990



4991

4992




4993
4994

4995
4996
4997
4998
4999


5000

5001



5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021

5022








5023
5024
5025
5026
5027
5028
5029


5030
5031
5032
5033
5034
5035
5036
    if( nVal==1 ) return SQLITE_OK;
  }

  zPath = (const char*)sqlite3_value_text(apVal[2]);
  nPath = (int)strlen(zPath);
  rc = zipfileGetMode(pTab, apVal[3], &mode);
  if( rc!=SQLITE_OK ) return rc;



  mTime = sqlite3_value_int64(apVal[4]);

  sz = sqlite3_value_int(apVal[5]);




  pData = sqlite3_value_blob(apVal[6]);
  nData = sqlite3_value_bytes(apVal[6]);


  /* If a NULL value is inserted into the 'method' column, do automatic
  ** compression. */
  if( nData>0 && sqlite3_value_type(apVal[7])==SQLITE_NULL ){
    pFree = (u8*)sqlite3_malloc(nData);


    if( pFree==0 ){

      rc = SQLITE_NOMEM;



    }else{
      int res;
      z_stream str;
      memset(&str, 0, sizeof(str));
      str.next_in = (z_const Bytef*)pData;
      str.avail_in = nData;
      str.next_out = pFree;
      str.avail_out = nData;
      deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
      res = deflate(&str, Z_FINISH);
      if( res==Z_STREAM_END ){
        pData = pFree;
        nData = str.total_out;
        iMethod = 8;
      }else if( res!=Z_OK ){
        pTab->base.zErrMsg = sqlite3_mprintf("zipfile: deflate() error");
        rc = SQLITE_ERROR;
      }
      deflateEnd(&str);
    }

  }else{








    iMethod = sqlite3_value_int(apVal[7]);
    if( iMethod<0 || iMethod>65535 ){
      pTab->base.zErrMsg = sqlite3_mprintf(
          "zipfile: invalid compression method: %d", iMethod
      );
      rc = SQLITE_ERROR;
    }


  }

  if( rc==SQLITE_OK ){
    /* Create the new CDS record. */
    memset(&cds, 0, sizeof(cds));
    cds.iVersionMadeBy = ZIPFILE_NEWENTRY_MADEBY;
    cds.iVersionExtract = ZIPFILE_NEWENTRY_REQUIRED;







>
>
>
|
>
|
>
>
>
>
|
|
>
|
<
<
|
|
>
>
|
>
|
>
>
>
|
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
<
|
<
|
>
|
>
>
>
>
>
>
>
>
|






>
>







5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089


5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100










5101
5102




5103

5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
    if( nVal==1 ) return SQLITE_OK;
  }

  zPath = (const char*)sqlite3_value_text(apVal[2]);
  nPath = (int)strlen(zPath);
  rc = zipfileGetMode(pTab, apVal[3], &mode);
  if( rc!=SQLITE_OK ) return rc;
  if( sqlite3_value_type(apVal[4])==SQLITE_NULL ){
    mTime = (sqlite3_int64)time(0);
  }else{
    mTime = sqlite3_value_int64(apVal[4]);
  }

  if( sqlite3_value_type(apVal[5])==SQLITE_NULL    /* sz */
   && sqlite3_value_type(apVal[6])==SQLITE_NULL    /* rawdata */
   && sqlite3_value_type(apVal[7])!=SQLITE_NULL    /* data */
  ){
    const u8 *aIn = sqlite3_value_blob(apVal[7]);
    int nIn = sqlite3_value_bytes(apVal[7]);
    int bAuto = sqlite3_value_type(apVal[8])==SQLITE_NULL;
    


    iMethod = sqlite3_value_int(apVal[8]);
    sz = nIn;
    if( iMethod!=0 && iMethod!=8 ){
      rc = SQLITE_CONSTRAINT;
    }else if( bAuto || iMethod ){
      rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nData);
      if( rc==SQLITE_OK ){
        if( iMethod || nData<nIn ){
          iMethod = 8;
          pData = pFree;
        }else{










          pData = aIn;
          nData = nIn;




        }

      }
    }
  }else 
  if( sqlite3_value_type(apVal[5])!=SQLITE_NULL    /* sz */
   && sqlite3_value_type(apVal[6])!=SQLITE_NULL    /* rawdata */
   && sqlite3_value_type(apVal[7])==SQLITE_NULL    /* data */
   && sqlite3_value_type(apVal[8])!=SQLITE_NULL    /* method */
  ){
    pData = sqlite3_value_blob(apVal[6]);
    nData = sqlite3_value_bytes(apVal[6]);
    sz = sqlite3_value_int(apVal[5]);
    iMethod = sqlite3_value_int(apVal[8]);
    if( iMethod<0 || iMethod>65535 ){
      pTab->base.zErrMsg = sqlite3_mprintf(
          "zipfile: invalid compression method: %d", iMethod
      );
      rc = SQLITE_ERROR;
    }
  }else{
    rc = SQLITE_CONSTRAINT;
  }

  if( rc==SQLITE_OK ){
    /* Create the new CDS record. */
    memset(&cds, 0, sizeof(cds));
    cds.iVersionMadeBy = ZIPFILE_NEWENTRY_MADEBY;
    cds.iVersionExtract = ZIPFILE_NEWENTRY_REQUIRED;
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
  int rc = sqlite3_create_module(db, "zipfile"  , &zipfileModule, 0);
  return rc;
}
#else         /* SQLITE_OMIT_VIRTUALTABLE */
# define zipfileRegister(x) SQLITE_OK
#endif

/*
** zipfile_uncompress(DATA, SZ, METHOD)
*/
static void zipfileUncompressFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  int iMethod;

  iMethod = sqlite3_value_int(argv[2]);
  if( iMethod==0 ){
    sqlite3_result_value(context, argv[0]);
  }else if( iMethod==8 ){
    Byte *res;
    int sz = sqlite3_value_int(argv[1]);
    z_stream str;
    memset(&str, 0, sizeof(str));
    str.next_in = (Byte*)sqlite3_value_blob(argv[0]);
    str.avail_in = sqlite3_value_bytes(argv[0]);
    res = str.next_out = (Byte*)sqlite3_malloc(sz);
    if( res==0 ){
      sqlite3_result_error_nomem(context);
    }else{
      int err;
      str.avail_out = sz;

      err = inflateInit2(&str, -15);
      if( err!=Z_OK ){
        zipfileCtxErrorMsg(context, "inflateInit2() failed (%d)", err);
      }else{
        err = inflate(&str, Z_NO_FLUSH);
        if( err!=Z_STREAM_END ){
          zipfileCtxErrorMsg(context, "inflate() failed (%d)", err);
        }else{
          sqlite3_result_blob(context, res, sz, SQLITE_TRANSIENT);
        }
      }
      sqlite3_free(res);
      inflateEnd(&str);
    }
  }else{
    zipfileCtxErrorMsg(context, "unrecognized compression method: %d", iMethod);
  }
}

#ifdef _WIN32

#endif
int sqlite3_zipfile_init(
  sqlite3 *db, 
  char **pzErrMsg, 
  const sqlite3_api_routines *pApi
){
  int rc = SQLITE_OK;
  SQLITE_EXTENSION_INIT2(pApi);
  (void)pzErrMsg;  /* Unused parameter */
  rc = sqlite3_create_function(db, "zipfile_uncompress", 3,
      SQLITE_UTF8, 0, zipfileUncompressFunc, 0, 0
  );
  if( rc!=SQLITE_OK ) return rc;
  return zipfileRegister(db);
}


/************************* End ../ext/misc/zipfile.c ********************/
/************************* Begin ../ext/misc/sqlar.c ******************/
/*







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<








<


<
<
<
<







5287
5288
5289
5290
5291
5292
5293














































5294
5295
5296
5297
5298
5299
5300
5301

5302
5303




5304
5305
5306
5307
5308
5309
5310
  int rc = sqlite3_create_module(db, "zipfile"  , &zipfileModule, 0);
  return rc;
}
#else         /* SQLITE_OMIT_VIRTUALTABLE */
# define zipfileRegister(x) SQLITE_OK
#endif















































#ifdef _WIN32

#endif
int sqlite3_zipfile_init(
  sqlite3 *db, 
  char **pzErrMsg, 
  const sqlite3_api_routines *pApi
){

  SQLITE_EXTENSION_INIT2(pApi);
  (void)pzErrMsg;  /* Unused parameter */




  return zipfileRegister(db);
}


/************************* End ../ext/misc/zipfile.c ********************/
/************************* Begin ../ext/misc/sqlar.c ******************/
/*
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
          pScan->pOrder = pNew;
          n++;
        }
      }
    }
  }

  pIdxInfo->estimatedCost = 1000000.0 / n;
  return rc;
}

static int expertUpdate(
  sqlite3_vtab *pVtab, 
  int nData, 
  sqlite3_value **azData, 







|







6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
          pScan->pOrder = pNew;
          n++;
        }
      }
    }
  }

  pIdxInfo->estimatedCost = 1000000.0 / (n+1);
  return rc;
}

static int expertUpdate(
  sqlite3_vtab *pVtab, 
  int nData, 
  sqlite3_value **azData, 
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
  if( *pRc==SQLITE_OK ){
    zAppend = sqlite3_vmprintf(zFmt, ap);
    if( zAppend ){
      nAppend = STRLEN(zAppend);
      zRet = (char*)sqlite3_malloc(nIn + nAppend + 1);
    }
    if( zAppend && zRet ){
      memcpy(zRet, zIn, nIn);
      memcpy(&zRet[nIn], zAppend, nAppend+1);
    }else{
      sqlite3_free(zRet);
      zRet = 0;
      *pRc = SQLITE_NOMEM;
    }
    sqlite3_free(zAppend);







|







6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
  if( *pRc==SQLITE_OK ){
    zAppend = sqlite3_vmprintf(zFmt, ap);
    if( zAppend ){
      nAppend = STRLEN(zAppend);
      zRet = (char*)sqlite3_malloc(nIn + nAppend + 1);
    }
    if( zAppend && zRet ){
      if( nIn ) memcpy(zRet, zIn, nIn);
      memcpy(&zRet[nIn], zAppend, nAppend+1);
    }else{
      sqlite3_free(zRet);
      zRet = 0;
      *pRc = SQLITE_NOMEM;
    }
    sqlite3_free(zAppend);
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
  sqlite3 *dbm = p->dbm;
  int rc = SQLITE_OK;
  if( (pEq || pTail) && 0==idxFindCompatible(&rc, dbm, pScan, pEq, pTail) ){
    IdxTable *pTab = pScan->pTab;
    char *zCols = 0;
    char *zIdx = 0;
    IdxConstraint *pCons;
    int h = 0;
    const char *zFmt;

    for(pCons=pEq; pCons; pCons=pCons->pLink){
      zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
    }
    for(pCons=pTail; pCons; pCons=pCons->pLink){
      zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);







|







6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
  sqlite3 *dbm = p->dbm;
  int rc = SQLITE_OK;
  if( (pEq || pTail) && 0==idxFindCompatible(&rc, dbm, pScan, pEq, pTail) ){
    IdxTable *pTab = pScan->pTab;
    char *zCols = 0;
    char *zIdx = 0;
    IdxConstraint *pCons;
    unsigned int h = 0;
    const char *zFmt;

    for(pCons=pEq; pCons; pCons=pCons->pLink){
      zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
    }
    for(pCons=pTail; pCons; pCons=pCons->pLink){
      zCols = idxAppendColDefn(&rc, zCols, pTab, pCons);
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
    "SELECT "
    "  :1 || name, "
    "  writefile(?1 || name, %s, mode, mtime) "
    "FROM %s WHERE (%s) AND (data IS NULL OR ?2 = 0)";

  const char *azExtraArg[] = { 
    "sqlar_uncompress(data, sz)",
    "zipfile_uncompress(data, sz, method)"
  };
  const char *azSource[] = {
    "sqlar", "zipfile(?3)"
  };



  sqlite3_stmt *pSql = 0;
  int rc = SQLITE_OK;
  char *zDir = 0;
  char *zWhere = 0;
  int i;








|




<
<







11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486


11487
11488
11489
11490
11491
11492
11493
    "SELECT "
    "  :1 || name, "
    "  writefile(?1 || name, %s, mode, mtime) "
    "FROM %s WHERE (%s) AND (data IS NULL OR ?2 = 0)";

  const char *azExtraArg[] = { 
    "sqlar_uncompress(data, sz)",
    "data"
  };
  const char *azSource[] = {
    "sqlar", "zipfile(?3)"
  };



  sqlite3_stmt *pSql = 0;
  int rc = SQLITE_OK;
  char *zDir = 0;
  char *zWhere = 0;
  int i;

Changes to src/sqlite3.c.
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION        "3.22.0"
#define SQLITE_VERSION_NUMBER 3022000
#define SQLITE_SOURCE_ID      "2018-01-07 23:28:10 90cb01d8d6ac12d0b88f2952a75aeefa81ba66f5e4a5377fdd8b9f86aec8e927"

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







|







1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION        "3.22.0"
#define SQLITE_VERSION_NUMBER 3022000
#define SQLITE_SOURCE_ID      "2018-01-09 00:28:24 4a7236140cb0f40fa846da4673a0d56218def1929d58cf016909ce881a681140"

/*
** CAPI3REF: Run-Time Library Version Numbers
** KEYWORDS: sqlite3_version sqlite3_sourceid
**
** These interfaces provide the same information as the [SQLITE_VERSION],
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
202939
202940
202941
202942
202943
202944
202945
202946
202947
202948
202949
202950
202951
202952
202953
static void fts5SourceIdFunc(
  sqlite3_context *pCtx,          /* Function call context */
  int nArg,                       /* Number of args */
  sqlite3_value **apUnused        /* Function arguments */
){
  assert( nArg==0 );
  UNUSED_PARAM2(nArg, apUnused);
  sqlite3_result_text(pCtx, "fts5: 2018-01-06 15:49:57 252ee55a7fc0b068b707af27bd912e684c28320996e78f0675217046b8c2fb49", -1, SQLITE_TRANSIENT);
}

static int fts5Init(sqlite3 *db){
  static const sqlite3_module fts5Mod = {
    /* iVersion      */ 2,
    /* xCreate       */ fts5CreateMethod,
    /* xConnect      */ fts5ConnectMethod,







|







202939
202940
202941
202942
202943
202944
202945
202946
202947
202948
202949
202950
202951
202952
202953
static void fts5SourceIdFunc(
  sqlite3_context *pCtx,          /* Function call context */
  int nArg,                       /* Number of args */
  sqlite3_value **apUnused        /* Function arguments */
){
  assert( nArg==0 );
  UNUSED_PARAM2(nArg, apUnused);
  sqlite3_result_text(pCtx, "fts5: 2018-01-09 00:28:24 4a7236140cb0f40fa846da4673a0d56218def1929d58cf016909ce881a681140", -1, SQLITE_TRANSIENT);
}

static int fts5Init(sqlite3 *db){
  static const sqlite3_module fts5Mod = {
    /* iVersion      */ 2,
    /* xCreate       */ fts5CreateMethod,
    /* xConnect      */ fts5ConnectMethod,
207209
207210
207211
207212
207213
207214
207215
207216
207217
207218
207219
207220
}
#endif /* SQLITE_CORE */
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */

/************** End of stmt.c ************************************************/
#if __LINE__!=207214
#undef SQLITE_SOURCE_ID
#define SQLITE_SOURCE_ID      "2018-01-07 23:28:10 90cb01d8d6ac12d0b88f2952a75aeefa81ba66f5e4a5377fdd8b9f86aec8alt2"
#endif
/* Return the source-id for this library */
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
/************************** End of sqlite3.c ******************************/







|




207209
207210
207211
207212
207213
207214
207215
207216
207217
207218
207219
207220
}
#endif /* SQLITE_CORE */
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */

/************** End of stmt.c ************************************************/
#if __LINE__!=207214
#undef SQLITE_SOURCE_ID
#define SQLITE_SOURCE_ID      "2018-01-09 00:28:24 4a7236140cb0f40fa846da4673a0d56218def1929d58cf016909ce881a68alt2"
#endif
/* Return the source-id for this library */
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
/************************** End of sqlite3.c ******************************/
Changes to src/sqlite3.h.
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION        "3.22.0"
#define SQLITE_VERSION_NUMBER 3022000
#define SQLITE_SOURCE_ID      "2018-01-07 23:28:10 90cb01d8d6ac12d0b88f2952a75aeefa81ba66f5e4a5377fdd8b9f86aec8e927"

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







|







121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
**
** See also: [sqlite3_libversion()],
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION        "3.22.0"
#define SQLITE_VERSION_NUMBER 3022000
#define SQLITE_SOURCE_ID      "2018-01-09 00:28:24 4a7236140cb0f40fa846da4673a0d56218def1929d58cf016909ce881a681140"

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