diff --git a/ext/fts3/fts3_test.c b/ext/fts3/fts3_test.c index dec977b916..2596e6dec7 100644 --- a/ext/fts3/fts3_test.c +++ b/ext/fts3/fts3_test.c @@ -458,7 +458,7 @@ static int testTokenizerNext( if( pCsr->iLangid & 0x00000001 ){ for(i=0; iaBuffer[i] = pToken[i]; }else{ - for(i=0; iaBuffer[i] = testTolower(pToken[i]); + for(i=0; iaBuffer[i] = (char)testTolower(pToken[i]); } pCsr->iToken++; pCsr->iInput = (int)(p - pCsr->aInput); diff --git a/ext/fts3/tool/fts3view.c b/ext/fts3/tool/fts3view.c index a8d7981af0..37f9b7396d 100644 --- a/ext/fts3/tool/fts3view.c +++ b/ext/fts3/tool/fts3view.c @@ -398,8 +398,8 @@ static void showSegmentStats(sqlite3 *db, const char *zTab){ if( sqlite3_step(pStmt)==SQLITE_ROW && (nLeaf = sqlite3_column_int(pStmt, 0))>0 ){ - nIdx = sqlite3_column_int(pStmt, 5); sqlite3_int64 sz; + nIdx = sqlite3_column_int(pStmt, 5); printf("For level %d:\n", i); printf(" Number of indexes...................... %9d\n", nIdx); printf(" Number of leaf segments................ %9d\n", nLeaf); diff --git a/ext/fts5/fts5_hash.c b/ext/fts5/fts5_hash.c index ada8bb16cb..afa2a30739 100644 --- a/ext/fts5/fts5_hash.c +++ b/ext/fts5/fts5_hash.c @@ -345,11 +345,11 @@ int sqlite3Fts5HashWrite( if( pHash->eDetail==FTS5_DETAIL_FULL ){ pPtr[p->nData++] = 0x01; p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol); - p->iCol = iCol; + p->iCol = (i16)iCol; p->iPos = 0; }else{ bNew = 1; - p->iCol = iPos = iCol; + p->iCol = (i16)(iPos = iCol); } } diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index 1200f5707b..1d5ebe1428 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -3244,7 +3244,7 @@ static void fts5IterSetOutputs_Col100(Fts5Iter *pIter, Fts5SegIter *pSeg){ if( aiCol==aiColEnd ) goto setoutputs_col_out; } if( *aiCol==iPrev ){ - *aOut++ = (iPrev - iPrevOut) + 2; + *aOut++ = (u8)((iPrev - iPrevOut) + 2); iPrevOut = iPrev; } } diff --git a/ext/misc/amatch.c b/ext/misc/amatch.c index 852491988a..efe76566ee 100644 --- a/ext/misc/amatch.c +++ b/ext/misc/amatch.c @@ -625,10 +625,10 @@ static int amatchLoadOneRule( }else{ memset(pRule, 0, sizeof(*pRule)); pRule->zFrom = &pRule->zTo[nTo+1]; - pRule->nFrom = nFrom; + pRule->nFrom = (amatch_len)nFrom; memcpy(pRule->zFrom, zFrom, nFrom+1); memcpy(pRule->zTo, zTo, nTo+1); - pRule->nTo = nTo; + pRule->nTo = (amatch_len)nTo; pRule->rCost = rCost; pRule->iLang = (int)iLang; } @@ -1081,7 +1081,7 @@ static void amatchAddWord( pWord->rCost = rCost; pWord->iSeq = pCur->nWord++; amatchWriteCost(pWord); - pWord->nMatch = nMatch; + pWord->nMatch = (short)nMatch; pWord->pNext = pCur->pAllWords; pCur->pAllWords = pWord; pWord->sCost.zKey = pWord->zCost; @@ -1162,7 +1162,7 @@ static int amatchNext(sqlite3_vtab_cursor *cur){ #endif nWord = (int)strlen(pWord->zWord+2); if( nWord+20>nBuf ){ - nBuf = nWord+100; + nBuf = (char)(nWord+100); zBuf = sqlite3_realloc(zBuf, nBuf); if( zBuf==0 ) return SQLITE_NOMEM; } diff --git a/ext/misc/fuzzer.c b/ext/misc/fuzzer.c index 3ed4b0a977..77db56d47a 100644 --- a/ext/misc/fuzzer.c +++ b/ext/misc/fuzzer.c @@ -344,10 +344,10 @@ static int fuzzerLoadOneRule( memset(pRule, 0, sizeof(*pRule)); pRule->zFrom = pRule->zTo; pRule->zFrom += nTo + 1; - pRule->nFrom = nFrom; + pRule->nFrom = (fuzzer_len)nFrom; memcpy(pRule->zFrom, zFrom, nFrom+1); memcpy(pRule->zTo, zTo, nTo+1); - pRule->nTo = nTo; + pRule->nTo = (fuzzer_len)nTo; pRule->rCost = nCost; pRule->iRuleset = (int)iRuleset; } diff --git a/ext/misc/regexp.c b/ext/misc/regexp.c index 7244d52998..b4a8ab5c04 100644 --- a/ext/misc/regexp.c +++ b/ext/misc/regexp.c @@ -136,7 +136,7 @@ struct ReCompiled { static void re_add_state(ReStateSet *pSet, int newState){ unsigned i; for(i=0; inState; i++) if( pSet->aState[i]==newState ) return; - pSet->aState[pSet->nState++] = newState; + pSet->aState[pSet->nState++] = (ReStateNumber)newState; } /* Extract the next unicode character from *pzIn and return it. Advance @@ -358,7 +358,7 @@ static int re_insert(ReCompiled *p, int iBefore, int op, int arg){ p->aArg[i] = p->aArg[i-1]; } p->nState++; - p->aOp[iBefore] = op; + p->aOp[iBefore] = (char)op; p->aArg[iBefore] = arg; return iBefore; } @@ -677,12 +677,12 @@ const char *re_compile(ReCompiled **ppRe, const char *zIn, int noCase){ for(j=0, i=1; jzInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){ unsigned x = pRe->aArg[i]; if( x<=127 ){ - pRe->zInit[j++] = x; + pRe->zInit[j++] = (unsigned char)x; }else if( x<=0xfff ){ - pRe->zInit[j++] = 0xc0 | (x>>6); + pRe->zInit[j++] = (unsigned char)(0xc0 | (x>>6)); pRe->zInit[j++] = 0x80 | (x&0x3f); }else if( x<=0xffff ){ - pRe->zInit[j++] = 0xd0 | (x>>12); + pRe->zInit[j++] = (unsigned char)(0xd0 | (x>>12)); pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f); pRe->zInit[j++] = 0x80 | (x&0x3f); }else{ diff --git a/ext/misc/spellfix.c b/ext/misc/spellfix.c index b5859ea2c8..cbcf8b7c5d 100644 --- a/ext/misc/spellfix.c +++ b/ext/misc/spellfix.c @@ -390,7 +390,7 @@ static int editdist1(const char *zA, const char *zB, int *pnMatch){ /* Special processing if either string is empty */ if( nA==0 ){ - cBprev = dc; + cBprev = (char)dc; for(xB=res=0; (cB = zB[xB])!=0; xB++){ res += insertOrDeleteCost(cBprev, cB, zB[xB+1])/FINAL_INS_COST_DIV; cBprev = cB; @@ -398,7 +398,7 @@ static int editdist1(const char *zA, const char *zB, int *pnMatch){ return res; } if( nB==0 ){ - cAprev = dc; + cAprev = (char)dc; for(xA=res=0; (cA = zA[xA])!=0; xA++){ res += insertOrDeleteCost(cAprev, cA, zA[xA+1]); cAprev = cA; @@ -420,8 +420,8 @@ static int editdist1(const char *zA, const char *zB, int *pnMatch){ /* Compute the Wagner edit distance */ m[0] = 0; - cx[0] = dc; - cBprev = dc; + cx[0] = (char)dc; + cBprev = (char)dc; for(xB=1; xB<=nB; xB++){ cBnext = zB[xB]; cB = zB[xB-1]; @@ -429,7 +429,7 @@ static int editdist1(const char *zA, const char *zB, int *pnMatch){ m[xB] = m[xB-1] + insertOrDeleteCost(cBprev, cB, cBnext); cBprev = cB; } - cAprev = dc; + cAprev = (char)dc; for(xA=1; xA<=nA; xA++){ int lastA = (xA==nA); cA = zA[xA-1]; @@ -476,7 +476,7 @@ static int editdist1(const char *zA, const char *zB, int *pnMatch){ d = m[xB]; dc = cx[xB]; m[xB] = totalCost; - cx[xB] = ncx; + cx[xB] = (char)ncx; cBprev = cB; } cAprev = cA; @@ -711,9 +711,9 @@ static int editDist3ConfigLoad( if( nExtra<0 ) nExtra = 0; pCost = sqlite3_malloc64( sizeof(*pCost) + nExtra ); if( pCost==0 ){ rc = SQLITE_NOMEM; break; } - pCost->nFrom = nFrom; - pCost->nTo = nTo; - pCost->iCost = iCost; + pCost->nFrom = (u8)nFrom; + pCost->nTo = (u8)nTo; + pCost->iCost = (u16)iCost; memcpy(pCost->a, zFrom, nFrom); memcpy(pCost->a + nFrom, zTo, nTo); pCost->pNext = pLang->pCost; @@ -1616,7 +1616,7 @@ static unsigned char *transliterate(const unsigned char *zIn, int nIn){ zIn += sz; nIn -= sz; if( c<=127 ){ - zOut[nOut++] = c; + zOut[nOut++] = (unsigned char)c; }else{ int xTop, xBtm, x; xTop = sizeof(translit)/sizeof(translit[0]) - 1; diff --git a/ext/rbu/sqlite3rbu.c b/ext/rbu/sqlite3rbu.c index 93b756aa6a..f553ebdac5 100644 --- a/ext/rbu/sqlite3rbu.c +++ b/ext/rbu/sqlite3rbu.c @@ -3356,7 +3356,7 @@ sqlite3 *sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){ */ static void rbuEditErrmsg(sqlite3rbu *p){ if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){ - int i; + unsigned int i; size_t nErrmsg = strlen(p->zErrmsg); for(i=0; i<(nErrmsg-8); i++){ if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){ diff --git a/ext/session/sqlite3session.c b/ext/session/sqlite3session.c index 437549dd70..b058d357e2 100644 --- a/ext/session/sqlite3session.c +++ b/ext/session/sqlite3session.c @@ -935,9 +935,9 @@ static int sessionTableInfo( int nDbCol = 0; int nThis; int i; - u8 *pAlloc; + u8 *pAlloc = 0; char **azCol = 0; - u8 *abPK; + u8 *abPK = 0; assert( pazCol && pabPK ); @@ -1593,9 +1593,9 @@ static void sessionDeleteTable(SessionTable *pList){ pNext = pTab->pNext; for(i=0; inChange; i++){ SessionChange *p; - SessionChange *pNext; - for(p=pTab->apChange[i]; p; p=pNext){ - pNext = p->pNext; + SessionChange *pNextChange; + for(p=pTab->apChange[i]; p; p=pNextChange){ + pNextChange = p->pNext; sqlite3_free(p); } } @@ -2882,7 +2882,6 @@ static int sessionChangesetNext( ** modified fields are present in the new.* record. The old.* record ** is currently completely empty. This block shifts the PK fields from ** new.* to old.*, to accommodate the code that reads these arrays. */ - int i; for(i=0; inCol; i++){ assert( p->apValue[i]==0 ); assert( p->abPK[i]==0 || p->apValue[i+p->nCol] ); @@ -3655,7 +3654,7 @@ static int sessionConflictHandler( void *pCtx, /* First argument for conflict handler */ int *pbReplace /* OUT: Set to true if PK row is found */ ){ - int res; /* Value returned by conflict handler */ + int res = 0; /* Value returned by conflict handler */ int rc; int nCol; int op; diff --git a/ext/session/test_session.c b/ext/session/test_session.c index 15f7b6f575..1aa63b74ed 100644 --- a/ext/session/test_session.c +++ b/ext/session/test_session.c @@ -314,7 +314,8 @@ static void test_append_value(Tcl_Obj *pList, sqlite3_value *pVal){ pObj = Tcl_NewStringObj(z, n); break; } - case SQLITE_BLOB: + default: + assert( sqlite3_value_type(pVal)==SQLITE_BLOB ); Tcl_ListObjAppendElement(0, pList, Tcl_NewStringObj("b", 1)); pObj = Tcl_NewByteArrayObj( sqlite3_value_blob(pVal), @@ -871,7 +872,6 @@ static int test_sqlite3session_foreach( pOld = Tcl_NewObj(); if( op!=SQLITE_INSERT ){ - int i; for(i=0; ivalidTZ = 0; } +#ifndef SQLITE_OMIT_LOCALTIME /* ** On recent Windows platforms, the localtime_s() function is available ** as part of the "Secure CRT". It is essentially equivalent to @@ -436,7 +446,6 @@ static void clearYMD_HMS_TZ(DateTime *p){ #define HAVE_LOCALTIME_S 1 #endif -#ifndef SQLITE_OMIT_LOCALTIME /* ** The following routine implements the rough equivalent of localtime_r() ** using whatever operating-system specific localtime facility that diff --git a/src/os_win.c b/src/os_win.c index 4aca70b6c9..929ad346cc 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -2118,16 +2118,17 @@ static void winLogIoerr(int nRetry, int lineno){ } } -#if SQLITE_OS_WINCE -/************************************************************************* -** This section contains code for WinCE only. -*/ -#if !defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API /* -** The MSVC CRT on Windows CE may not have a localtime() function. So -** create a substitute. +** This #if does not rely on the SQLITE_OS_WINCE define because the +** corresponding section in "date.c" cannot use it. */ -#include +#if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \ + (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API) +/* +** The MSVC CRT on Windows CE may not have a localtime() function. +** So define a substitute. +*/ +# include struct tm *__cdecl localtime(const time_t *t) { static struct tm y; @@ -2151,6 +2152,10 @@ struct tm *__cdecl localtime(const time_t *t) } #endif +#if SQLITE_OS_WINCE +/************************************************************************* +** This section contains code for WinCE only. +*/ #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)] /* diff --git a/src/shell.c b/src/shell.c index 001dd6d465..33010e5ff1 100644 --- a/src/shell.c +++ b/src/shell.c @@ -669,6 +669,7 @@ struct ShellState { #define MODE_Csv 7 /* Quote strings, numbers are plain */ #define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */ #define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */ +#define MODE_Pretty 10 /* Pretty-print schemas */ static const char *modeDescr[] = { "line", @@ -681,6 +682,7 @@ static const char *modeDescr[] = { "csv", "explain", "ascii", + "prettyprint", }; /* @@ -1054,7 +1056,71 @@ static int shell_callback( } break; } - case MODE_Semi: + case MODE_Semi: { /* .schema and .fullschema output */ + utf8_printf(p->out, "%s;\n", azArg[0]); + break; + } + case MODE_Pretty: { /* .schema and .fullschema with --indent */ + char *z; + int i,j; + int nParen = 0; + char cEnd = 0; + char c; + int nLine = 0; + assert( nArg==1 ); + if( azArg[0]==0 ) break; + if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0 + || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0 + ){ + utf8_printf(p->out, "%s;\n", azArg[0]); + break; + } + z = sqlite3_mprintf("%s", azArg[0]); + j = 0; + for(i=0; IsSpace(z[i]); i++){} + for(; (c = z[i])!=0; i++){ + if( IsSpace(c) ){ + if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue; + }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){ + j--; + } + z[j++] = c; + } + while( j>0 && IsSpace(z[j-1]) ){ j--; } + z[j] = 0; + if( strlen30(z)>=79 ){ + for(i=j=0; z[i]; i++){ + char c = z[i]; + if( c==cEnd ){ + cEnd = 0; + }else if( c=='"' || c=='\'' || c=='`' ){ + cEnd = c; + }else if( c=='[' ){ + cEnd = ']'; + }else if( c=='(' ){ + nParen++; + }else if( c==')' ){ + nParen--; + if( nLine>0 && nParen==0 && j>0 ){ + utf8_printf(p->out, "%.*s\n", j, z); + j = 0; + } + } + z[j++] = c; + if( nParen==1 && (c=='(' || c==',' || c=='\n') ){ + if( c=='\n' ) j--; + utf8_printf(p->out, "%.*s\n ", j, z); + j = 0; + nLine++; + while( IsSpace(z[i+1]) ){ i++; } + } + } + z[j] = 0; + } + utf8_printf(p->out, "%s;\n", z); + sqlite3_free(z); + break; + } case MODE_List: { if( p->cnt++==0 && p->showHeader ){ for(i=0; iout, "%s", z); if( iout, "%s", p->colSeparator); - }else if( p->cMode==MODE_Semi ){ - utf8_printf(p->out, ";%s", p->rowSeparator); }else{ utf8_printf(p->out, "%s", p->rowSeparator); } @@ -2024,7 +2088,7 @@ static char zHelp[] = ".eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN\n" ".exit Exit this program\n" ".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n" - ".fullschema Show schema and the content of sqlite_stat tables\n" + ".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n" ".headers on|off Turn display of headers on or off\n" ".help Show this message\n" ".import FILE TABLE Import data from FILE into TABLE\n" @@ -2060,9 +2124,8 @@ static char zHelp[] = ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n" ".save FILE Write in-memory database into FILE\n" ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n" - ".schema ?TABLE? Show the CREATE statements\n" - " If TABLE specified, only show tables matching\n" - " LIKE pattern TABLE.\n" + ".schema ?PATTERN? Show the CREATE statements matching PATTERN\n" + " Add --indent for pretty-printing\n" ".separator COL ?ROW? Change the column separator and optionally the row\n" " separator for both the output mode and .import\n" #if defined(SQLITE_ENABLE_SESSION) @@ -2933,6 +2996,17 @@ static int shellNomemError(void){ return 1; } +/* +** Compare the string as a command-line option with either one or two +** initial "-" characters. +*/ +static int optionMatch(const char *zStr, const char *zOpt){ + if( zStr[0]!='-' ) return 0; + zStr++; + if( zStr[0]=='-' ) zStr++; + return strcmp(zStr, zOpt)==0; +} + /* ** If an input line begins with "." then invoke this routine to ** process that line. @@ -3219,15 +3293,19 @@ static int do_meta_command(char *zLine, ShellState *p){ ShellState data; char *zErrMsg = 0; int doStats = 0; + memcpy(&data, p, sizeof(data)); + data.showHeader = 0; + data.cMode = data.mode = MODE_Semi; + if( nArg==2 && optionMatch(azArg[1], "indent") ){ + data.cMode = data.mode = MODE_Pretty; + nArg = 1; + } if( nArg!=1 ){ - raw_printf(stderr, "Usage: .fullschema\n"); + raw_printf(stderr, "Usage: .fullschema ?--indent?\n"); rc = 1; goto meta_command_exit; } open_db(p, 0); - memcpy(&data, p, sizeof(data)); - data.showHeader = 0; - data.cMode = data.mode = MODE_Semi; rc = sqlite3_exec(p->db, "SELECT sql FROM" " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x" @@ -3862,7 +3940,12 @@ static int do_meta_command(char *zLine, ShellState *p){ memcpy(&data, p, sizeof(data)); data.showHeader = 0; data.cMode = data.mode = MODE_Semi; - if( nArg==2 ){ + if( nArg>=2 && optionMatch(azArg[1], "indent") ){ + data.cMode = data.mode = MODE_Pretty; + nArg--; + if( nArg==2 ) azArg[1] = azArg[2]; + } + if( nArg==2 && azArg[1][0]!='-' ){ int i; for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]); if( strcmp(azArg[1],"sqlite_master")==0 ){ @@ -3917,7 +4000,7 @@ static int do_meta_command(char *zLine, ShellState *p){ callback, &data, &zErrMsg ); }else{ - raw_printf(stderr, "Usage: .schema ?LIKE-PATTERN?\n"); + raw_printf(stderr, "Usage: .schema ?--indent? ?LIKE-PATTERN?\n"); rc = 1; goto meta_command_exit; } diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 96b5691f16..d6a36118c4 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -3035,7 +3035,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ /* set ppHook to point at pUpdateHook or pRollbackHook, depending on ** whether [$db update_hook] or [$db rollback_hook] was invoked. */ - Tcl_Obj **ppHook; + Tcl_Obj **ppHook = 0; if( choice==DB_WAL_HOOK ) ppHook = &pDb->pWalHook; if( choice==DB_UPDATE_HOOK ) ppHook = &pDb->pUpdateHook; if( choice==DB_ROLLBACK_HOOK ) ppHook = &pDb->pRollbackHook; diff --git a/src/test_multiplex.c b/src/test_multiplex.c index 07dcbbc1aa..ba4e61b090 100644 --- a/src/test_multiplex.c +++ b/src/test_multiplex.c @@ -539,7 +539,7 @@ static int multiplexOpen( memset(pGroup, 0, sz); pMultiplexOpen->pGroup = pGroup; pGroup->bEnabled = (unsigned char)-1; - pGroup->bTruncate = sqlite3_uri_boolean(zUri, "truncate", + pGroup->bTruncate = (unsigned char)sqlite3_uri_boolean(zUri, "truncate", (flags & SQLITE_OPEN_MAIN_DB)==0); pGroup->szChunk = (int)sqlite3_uri_int64(zUri, "chunksize", SQLITE_MULTIPLEX_CHUNK_SIZE); @@ -978,7 +978,7 @@ static int multiplexFileControl(sqlite3_file *pConn, int op, void *pArg){ case MULTIPLEX_CTRL_ENABLE: if( pArg ) { int bEnabled = *(int *)pArg; - pGroup->bEnabled = bEnabled; + pGroup->bEnabled = (unsigned char)bEnabled; rc = SQLITE_OK; } break; diff --git a/src/test_onefile.c b/src/test_onefile.c index 122be700e6..46c8bc9c83 100644 --- a/src/test_onefile.c +++ b/src/test_onefile.c @@ -508,7 +508,7 @@ static int fsSync(sqlite3_file *pFile, int flags){ if( p->eType==DATABASE_FILE ){ unsigned char zSize[4]; zSize[0] = (pReal->nDatabase&0xFF000000)>>24; - zSize[1] = (pReal->nDatabase&0x00FF0000)>>16; + zSize[1] = (unsigned char)((pReal->nDatabase&0x00FF0000)>>16); zSize[2] = (pReal->nDatabase&0x0000FF00)>>8; zSize[3] = (pReal->nDatabase&0x000000FF); rc = pRealFile->pMethods->xWrite(pRealFile, zSize, 4, 0); diff --git a/src/test_osinst.c b/src/test_osinst.c index 4ae23a87c6..e51ce77ef8 100644 --- a/src/test_osinst.c +++ b/src/test_osinst.c @@ -644,9 +644,9 @@ static void vfslog_flush(VfslogVfs *p){ static void put32bits(unsigned char *p, unsigned int v){ p[0] = v>>24; - p[1] = v>>16; - p[2] = v>>8; - p[3] = v; + p[1] = (unsigned char)(v>>16); + p[2] = (unsigned char)(v>>8); + p[3] = (unsigned char)v; } static void vfslog_call( diff --git a/test/shell1.test b/test/shell1.test index 9dd0f42093..760c85fadc 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -568,7 +568,7 @@ do_test shell1-3.21.2 { do_test shell1-3.21.3 { # too many arguments catchcmd "test.db" ".schema FOO BAD" -} {1 {Usage: .schema ?LIKE-PATTERN?}} +} {1 {Usage: .schema ?--indent? ?LIKE-PATTERN?}} do_test shell1-3.21.4 { catchcmd "test.db" { diff --git a/test/speedtest1.c b/test/speedtest1.c index 8ed0424f88..2d337d4705 100644 --- a/test/speedtest1.c +++ b/test/speedtest1.c @@ -30,6 +30,7 @@ static const char zHelp[] = " --shrink-memory Invoke sqlite3_db_release_memory() frequently.\n" " --size N Relative test size. Default=100\n" " --stats Show statistics at the end\n" + " --temp N N from 0 to 9. 0: no temp table. 9: all temp tables\n" " --testset T Run test-set T\n" " --trace Turn on SQL tracing\n" " --threads N Use up to N threads for sorting\n" @@ -69,6 +70,7 @@ static struct Global { int bExplain; /* Print SQL with EXPLAIN prefix */ int bVerify; /* Try to verify that results are correct */ int bMemShrink; /* Call sqlite3_db_release_memory() often */ + int eTemp; /* 0: no TEMP. 9: always TEMP. */ int szTest; /* Scale factor for test iterations */ const char *zWR; /* Might be WITHOUT ROWID */ const char *zNN; /* Might be NOT NULL */ @@ -78,6 +80,12 @@ static struct Global { char zResult[3000]; /* Text of the current result */ } g; +/* Return " TEMP" or "", as appropriate for creating a table. +*/ +static const char *isTemp(int N){ + return g.eTemp>=N ? " TEMP" : ""; +} + /* Print an error message and exit */ static void fatal_error(const char *zMsg, ...){ @@ -459,8 +467,8 @@ void testset_main(void){ maxb = roundup_allones(sz); speedtest1_begin_test(100, "%d INSERTs into table with no index", n); speedtest1_exec("BEGIN"); - speedtest1_exec("CREATE TABLE t1(a INTEGER %s, b INTEGER %s, c TEXT %s);", - g.zNN, g.zNN, g.zNN); + speedtest1_exec("CREATE%s TABLE t1(a INTEGER %s, b INTEGER %s, c TEXT %s);", + isTemp(9), g.zNN, g.zNN, g.zNN); speedtest1_prepare("INSERT INTO t1 VALUES(?1,?2,?3); -- %d times", n); for(i=1; i<=n; i++){ x1 = swizzle(i,maxb); @@ -477,8 +485,9 @@ void testset_main(void){ n = sz; speedtest1_begin_test(110, "%d ordered INSERTS with one index/PK", n); speedtest1_exec("BEGIN"); - speedtest1_exec("CREATE TABLE t2(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s", - g.zNN, g.zPK, g.zNN, g.zNN, g.zWR); + speedtest1_exec( + "CREATE%s TABLE t2(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s", + isTemp(5), g.zNN, g.zPK, g.zNN, g.zNN, g.zWR); speedtest1_prepare("INSERT INTO t2 VALUES(?1,?2,?3); -- %d times", n); for(i=1; i<=n; i++){ x1 = swizzle(i,maxb); @@ -495,8 +504,9 @@ void testset_main(void){ n = sz; speedtest1_begin_test(120, "%d unordered INSERTS with one index/PK", n); speedtest1_exec("BEGIN"); - speedtest1_exec("CREATE TABLE t3(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s", - g.zNN, g.zPK, g.zNN, g.zNN, g.zWR); + speedtest1_exec( + "CREATE%s TABLE t3(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s", + isTemp(3), g.zNN, g.zPK, g.zNN, g.zNN, g.zWR); speedtest1_prepare("INSERT INTO t3 VALUES(?1,?2,?3); -- %d times", n); for(i=1; i<=n; i++){ x1 = swizzle(i,maxb); @@ -654,12 +664,12 @@ void testset_main(void){ speedtest1_begin_test(180, "%d INSERTS with three indexes", n); speedtest1_exec("BEGIN"); speedtest1_exec( - "CREATE TABLE t4(\n" + "CREATE%s TABLE t4(\n" " a INTEGER %s %s,\n" " b INTEGER %s,\n" " c TEXT %s\n" ") %s", - g.zNN, g.zPK, g.zNN, g.zNN, g.zWR); + isTemp(1), g.zNN, g.zPK, g.zNN, g.zNN, g.zWR); speedtest1_exec("CREATE INDEX t4b ON t4(b)"); speedtest1_exec("CREATE INDEX t4c ON t4(c)"); speedtest1_exec("INSERT INTO t4 SELECT * FROM t1"); @@ -1047,7 +1057,7 @@ void testset_rtree(int p1, int p2){ speedtest1_end_test(); speedtest1_begin_test(101, "Copy from rtree to a regular table"); - speedtest1_exec("CREATE TABLE t1(id INTEGER PRIMARY KEY,x0,x1,y0,y1,z0,z1)"); + speedtest1_exec(" TABLE t1(id INTEGER PRIMARY KEY,x0,x1,y0,y1,z0,z1)"); speedtest1_exec("INSERT INTO t1 SELECT * FROM rt1"); speedtest1_end_test(); @@ -1321,6 +1331,13 @@ int main(int argc, char **argv){ g.szTest = integerValue(argv[++i]); }else if( strcmp(z,"stats")==0 ){ showStats = 1; + }else if( strcmp(z,"temp")==0 ){ + if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); + i++; + if( argv[i][0]<'0' || argv[i][0]>'9' || argv[i][1]!=0 ){ + fatal_error("argument to --temp should be integer between 0 and 9"); + } + g.eTemp = argv[i][0] - '0'; }else if( strcmp(z,"testset")==0 ){ if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]); zTSet = argv[++i]; @@ -1352,11 +1369,7 @@ int main(int argc, char **argv){ argv[i], argv[0]); } } -#if 0 - if( zDbName==0 ){ - fatal_error(zHelp, argv[0]); - } -#endif + if( zDbName!=0 ) unlink(zDbName); #if SQLITE_VERSION_NUMBER>=3006001 if( nHeap>0 ){ pHeap = malloc( nHeap ); diff --git a/tool/logest.c b/tool/logest.c index 347fa68a4f..e936e02cbe 100644 --- a/tool/logest.c +++ b/tool/logest.c @@ -147,7 +147,7 @@ int main(int argc, char **argv){ }else if( strcmp(z,"inv")==0 ){ if( n>0 ) a[n-1] = -a[n-1]; }else if( z[0]=='^' ){ - a[n++] = atoi(z+1); + a[n++] = (LogEst)atoi(z+1); }else if( isInteger(z) ){ a[n++] = logEstFromInteger(atoi(z)); }else if( isFloat(z) && z[0]!='-' ){ diff --git a/tool/showdb.c b/tool/showdb.c index 06cd36cd2c..d51a2fd83d 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -151,7 +151,7 @@ static unsigned char *fileRead(sqlite3_int64 ofst, int nByte){ exit(1); } }else{ - lseek(g.dbfd, ofst, SEEK_SET); + lseek(g.dbfd, (long)ofst, SEEK_SET); got = read(g.dbfd, aData, nByte); if( got>0 && got