| | @@ -92,14 +92,14 @@ |
| 92 | 92 | # include <signal.h> |
| 93 | 93 | # if !defined(__RTP__) && !defined(_WRS_KERNEL) |
| 94 | 94 | # include <pwd.h> |
| 95 | 95 | # endif |
| 96 | 96 | #endif |
| 97 | | -#if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW_H) |
| 97 | +#if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW32__) |
| 98 | 98 | # include <unistd.h> |
| 99 | 99 | # include <dirent.h> |
| 100 | | -# if defined(__MINGW_H) |
| 100 | +# if defined(__MINGW32__) |
| 101 | 101 | # define DIRENT dirent |
| 102 | 102 | # ifndef S_ISLNK |
| 103 | 103 | # define S_ISLNK(mode) (0) |
| 104 | 104 | # endif |
| 105 | 105 | # endif |
| | @@ -818,12 +818,13 @@ |
| 818 | 818 | sqlite3_value **apVal |
| 819 | 819 | ){ |
| 820 | 820 | const char *zName = (const char*)sqlite3_value_text(apVal[0]); |
| 821 | 821 | char *zFake = shellFakeSchema(sqlite3_context_db_handle(pCtx), 0, zName); |
| 822 | 822 | if( zFake ){ |
| 823 | | - sqlite3_result_text(pCtx, sqlite3_mprintf("/* %z */", zFake), |
| 823 | + sqlite3_result_text(pCtx, sqlite3_mprintf("/* %s */", zFake), |
| 824 | 824 | -1, sqlite3_free); |
| 825 | + free(zFake); |
| 825 | 826 | } |
| 826 | 827 | } |
| 827 | 828 | |
| 828 | 829 | /* |
| 829 | 830 | ** SQL function: shell_add_schema(S,X) |
| | @@ -879,14 +880,15 @@ |
| 879 | 880 | if( zName |
| 880 | 881 | && aPrefix[i][0]=='V' |
| 881 | 882 | && (zFake = shellFakeSchema(db, zSchema, zName))!=0 |
| 882 | 883 | ){ |
| 883 | 884 | if( z==0 ){ |
| 884 | | - z = sqlite3_mprintf("%s\n/* %z */", zIn, zFake); |
| 885 | + z = sqlite3_mprintf("%s\n/* %s */", zIn, zFake); |
| 885 | 886 | }else{ |
| 886 | | - z = sqlite3_mprintf("%z\n/* %z */", z, zFake); |
| 887 | + z = sqlite3_mprintf("%z\n/* %s */", z, zFake); |
| 887 | 888 | } |
| 889 | + free(zFake); |
| 888 | 890 | } |
| 889 | 891 | if( z ){ |
| 890 | 892 | sqlite3_result_text(pCtx, z, -1, sqlite3_free); |
| 891 | 893 | return; |
| 892 | 894 | } |
| | @@ -2068,11 +2070,10 @@ |
| 2068 | 2070 | # include "windows.h" |
| 2069 | 2071 | # include <io.h> |
| 2070 | 2072 | # include <direct.h> |
| 2071 | 2073 | /* # include "test_windirent.h" */ |
| 2072 | 2074 | # define dirent DIRENT |
| 2073 | | -# define timespec TIMESPEC |
| 2074 | 2075 | # define stat _stat |
| 2075 | 2076 | # define mkdir(path,mode) _mkdir(path) |
| 2076 | 2077 | # define lstat(path,buf) _stat(path,buf) |
| 2077 | 2078 | #endif |
| 2078 | 2079 | #include <time.h> |
| | @@ -3885,21 +3886,22 @@ |
| 3885 | 3886 | typedef unsigned short u16; |
| 3886 | 3887 | typedef unsigned long u32; |
| 3887 | 3888 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) |
| 3888 | 3889 | #endif |
| 3889 | 3890 | |
| 3890 | | -#define ZIPFILE_SCHEMA "CREATE TABLE y(" \ |
| 3891 | | - "name, /* Name of file in zip archive */" \ |
| 3892 | | - "mode, /* POSIX mode for file */" \ |
| 3893 | | - "mtime, /* Last modification time in seconds since epoch */" \ |
| 3894 | | - "sz, /* Size of object */" \ |
| 3895 | | - "data, /* Data stored in zip file (possibly compressed) */" \ |
| 3896 | | - "method, /* Compression method (integer) */" \ |
| 3897 | | - "f HIDDEN /* Name of zip file */" \ |
| 3891 | +#define ZIPFILE_SCHEMA "CREATE TABLE y(" \ |
| 3892 | + "name, /* 0: Name of file in zip archive */" \ |
| 3893 | + "mode, /* 1: POSIX mode for file */" \ |
| 3894 | + "mtime, /* 2: Last modification time in seconds since epoch */" \ |
| 3895 | + "sz, /* 3: Size of object */" \ |
| 3896 | + "rawdata, /* 4: Raw data */" \ |
| 3897 | + "data, /* 5: Uncompressed data */" \ |
| 3898 | + "method, /* 6: Compression method (integer) */" \ |
| 3899 | + "file HIDDEN /* Name of zip file */" \ |
| 3898 | 3900 | ");" |
| 3899 | 3901 | |
| 3900 | | -#define ZIPFILE_F_COLUMN_IDX 6 /* Index of column "f" in the above */ |
| 3902 | +#define ZIPFILE_F_COLUMN_IDX 7 /* Index of column "f" in the above */ |
| 3901 | 3903 | #define ZIPFILE_BUFFER_SIZE (64*1024) |
| 3902 | 3904 | |
| 3903 | 3905 | |
| 3904 | 3906 | /* |
| 3905 | 3907 | ** Magic numbers used to read and write zip files. |
| | @@ -4513,10 +4515,84 @@ |
| 4513 | 4515 | pCds->mDate = (u16)( |
| 4514 | 4516 | (res.tm_mday-1) + |
| 4515 | 4517 | ((res.tm_mon+1) << 5) + |
| 4516 | 4518 | ((res.tm_year-80) << 9)); |
| 4517 | 4519 | } |
| 4520 | + |
| 4521 | +static void zipfileInflate( |
| 4522 | + sqlite3_context *pCtx, /* Store error here, if any */ |
| 4523 | + const u8 *aIn, /* Compressed data */ |
| 4524 | + int nIn, /* Size of buffer aIn[] in bytes */ |
| 4525 | + int nOut /* Expected output size */ |
| 4526 | +){ |
| 4527 | + u8 *aRes = sqlite3_malloc(nOut); |
| 4528 | + if( aRes==0 ){ |
| 4529 | + sqlite3_result_error_nomem(pCtx); |
| 4530 | + }else{ |
| 4531 | + int err; |
| 4532 | + z_stream str; |
| 4533 | + memset(&str, 0, sizeof(str)); |
| 4534 | + |
| 4535 | + str.next_in = (Byte*)aIn; |
| 4536 | + str.avail_in = nIn; |
| 4537 | + str.next_out = (Byte*)aRes; |
| 4538 | + str.avail_out = nOut; |
| 4539 | + |
| 4540 | + err = inflateInit2(&str, -15); |
| 4541 | + if( err!=Z_OK ){ |
| 4542 | + zipfileCtxErrorMsg(pCtx, "inflateInit2() failed (%d)", err); |
| 4543 | + }else{ |
| 4544 | + err = inflate(&str, Z_NO_FLUSH); |
| 4545 | + if( err!=Z_STREAM_END ){ |
| 4546 | + zipfileCtxErrorMsg(pCtx, "inflate() failed (%d)", err); |
| 4547 | + }else{ |
| 4548 | + sqlite3_result_blob(pCtx, aRes, nOut, SQLITE_TRANSIENT); |
| 4549 | + } |
| 4550 | + } |
| 4551 | + sqlite3_free(aRes); |
| 4552 | + inflateEnd(&str); |
| 4553 | + } |
| 4554 | +} |
| 4555 | + |
| 4556 | +static int zipfileDeflate( |
| 4557 | + ZipfileTab *pTab, /* Set error message here */ |
| 4558 | + const u8 *aIn, int nIn, /* Input */ |
| 4559 | + u8 **ppOut, int *pnOut /* Output */ |
| 4560 | +){ |
| 4561 | + int nAlloc = (int)compressBound(nIn); |
| 4562 | + u8 *aOut; |
| 4563 | + int rc = SQLITE_OK; |
| 4564 | + |
| 4565 | + aOut = (u8*)sqlite3_malloc(nAlloc); |
| 4566 | + if( aOut==0 ){ |
| 4567 | + rc = SQLITE_NOMEM; |
| 4568 | + }else{ |
| 4569 | + int res; |
| 4570 | + z_stream str; |
| 4571 | + memset(&str, 0, sizeof(str)); |
| 4572 | + str.next_in = (z_const Bytef*)aIn; |
| 4573 | + str.avail_in = nIn; |
| 4574 | + str.next_out = aOut; |
| 4575 | + str.avail_out = nAlloc; |
| 4576 | + |
| 4577 | + deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); |
| 4578 | + res = deflate(&str, Z_FINISH); |
| 4579 | + |
| 4580 | + if( res==Z_STREAM_END ){ |
| 4581 | + *ppOut = aOut; |
| 4582 | + *pnOut = (int)str.total_out; |
| 4583 | + }else{ |
| 4584 | + sqlite3_free(aOut); |
| 4585 | + pTab->base.zErrMsg = sqlite3_mprintf("zipfile: deflate() error"); |
| 4586 | + rc = SQLITE_ERROR; |
| 4587 | + } |
| 4588 | + deflateEnd(&str); |
| 4589 | + } |
| 4590 | + |
| 4591 | + return rc; |
| 4592 | +} |
| 4593 | + |
| 4518 | 4594 | |
| 4519 | 4595 | /* |
| 4520 | 4596 | ** Return values of columns for the row at which the series_cursor |
| 4521 | 4597 | ** is currently pointing. |
| 4522 | 4598 | */ |
| | @@ -4546,30 +4622,37 @@ |
| 4546 | 4622 | } |
| 4547 | 4623 | case 3: { /* sz */ |
| 4548 | 4624 | sqlite3_result_int64(ctx, pCsr->cds.szUncompressed); |
| 4549 | 4625 | break; |
| 4550 | 4626 | } |
| 4551 | | - case 4: { /* data */ |
| 4552 | | - int sz = pCsr->cds.szCompressed; |
| 4553 | | - if( sz>0 ){ |
| 4554 | | - u8 *aBuf = sqlite3_malloc(sz); |
| 4555 | | - if( aBuf==0 ){ |
| 4556 | | - rc = SQLITE_NOMEM; |
| 4557 | | - }else{ |
| 4558 | | - FILE *pFile = zipfileGetFd(pCsr); |
| 4559 | | - rc = zipfileReadData(pFile, aBuf, sz, pCsr->iDataOff, |
| 4560 | | - &pCsr->base.pVtab->zErrMsg |
| 4561 | | - ); |
| 4562 | | - } |
| 4563 | | - if( rc==SQLITE_OK ){ |
| 4564 | | - sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT); |
| 4565 | | - sqlite3_free(aBuf); |
| 4627 | + case 4: /* rawdata */ |
| 4628 | + case 5: { /* data */ |
| 4629 | + if( i==4 || pCsr->cds.iCompression==0 || pCsr->cds.iCompression==8 ){ |
| 4630 | + int sz = pCsr->cds.szCompressed; |
| 4631 | + if( sz>0 ){ |
| 4632 | + u8 *aBuf = sqlite3_malloc(sz); |
| 4633 | + if( aBuf==0 ){ |
| 4634 | + rc = SQLITE_NOMEM; |
| 4635 | + }else{ |
| 4636 | + FILE *pFile = zipfileGetFd(pCsr); |
| 4637 | + rc = zipfileReadData(pFile, aBuf, sz, pCsr->iDataOff, |
| 4638 | + &pCsr->base.pVtab->zErrMsg |
| 4639 | + ); |
| 4640 | + } |
| 4641 | + if( rc==SQLITE_OK ){ |
| 4642 | + if( i==5 && pCsr->cds.iCompression ){ |
| 4643 | + zipfileInflate(ctx, aBuf, sz, pCsr->cds.szUncompressed); |
| 4644 | + }else{ |
| 4645 | + sqlite3_result_blob(ctx, aBuf, sz, SQLITE_TRANSIENT); |
| 4646 | + } |
| 4647 | + sqlite3_free(aBuf); |
| 4648 | + } |
| 4566 | 4649 | } |
| 4567 | 4650 | } |
| 4568 | 4651 | break; |
| 4569 | 4652 | } |
| 4570 | | - case 5: /* method */ |
| 4653 | + case 6: /* method */ |
| 4571 | 4654 | sqlite3_result_int(ctx, pCsr->cds.iCompression); |
| 4572 | 4655 | break; |
| 4573 | 4656 | } |
| 4574 | 4657 | |
| 4575 | 4658 | return SQLITE_OK; |
| | @@ -4916,11 +4999,13 @@ |
| 4916 | 4999 | } |
| 4917 | 5000 | |
| 4918 | 5001 | static int zipfileGetMode(ZipfileTab *pTab, sqlite3_value *pVal, int *pMode){ |
| 4919 | 5002 | const char *z = (const char*)sqlite3_value_text(pVal); |
| 4920 | 5003 | int mode = 0; |
| 4921 | | - if( z==0 || (z[0]>=0 && z[0]<=9) ){ |
| 5004 | + if( z==0 ){ |
| 5005 | + mode = 33188; /* -rw-r--r-- */ |
| 5006 | + }else if( z[0]>=0 && z[0]<=9 ){ |
| 4922 | 5007 | mode = sqlite3_value_int(pVal); |
| 4923 | 5008 | }else{ |
| 4924 | 5009 | const char zTemplate[11] = "-rwxrwxrwx"; |
| 4925 | 5010 | int i; |
| 4926 | 5011 | if( strlen(z)!=10 ) goto parse_error; |
| | @@ -4958,15 +5043,15 @@ |
| 4958 | 5043 | int rc = SQLITE_OK; /* Return Code */ |
| 4959 | 5044 | ZipfileEntry *pNew = 0; /* New in-memory CDS entry */ |
| 4960 | 5045 | |
| 4961 | 5046 | int mode; /* Mode for new entry */ |
| 4962 | 5047 | i64 mTime; /* Modification time for new entry */ |
| 4963 | | - i64 sz; /* Uncompressed size */ |
| 5048 | + i64 sz = 0; /* Uncompressed size */ |
| 4964 | 5049 | const char *zPath; /* Path for new entry */ |
| 4965 | 5050 | int nPath; /* strlen(zPath) */ |
| 4966 | | - const u8 *pData; /* Pointer to buffer containing content */ |
| 4967 | | - int nData; /* Size of pData buffer in bytes */ |
| 5051 | + const u8 *pData = 0; /* Pointer to buffer containing content */ |
| 5052 | + int nData = 0; /* Size of pData buffer in bytes */ |
| 4968 | 5053 | int iMethod = 0; /* Compression method for new entry */ |
| 4969 | 5054 | u8 *pFree = 0; /* Free this */ |
| 4970 | 5055 | ZipfileCDS cds; /* New Central Directory Structure entry */ |
| 4971 | 5056 | |
| 4972 | 5057 | assert( pTab->zFile ); |
| | @@ -4986,49 +5071,58 @@ |
| 4986 | 5071 | |
| 4987 | 5072 | zPath = (const char*)sqlite3_value_text(apVal[2]); |
| 4988 | 5073 | nPath = (int)strlen(zPath); |
| 4989 | 5074 | rc = zipfileGetMode(pTab, apVal[3], &mode); |
| 4990 | 5075 | if( rc!=SQLITE_OK ) return rc; |
| 4991 | | - mTime = sqlite3_value_int64(apVal[4]); |
| 4992 | | - sz = sqlite3_value_int(apVal[5]); |
| 4993 | | - pData = sqlite3_value_blob(apVal[6]); |
| 4994 | | - nData = sqlite3_value_bytes(apVal[6]); |
| 4995 | | - |
| 4996 | | - /* If a NULL value is inserted into the 'method' column, do automatic |
| 4997 | | - ** compression. */ |
| 4998 | | - if( nData>0 && sqlite3_value_type(apVal[7])==SQLITE_NULL ){ |
| 4999 | | - pFree = (u8*)sqlite3_malloc(nData); |
| 5000 | | - if( pFree==0 ){ |
| 5001 | | - rc = SQLITE_NOMEM; |
| 5002 | | - }else{ |
| 5003 | | - int res; |
| 5004 | | - z_stream str; |
| 5005 | | - memset(&str, 0, sizeof(str)); |
| 5006 | | - str.next_in = (z_const Bytef*)pData; |
| 5007 | | - str.avail_in = nData; |
| 5008 | | - str.next_out = pFree; |
| 5009 | | - str.avail_out = nData; |
| 5010 | | - deflateInit2(&str, 9, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); |
| 5011 | | - res = deflate(&str, Z_FINISH); |
| 5012 | | - if( res==Z_STREAM_END ){ |
| 5013 | | - pData = pFree; |
| 5014 | | - nData = str.total_out; |
| 5015 | | - iMethod = 8; |
| 5016 | | - }else if( res!=Z_OK ){ |
| 5017 | | - pTab->base.zErrMsg = sqlite3_mprintf("zipfile: deflate() error"); |
| 5018 | | - rc = SQLITE_ERROR; |
| 5019 | | - } |
| 5020 | | - deflateEnd(&str); |
| 5021 | | - } |
| 5022 | | - }else{ |
| 5023 | | - iMethod = sqlite3_value_int(apVal[7]); |
| 5076 | + if( sqlite3_value_type(apVal[4])==SQLITE_NULL ){ |
| 5077 | + mTime = (sqlite3_int64)time(0); |
| 5078 | + }else{ |
| 5079 | + mTime = sqlite3_value_int64(apVal[4]); |
| 5080 | + } |
| 5081 | + |
| 5082 | + if( sqlite3_value_type(apVal[5])==SQLITE_NULL /* sz */ |
| 5083 | + && sqlite3_value_type(apVal[6])==SQLITE_NULL /* rawdata */ |
| 5084 | + && sqlite3_value_type(apVal[7])!=SQLITE_NULL /* data */ |
| 5085 | + ){ |
| 5086 | + const u8 *aIn = sqlite3_value_blob(apVal[7]); |
| 5087 | + int nIn = sqlite3_value_bytes(apVal[7]); |
| 5088 | + int bAuto = sqlite3_value_type(apVal[8])==SQLITE_NULL; |
| 5089 | + |
| 5090 | + iMethod = sqlite3_value_int(apVal[8]); |
| 5091 | + sz = nIn; |
| 5092 | + if( iMethod!=0 && iMethod!=8 ){ |
| 5093 | + rc = SQLITE_CONSTRAINT; |
| 5094 | + }else if( bAuto || iMethod ){ |
| 5095 | + rc = zipfileDeflate(pTab, aIn, nIn, &pFree, &nData); |
| 5096 | + if( rc==SQLITE_OK ){ |
| 5097 | + if( iMethod || nData<nIn ){ |
| 5098 | + iMethod = 8; |
| 5099 | + pData = pFree; |
| 5100 | + }else{ |
| 5101 | + pData = aIn; |
| 5102 | + nData = nIn; |
| 5103 | + } |
| 5104 | + } |
| 5105 | + } |
| 5106 | + }else |
| 5107 | + if( sqlite3_value_type(apVal[5])!=SQLITE_NULL /* sz */ |
| 5108 | + && sqlite3_value_type(apVal[6])!=SQLITE_NULL /* rawdata */ |
| 5109 | + && sqlite3_value_type(apVal[7])==SQLITE_NULL /* data */ |
| 5110 | + && sqlite3_value_type(apVal[8])!=SQLITE_NULL /* method */ |
| 5111 | + ){ |
| 5112 | + pData = sqlite3_value_blob(apVal[6]); |
| 5113 | + nData = sqlite3_value_bytes(apVal[6]); |
| 5114 | + sz = sqlite3_value_int(apVal[5]); |
| 5115 | + iMethod = sqlite3_value_int(apVal[8]); |
| 5024 | 5116 | if( iMethod<0 || iMethod>65535 ){ |
| 5025 | 5117 | pTab->base.zErrMsg = sqlite3_mprintf( |
| 5026 | 5118 | "zipfile: invalid compression method: %d", iMethod |
| 5027 | 5119 | ); |
| 5028 | 5120 | rc = SQLITE_ERROR; |
| 5029 | 5121 | } |
| 5122 | + }else{ |
| 5123 | + rc = SQLITE_CONSTRAINT; |
| 5030 | 5124 | } |
| 5031 | 5125 | |
| 5032 | 5126 | if( rc==SQLITE_OK ){ |
| 5033 | 5127 | /* Create the new CDS record. */ |
| 5034 | 5128 | memset(&cds, 0, sizeof(cds)); |
| | @@ -5195,71 +5289,20 @@ |
| 5195 | 5289 | } |
| 5196 | 5290 | #else /* SQLITE_OMIT_VIRTUALTABLE */ |
| 5197 | 5291 | # define zipfileRegister(x) SQLITE_OK |
| 5198 | 5292 | #endif |
| 5199 | 5293 | |
| 5200 | | -/* |
| 5201 | | -** zipfile_uncompress(DATA, SZ, METHOD) |
| 5202 | | -*/ |
| 5203 | | -static void zipfileUncompressFunc( |
| 5204 | | - sqlite3_context *context, |
| 5205 | | - int argc, |
| 5206 | | - sqlite3_value **argv |
| 5207 | | -){ |
| 5208 | | - int iMethod; |
| 5209 | | - |
| 5210 | | - iMethod = sqlite3_value_int(argv[2]); |
| 5211 | | - if( iMethod==0 ){ |
| 5212 | | - sqlite3_result_value(context, argv[0]); |
| 5213 | | - }else if( iMethod==8 ){ |
| 5214 | | - Byte *res; |
| 5215 | | - int sz = sqlite3_value_int(argv[1]); |
| 5216 | | - z_stream str; |
| 5217 | | - memset(&str, 0, sizeof(str)); |
| 5218 | | - str.next_in = (Byte*)sqlite3_value_blob(argv[0]); |
| 5219 | | - str.avail_in = sqlite3_value_bytes(argv[0]); |
| 5220 | | - res = str.next_out = (Byte*)sqlite3_malloc(sz); |
| 5221 | | - if( res==0 ){ |
| 5222 | | - sqlite3_result_error_nomem(context); |
| 5223 | | - }else{ |
| 5224 | | - int err; |
| 5225 | | - str.avail_out = sz; |
| 5226 | | - |
| 5227 | | - err = inflateInit2(&str, -15); |
| 5228 | | - if( err!=Z_OK ){ |
| 5229 | | - zipfileCtxErrorMsg(context, "inflateInit2() failed (%d)", err); |
| 5230 | | - }else{ |
| 5231 | | - err = inflate(&str, Z_NO_FLUSH); |
| 5232 | | - if( err!=Z_STREAM_END ){ |
| 5233 | | - zipfileCtxErrorMsg(context, "inflate() failed (%d)", err); |
| 5234 | | - }else{ |
| 5235 | | - sqlite3_result_blob(context, res, sz, SQLITE_TRANSIENT); |
| 5236 | | - } |
| 5237 | | - } |
| 5238 | | - sqlite3_free(res); |
| 5239 | | - inflateEnd(&str); |
| 5240 | | - } |
| 5241 | | - }else{ |
| 5242 | | - zipfileCtxErrorMsg(context, "unrecognized compression method: %d", iMethod); |
| 5243 | | - } |
| 5244 | | -} |
| 5245 | | - |
| 5246 | 5294 | #ifdef _WIN32 |
| 5247 | 5295 | |
| 5248 | 5296 | #endif |
| 5249 | 5297 | int sqlite3_zipfile_init( |
| 5250 | 5298 | sqlite3 *db, |
| 5251 | 5299 | char **pzErrMsg, |
| 5252 | 5300 | const sqlite3_api_routines *pApi |
| 5253 | 5301 | ){ |
| 5254 | | - int rc = SQLITE_OK; |
| 5255 | 5302 | SQLITE_EXTENSION_INIT2(pApi); |
| 5256 | 5303 | (void)pzErrMsg; /* Unused parameter */ |
| 5257 | | - rc = sqlite3_create_function(db, "zipfile_uncompress", 3, |
| 5258 | | - SQLITE_UTF8, 0, zipfileUncompressFunc, 0, 0 |
| 5259 | | - ); |
| 5260 | | - if( rc!=SQLITE_OK ) return rc; |
| 5261 | 5304 | return zipfileRegister(db); |
| 5262 | 5305 | } |
| 5263 | 5306 | |
| 5264 | 5307 | |
| 5265 | 5308 | /************************* End ../ext/misc/zipfile.c ********************/ |
| | @@ -6052,11 +6095,11 @@ |
| 6052 | 6095 | } |
| 6053 | 6096 | } |
| 6054 | 6097 | } |
| 6055 | 6098 | } |
| 6056 | 6099 | |
| 6057 | | - pIdxInfo->estimatedCost = 1000000.0 / n; |
| 6100 | + pIdxInfo->estimatedCost = 1000000.0 / (n+1); |
| 6058 | 6101 | return rc; |
| 6059 | 6102 | } |
| 6060 | 6103 | |
| 6061 | 6104 | static int expertUpdate( |
| 6062 | 6105 | sqlite3_vtab *pVtab, |
| | @@ -6311,11 +6354,11 @@ |
| 6311 | 6354 | if( zAppend ){ |
| 6312 | 6355 | nAppend = STRLEN(zAppend); |
| 6313 | 6356 | zRet = (char*)sqlite3_malloc(nIn + nAppend + 1); |
| 6314 | 6357 | } |
| 6315 | 6358 | if( zAppend && zRet ){ |
| 6316 | | - memcpy(zRet, zIn, nIn); |
| 6359 | + if( nIn ) memcpy(zRet, zIn, nIn); |
| 6317 | 6360 | memcpy(&zRet[nIn], zAppend, nAppend+1); |
| 6318 | 6361 | }else{ |
| 6319 | 6362 | sqlite3_free(zRet); |
| 6320 | 6363 | zRet = 0; |
| 6321 | 6364 | *pRc = SQLITE_NOMEM; |
| | @@ -6465,11 +6508,11 @@ |
| 6465 | 6508 | if( (pEq || pTail) && 0==idxFindCompatible(&rc, dbm, pScan, pEq, pTail) ){ |
| 6466 | 6509 | IdxTable *pTab = pScan->pTab; |
| 6467 | 6510 | char *zCols = 0; |
| 6468 | 6511 | char *zIdx = 0; |
| 6469 | 6512 | IdxConstraint *pCons; |
| 6470 | | - int h = 0; |
| 6513 | + unsigned int h = 0; |
| 6471 | 6514 | const char *zFmt; |
| 6472 | 6515 | |
| 6473 | 6516 | for(pCons=pEq; pCons; pCons=pCons->pLink){ |
| 6474 | 6517 | zCols = idxAppendColDefn(&rc, zCols, pTab, pCons); |
| 6475 | 6518 | } |
| | @@ -11434,17 +11477,15 @@ |
| 11434 | 11477 | " writefile(?1 || name, %s, mode, mtime) " |
| 11435 | 11478 | "FROM %s WHERE (%s) AND (data IS NULL OR ?2 = 0)"; |
| 11436 | 11479 | |
| 11437 | 11480 | const char *azExtraArg[] = { |
| 11438 | 11481 | "sqlar_uncompress(data, sz)", |
| 11439 | | - "zipfile_uncompress(data, sz, method)" |
| 11482 | + "data" |
| 11440 | 11483 | }; |
| 11441 | 11484 | const char *azSource[] = { |
| 11442 | 11485 | "sqlar", "zipfile(?3)" |
| 11443 | 11486 | }; |
| 11444 | | - |
| 11445 | | - |
| 11446 | 11487 | |
| 11447 | 11488 | sqlite3_stmt *pSql = 0; |
| 11448 | 11489 | int rc = SQLITE_OK; |
| 11449 | 11490 | char *zDir = 0; |
| 11450 | 11491 | char *zWhere = 0; |
| 11451 | 11492 | |