diff --git a/Makefile.in b/Makefile.in index a0217c4343..31e30ffc48 100644 --- a/Makefile.in +++ b/Makefile.in @@ -534,7 +534,7 @@ mptester$(EXE): sqlite3.c $(TOP)/mptest/mptest.c mkdir tsrc cp -f $(SRC) tsrc rm tsrc/sqlite.h.in tsrc/parse.y - $(TCLSH_CMD) $(TOP)/tool/vdbe-compress.tcl vdbe.new + $(TCLSH_CMD) $(TOP)/tool/vdbe-compress.tcl $(OPTS) vdbe.new mv vdbe.new tsrc/vdbe.c touch .target_source diff --git a/Makefile.msc b/Makefile.msc index 34059ea2f3..94cd38d0ae 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -911,7 +911,7 @@ mptester.exe: $(TOP)\mptest\mptest.c libsqlite3.lib $(LIBRESOBJS) sqlite3.h -mkdir tsrc for %i in ($(SRC)) do copy /Y %i tsrc del /Q tsrc\sqlite.h.in tsrc\parse.y - $(TCLSH_CMD) $(TOP)\tool\vdbe-compress.tcl < tsrc\vdbe.c > vdbe.new + $(TCLSH_CMD) $(TOP)\tool\vdbe-compress.tcl $(OPTS) < tsrc\vdbe.c > vdbe.new move vdbe.new tsrc\vdbe.c echo > .target_source diff --git a/main.mk b/main.mk index 41d1743832..a53727c904 100644 --- a/main.mk +++ b/main.mk @@ -402,7 +402,7 @@ target_source: $(SRC) $(TOP)/tool/vdbe-compress.tcl mkdir tsrc cp -f $(SRC) tsrc rm tsrc/sqlite.h.in tsrc/parse.y - tclsh $(TOP)/tool/vdbe-compress.tcl vdbe.new + tclsh $(TOP)/tool/vdbe-compress.tcl $(OPTS) vdbe.new mv vdbe.new tsrc/vdbe.c touch target_source diff --git a/manifest b/manifest index 8b592a7952..4df669542d 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Have\sthe\scrash-test\sinfrastructure\scode\sin\stest6.c\sread\sand\swrite\sthe\s512-byte\sblock\scontaining\sthe\spending-byte\slock\sas\snormal.\sEarlier\sversions\sdid\snot\saccess\sthis\spart\sof\sthe\sfile\sin\sorder\sto\savoid\striggering\san\sassert\sin\sos_unix.c.\sBut\sthe\sassert()\shas\ssince\sbeen\sremoved.\sAnd\snot\sreading/writing\sthis\spart\sof\sthe\sfile\scauses\sproblems\sfor\smultiplexor\stests. -D 2013-12-11T11:03:19.250 +C Merge\sin\sthe\slatest\strunk\schanges. +D 2013-12-11T14:17:06.145 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f -F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b +F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc bb1f271c8ee9773489c89be00f3f8ad7ed7ae8e0 +F Makefile.msc 4d4ead6b71d1bf03028fbd61da0ba0ec5e1556e1 F Makefile.vxworks db21ed42a01d5740e656b16f92cb5d8d5e5dd315 F README cd04a36fbc7ea56932a4052d7d0b7f09f27c33d6 F VERSION 8ed548d87d0a27fd7d7620476f9e25f9fa742d73 @@ -142,7 +142,7 @@ F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt f439556c5ce01ced70987e5ee86549a45165d9ff -F main.mk 82fd90375561d7b66287ae5a8b09e1e027394019 +F main.mk 9f091ea7920f8b15e48c7b6e5b6fb0182577ab2e F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f F mkextw.sh d2a981497b404d6498f5ff3e3b1f3816bdfcb338 @@ -178,7 +178,7 @@ F src/delete.c b36db1f79ee50eaca979660c9dd36437f5410b93 F src/expr.c 31a2b65339f6c3795d4cfa5e99798cd72f9fdfdf F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 2ab0f5384b70594468ef3ac5c7ed8ca24bfd17d5 -F src/func.c ef30d26ae4d79bbc7300c74e77fd117a0ba30235 +F src/func.c fed87f35cf4da4a798b726d84abefc209b48d831 F src/global.c 1d7bb7ea8254ae6a68ed9bfaf65fcb3d1690b486 F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4 F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22 @@ -188,8 +188,8 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c 355fc9ab213b43a4d8a96aadf2a84622e6668f0a -F src/malloc.c 543a8eb5508eaf4cadf55a9b503379eba2088128 +F src/main.c a79c8ca051a914e50d6b221d56801d47835714d8 +F src/malloc.c 0203ebce9152c6a0e5de520140b8ba65187350be F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c0c990fcaddff810ea277b4fb5d9138603dd5d4b F src/mem2.c dce31758da87ec2cfa52ba4c5df1aed6e07d8e8f @@ -207,7 +207,7 @@ F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_unix.c 60a7b3b23e6fcf83a50d1e320b280b551724e11f F src/os_win.c 16eac0961603182ffc10c02b39fe830126538e07 -F src/pager.c 994b3ee3716c89707952051115d72e0bd877e7b9 +F src/pager.c 95a568497d789d5729927fca93fec653c485df45 F src/pager.h 6a790b64a9ea79bc2c849bdefdd39e2344bca94a F src/parse.y acee1a9958539e21263362b194594c5255ad2fca F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 @@ -215,12 +215,12 @@ F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c a467393909a4ed7ca9de066d85ba5c5b04a5be63 F src/pragma.c 5ab7279d132143feb77f773688a24ab05da75fd7 F src/prepare.c 359d1a1e9c9bd4488e4dd3a1aaaf2d2ebb9bb768 -F src/printf.c aacd7f73018122689dbbe89d85c2e37f737b931f +F src/printf.c b2778aa160ef792ba51c9f11b743bfc015b66679 F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68 F src/resolve.c 7eda9097b29fcf3d2b42fdc17d1de672134e09b6 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c d41381d80a22d3a83352aeca274cccf264ac277a -F src/shell.c 936a72ff784efff3832cce274a96ed0b036e6758 +F src/shell.c 18924f6ccfa70da98bf9e388bab512c0fd1e792e F src/sqlite.h.in 592057b6b3881573c2d516bad30fb20171f16b05 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -280,15 +280,15 @@ F src/update.c d1c2477dcf14d90999d1935af4efb4806553250b F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/util.c 76ed0519296e3f62e97e57dab1999e34184c8e49 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c 4bfb1fe75a0ad08646e9b82670691c62699bc5ee +F src/vdbe.c 919422843c859a1db08db0c88189912dbf625fc7 F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644 -F src/vdbeInt.h 7e38eef8f4bd7141e1638b0eacaebf9bc41b26bc +F src/vdbeInt.h a7bc268f844d75be48bb7ae16f77b418fd3c641c F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed -F src/vdbeaux.c d64bc2a057e77aef3e2a4bc6670b80f516a36d55 +F src/vdbeaux.c 74f3ad068f91d60ff56179a22610e7b0ef71e5d6 F src/vdbeblob.c 8cd05a5630e6d5563ad017bf82edaf812b28acde -F src/vdbemem.c 2293b66374f4adf54bbdcd662c05a003318600e1 +F src/vdbemem.c ac71e169dc056936f7a26ccaa808cd17456ffab1 F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147 -F src/vdbetrace.c e7ec40e1999ff3c6414424365d5941178966dcbc +F src/vdbetrace.c f7eb148eb3b4fa3401b20024630dcb43d322e73c F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 @@ -804,7 +804,7 @@ F test/shell1.test e7c0b9ebda25d5e78f0a3ea0dc4e31bb6d8098c0 F test/shell2.test e1d3790f064e50b2f973502f45750012667486df F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29 F test/shell4.test aa4eef8118b412d1a01477a53426ece169ea86a9 -F test/shell5.test 46c8c18d62732415c4fe084816c13d559831705e +F test/shell5.test cee83b4385f842fec1f2a0bec9ea811f35386edf F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/shrink.test 8c70f62b6e8eb4d54533de6d65bd06b1b9a17868 F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329 @@ -1142,11 +1142,11 @@ F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 -F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 +F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 46231af985a1a872d1dc3418591cbaacb0b7c249 -R cf82896d56fef77694a1be0de6074b9d -U dan -Z ff5d29c735004d7eb85a84bef2a95faa +P fdc3f3fa3de1481860e1e2a819db2d6c4eb05658 5e239ecda0f7835ce037b38b04627a574b5854cd +R 67e94d0b56b00fc27eeae35854bf8ba9 +U drh +Z 7c7b3737dbf629b19ab7333ee0081c4f diff --git a/manifest.uuid b/manifest.uuid index fe1cfc392c..856d09cdcf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fdc3f3fa3de1481860e1e2a819db2d6c4eb05658 \ No newline at end of file +9ff4dfe1e36b40e386858b03f36cfab8f6806fdd \ No newline at end of file diff --git a/src/func.c b/src/func.c index 46c606ac06..951af97b35 100644 --- a/src/func.c +++ b/src/func.c @@ -1511,11 +1511,11 @@ static void groupConcatStep( zSep = ","; nSep = 1; } - sqlite3StrAccumAppend(pAccum, zSep, nSep); + if( nSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep); } zVal = (char*)sqlite3_value_text(argv[0]); nVal = sqlite3_value_bytes(argv[0]); - sqlite3StrAccumAppend(pAccum, zVal, nVal); + if( nVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal); } } static void groupConcatFinalize(sqlite3_context *context){ diff --git a/src/main.c b/src/main.c index 1ba555fde8..3e9f4e0171 100644 --- a/src/main.c +++ b/src/main.c @@ -588,7 +588,8 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ db->lookaside.bEnabled = 1; db->lookaside.bMalloced = pBuf==0 ?1:0; }else{ - db->lookaside.pEnd = 0; + db->lookaside.pStart = db; + db->lookaside.pEnd = db; db->lookaside.bEnabled = 0; db->lookaside.bMalloced = 0; } diff --git a/src/malloc.c b/src/malloc.c index 799f0485d4..9c11d07767 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -433,7 +433,7 @@ void sqlite3ScratchFree(void *p){ */ #ifndef SQLITE_OMIT_LOOKASIDE static int isLookaside(sqlite3 *db, void *p){ - return p && p>=db->lookaside.pStart && plookaside.pEnd; + return p>=db->lookaside.pStart && plookaside.pEnd; } #else #define isLookaside(A,B) 0 @@ -449,8 +449,9 @@ int sqlite3MallocSize(void *p){ return sqlite3GlobalConfig.m.xSize(p); } int sqlite3DbMallocSize(sqlite3 *db, void *p){ - assert( db==0 || sqlite3_mutex_held(db->mutex) ); - if( db && isLookaside(db, p) ){ + assert( db!=0 ); + assert( sqlite3_mutex_held(db->mutex) ); + if( isLookaside(db, p) ){ return db->lookaside.sz; }else{ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); diff --git a/src/pager.c b/src/pager.c index d2f16d1be5..b4988cece7 100644 --- a/src/pager.c +++ b/src/pager.c @@ -5785,7 +5785,7 @@ int sqlite3PagerWrite(DbPage *pDbPage){ assert( pPager->eState!=PAGER_ERROR ); assert( assert_pager_state(pPager) ); - if( pPager->sectorSize > pPager->pageSize ){ + if( pPager->sectorSize > (u32)pPager->pageSize ){ Pgno nPageCount; /* Total number of pages in database file */ Pgno pg1; /* First page of the sector pPg is located on. */ int nPage = 0; /* Number of pages starting at pg1 to journal */ diff --git a/src/printf.c b/src/printf.c index 011eecdfaa..9be0fc9404 100644 --- a/src/printf.c +++ b/src/printf.c @@ -637,7 +637,7 @@ void sqlite3VXPrintf( } case etTOKEN: { Token *pToken = va_arg(ap, Token*); - if( pToken ){ + if( pToken && pToken->n ){ sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n); } length = width = 0; @@ -691,7 +691,7 @@ void sqlite3VXPrintf( ** Append N bytes of text from z to the StrAccum object. */ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ - assert( z!=0 || N==0 ); + assert( z!=0 ); assert( p->zText!=0 || p->nChar==0 || p->accError ); assert( N>=0 ); assert( p->accError==0 || p->nAlloc==0 ); @@ -743,7 +743,7 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ ** Append the complete text of zero-terminated string z[] to the p string. */ void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){ - return sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z)); + sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z)); } diff --git a/src/shell.c b/src/shell.c index 480ec5b455..7826fdf204 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1836,7 +1836,7 @@ static void csv_append_char(CSVReader *p, int c){ ** + Report syntax errors on stderr */ static char *csv_read_one_field(CSVReader *p){ - int c, pc; + int c, pc, ppc; int cSep = p->cSeparator; p->n = 0; c = fgetc(p->in); @@ -1847,7 +1847,7 @@ static char *csv_read_one_field(CSVReader *p){ if( c=='"' ){ int startLine = p->nLine; int cQuote = c; - pc = 0; + pc = ppc = 0; while( 1 ){ c = fgetc(p->in); if( c=='\n' ) p->nLine++; @@ -1859,7 +1859,7 @@ static char *csv_read_one_field(CSVReader *p){ } if( (c==cSep && pc==cQuote) || (c=='\n' && pc==cQuote) - || (c=='\n' && pc=='\r' && p->n>=2 && p->z[p->n-2]==cQuote) + || (c=='\n' && pc=='\r' && ppc==cQuote) || (c==EOF && pc==cQuote) ){ do{ p->n--; }while( p->z[p->n]!=cQuote ); @@ -1877,6 +1877,7 @@ static char *csv_read_one_field(CSVReader *p){ break; } csv_append_char(p, c); + ppc = pc; pc = c; } }else{ diff --git a/src/vdbe.c b/src/vdbe.c index a0a69e8a5c..3361120933 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2595,16 +2595,22 @@ case OP_MakeRecord: { pOut = &aMem[pOp->p3]; memAboutToChange(p, pOut); + /* Apply the requested affinity to all inputs + */ + assert( pData0<=pLast ); + if( zAffinity ){ + pRec = pData0; + do{ + applyAffinity(pRec, *(zAffinity++), encoding); + }while( (++pRec)<=pLast ); + } + /* Loop through the elements that will make up the record to figure ** out how much space is required for the new record. */ - assert( pData0<=pLast ); pRec = pLast; do{ assert( memIsValid(pRec) ); - if( zAffinity ){ - applyAffinity(pRec, zAffinity[pRec-pData0], encoding); - } serial_type = sqlite3VdbeSerialType(pRec, file_format); len = sqlite3VdbeSerialTypeLen(serial_type); if( pRec->flags & MEM_Zero ){ @@ -2656,7 +2662,7 @@ case OP_MakeRecord: { do{ serial_type = sqlite3VdbeSerialType(pRec, file_format); i += putVarint32(&zNewRecord[i], serial_type); /* serial type */ - j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, file_format); /* content */ + j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */ }while( (++pRec)<=pLast ); assert( i==nHdr ); assert( j==nByte ); @@ -2688,6 +2694,7 @@ case OP_Count: { /* out2-prerelease */ pCrsr = p->apCsr[pOp->p1]->pCursor; assert( pCrsr ); + nEntry = 0; /* Not needed. Only used to silence a warning. */ rc = sqlite3BtreeCount(pCrsr, &nEntry); pOut->u.i = nEntry; break; @@ -3708,7 +3715,6 @@ case OP_Found: { /* jump, in3 */ if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++; #endif - alreadyExists = 0; assert( pOp->p1>=0 && pOp->p1nCursor ); assert( pOp->p4type==P4_INT32 ); pC = p->apCsr[pOp->p1]; @@ -3716,6 +3722,7 @@ case OP_Found: { /* jump, in3 */ pIn3 = &aMem[pOp->p3]; assert( pC->pCursor!=0 ); assert( pC->isTable==0 ); + pFree = 0; /* Not needed. Only used to suppress a compiler warning. */ if( pOp->p4.i>0 ){ r.pKeyInfo = pC->pKeyInfo; r.nField = (u16)pOp->p4.i; @@ -4648,6 +4655,7 @@ case OP_IdxRowid: { /* out2-prerelease */ assert( pC->deferredMoveto==0 ); assert( pC->isTable==0 ); if( !pC->nullRow ){ + rowid = 0; /* Not needed. Only used to silence a warning. */ rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid); if( rc!=SQLITE_OK ){ goto abort_due_to_error; @@ -4711,6 +4719,7 @@ case OP_IdxGE: { /* jump */ #ifdef SQLITE_DEBUG { int i; for(i=0; iopcode==OP_IdxLT ){ res = -res; @@ -4771,6 +4780,7 @@ case OP_Destroy: { /* out2-prerelease */ iDb = pOp->p3; assert( iCnt==1 ); assert( (p->btreeMask & (((yDbMask)1)<aDb[iDb].pBt, pOp->p1, &iMoved); pOut->flags = MEM_Int; pOut->u.i = iMoved; @@ -5343,7 +5353,6 @@ case OP_FkIfZero: { /* jump */ ** an integer. */ case OP_MemMax: { /* in2 */ - Mem *pIn1; VdbeFrame *pFrame; if( p->pFrame ){ for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); diff --git a/src/vdbeInt.h b/src/vdbeInt.h index b01af20188..d6d71a3957 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -389,7 +389,7 @@ void sqlite3VdbePrintOp(FILE*, int, Op*); #endif u32 sqlite3VdbeSerialTypeLen(u32); u32 sqlite3VdbeSerialType(Mem*, int); -u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, int); +u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); void sqlite3VdbeDeleteAuxData(Vdbe*, int, int); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index c610de4562..9e1eb581f0 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -2835,8 +2835,7 @@ static u64 floatSwap(u64 in){ ** of bytes in the zero-filled tail is included in the return value only ** if those bytes were zeroed in buf[]. */ -u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, int file_format){ - u32 serial_type = sqlite3VdbeSerialType(pMem, file_format); +u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){ u32 len; /* Integer and Real */ diff --git a/src/vdbemem.c b/src/vdbemem.c index 451744291f..d5901b439a 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -59,18 +59,14 @@ int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){ /* ** Make sure pMem->z points to a writable allocation of at least -** n bytes. +** min(n,32) bytes. ** -** If the third argument passed to this function is true, then memory -** cell pMem must contain a string or blob. In this case the content is -** preserved. Otherwise, if the third parameter to this function is false, -** any current string or blob value may be discarded. -** -** This function sets the MEM_Dyn flag and clears any xDel callback. -** It also clears MEM_Ephem and MEM_Static. If the preserve flag is -** not set, Mem.n is zeroed. +** If the bPreserve argument is true, then copy of the content of +** pMem->z into the new allocation. pMem must be either a string or +** blob if bPreserve is true. If bPreserve is false, any prior content +** in pMem->z is discarded. */ -int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){ +int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){ assert( 1 >= ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) + (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + @@ -79,37 +75,39 @@ int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){ ); assert( (pMem->flags&MEM_RowSet)==0 ); - /* If the preserve flag is set to true, then the memory cell must already + /* If the bPreserve flag is set to true, then the memory cell must already ** contain a valid string or blob value. */ - assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); + assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); + testcase( bPreserve && pMem->z==0 ); - if( n<32 ) n = 32; - if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)z==pMem->zMalloc ){ + if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)z==pMem->zMalloc ){ pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n); - preserve = 0; + bPreserve = 0; }else{ sqlite3DbFree(pMem->db, pMem->zMalloc); pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n); } + if( pMem->zMalloc==0 ){ + sqlite3VdbeMemRelease(pMem); + pMem->flags = MEM_Null; + return SQLITE_NOMEM; + } } - if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){ + if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){ memcpy(pMem->zMalloc, pMem->z, pMem->n); } - if( pMem->flags&MEM_Dyn && pMem->xDel ){ + if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){ assert( pMem->xDel!=SQLITE_DYNAMIC ); pMem->xDel((void *)(pMem->z)); } pMem->z = pMem->zMalloc; - if( pMem->z==0 ){ - pMem->flags = MEM_Null; - }else{ - pMem->flags &= ~(MEM_Ephem|MEM_Static); - } + pMem->flags &= ~(MEM_Ephem|MEM_Static); pMem->xDel = 0; - return (pMem->z ? SQLITE_OK : SQLITE_NOMEM); + return SQLITE_OK; } /* @@ -1221,7 +1219,7 @@ static void recordFunc( }else{ aRet[0] = nSerial+1; sqlite3PutVarint(&aRet[1], iSerial); - sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], file_format); + sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial); sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT); sqlite3DbFree(db, aRet); } diff --git a/src/vdbetrace.c b/src/vdbetrace.c index 0a767261f0..a7ff0a685d 100644 --- a/src/vdbetrace.c +++ b/src/vdbetrace.c @@ -92,6 +92,7 @@ char *sqlite3VdbeExpandSql( const char *zStart = zRawSql; while( *(zRawSql++)!='\n' && *zRawSql ); sqlite3StrAccumAppend(&out, "-- ", 3); + assert( (zRawSql - zStart) > 0 ); sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart)); } }else{ diff --git a/test/shell5.test b/test/shell5.test index cd3d471031..ce05a303ca 100644 --- a/test/shell5.test +++ b/test/shell5.test @@ -268,4 +268,23 @@ do_test shell5-1.9 { } {1 {} 11 | 2 x 22 | 3 {"} 33 | 4 hello 44 | 5 55 {} | 6 66 x | 7 77 {"} | 8 88 hello | {} 9 99 | x 10 110 | {"} 11 121 | hello 12 132 |} db close +# Import columns containing quoted strings +do_test shell5-1.10 { + set out [open shell5.csv w] + fconfigure $out -translation lf + puts $out {column1,column2,column3,column4} + puts $out "field1,field2,\"x3 \"\"\r\ndata\"\" 3\",field4" + puts $out "x1,x2,\"x3 \"\"\ndata\"\" 3\",x4" + close $out + forcedelete test.db + catchcmd test.db {.mode csv + CREATE TABLE t1(a,b,c,d); +.import shell5.csv t1 + } + sqlite3 db test.db + db eval {SELECT hex(c) FROM t1 ORDER BY rowid} +} {636F6C756D6E33 783320220D0A64617461222033 783320220A64617461222033} + +db close + finish_test diff --git a/tool/vdbe-compress.tcl b/tool/vdbe-compress.tcl index 95cc1ebf5a..a349830bcf 100644 --- a/tool/vdbe-compress.tcl +++ b/tool/vdbe-compress.tcl @@ -13,7 +13,7 @@ # Script usage: # # mv vdbe.c vdbe.c.template -# tclsh vdbe-compress.tcl vdbe.c +# tclsh vdbe-compress.tcl $CFLAGS vdbe.c # # Modifications made: # @@ -42,6 +42,16 @@ set unionDef {} ;# C code of the union set afterUnion {} ;# C code after the union set sCtr 0 ;# Context counter +# If the SQLITE_SMALL_STACK compile-time option is missing, then +# this transformation becomes a no-op. +# +if {![regexp {SQLITE_SMALL_STACK} $argv]} { + while {![eof stdin]} { + puts [gets stdin] + } + exit +} + # Read program text up to the spot where the union should be # inserted. #