Index: src/auth.c ================================================================== --- src/auth.c +++ src/auth.c @@ -12,11 +12,11 @@ ** This file contains code used to implement the sqlite3_set_authorizer() ** API. This facility is an optional feature of the library. Embedded ** systems that do not need this facility may omit it by recompiling ** the library with -DSQLITE_OMIT_AUTHORIZATION=1 ** -** $Id: auth.c,v 1.24 2006/01/13 13:55:45 drh Exp $ +** $Id: auth.c,v 1.23 2006/01/05 11:34:34 danielk1977 Exp $ */ #include "sqliteInt.h" /* ** All of the code in this file may be omitted by defining a single @@ -116,15 +116,10 @@ if( db->xAuth==0 ) return; if( pExpr->op==TK_AS ) return; assert( pExpr->op==TK_COLUMN ); iDb = sqlite3SchemaToIndex(pParse->db, pExpr->pSchema); - if( iDb<0 ){ - /* An attempt to read a column out of a subquery or other - ** temporary table. */ - return; - } for(iSrc=0; pTabList && iSrcnSrc; iSrc++){ if( pExpr->iTable==pTabList->a[iSrc].iCursor ) break; } if( iSrc>=0 && pTabList && iSrcnSrc ){ pTab = pTabList->a[iSrc].pTab; @@ -145,11 +140,11 @@ assert( pTab->iPKeynCol ); zCol = pTab->aCol[pTab->iPKey].zName; }else{ zCol = "ROWID"; } - assert( iDb>=0 && iDbnDb ); + assert( iDbnDb ); zDBase = db->aDb[iDb].zName; rc = db->xAuth(db->pAuthArg, SQLITE_READ, pTab->zName, zCol, zDBase, pParse->zAuthContext); if( rc==SQLITE_IGNORE ){ pExpr->op = TK_NULL; Index: src/btree.c ================================================================== --- src/btree.c +++ src/btree.c @@ -7,11 +7,11 @@ ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.297 2006/01/13 11:22:07 danielk1977 Exp $ +** $Id: btree.c,v 1.293 2006/01/12 15:01:16 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to ** ** Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3: @@ -409,11 +409,11 @@ ** ** CURSOR_REQUIRESEEK: ** The table that this cursor was opened on still exists, but has been ** modified since the cursor was last used. The cursor position is saved ** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in -** this state, restoreOrClearCursorPosition() can be called to attempt to seek +** this state, restoreCursorPosition() can be called to attempt to seek ** the cursor to the saved position. */ #define CURSOR_INVALID 0 #define CURSOR_VALID 1 #define CURSOR_REQUIRESEEK 2 @@ -499,11 +499,11 @@ ** So define the lock related functions as no-ops. */ #define queryTableLock(a,b,c) SQLITE_OK #define lockTable(a,b,c) SQLITE_OK #define unlockAllTables(a) - #define restoreOrClearCursorPosition(a,b) SQLITE_OK + #define restoreCursorPosition(a,b) SQLITE_OK #define saveAllCursors(a,b,c) SQLITE_OK #else /* @@ -572,37 +572,35 @@ /* ** Restore the cursor to the position it was in (or as close to as possible) ** when saveCursorPosition() was called. Note that this call deletes the ** saved position info stored by saveCursorPosition(), so there can be -** at most one effective restoreOrClearCursorPosition() call after each +** at most one effective restoreCursorPosition() call after each ** saveCursorPosition(). ** ** If the second argument argument - doSeek - is false, then instead of ** returning the cursor to it's saved position, any saved position is deleted ** and the cursor state set to CURSOR_INVALID. */ -static int restoreOrClearCursorPositionX(BtCursor *pCur, int doSeek){ +static int restoreCursorPosition(BtCursor *pCur, int doSeek){ int rc = SQLITE_OK; - assert( sqlite3ThreadDataReadOnly()->useSharedData ); - assert( pCur->eState==CURSOR_REQUIRESEEK ); - if( doSeek ){ - rc = sqlite3BtreeMoveto(pCur, pCur->pKey, pCur->nKey, &pCur->skip); - }else{ - pCur->eState = CURSOR_INVALID; - } - if( rc==SQLITE_OK ){ - sqliteFree(pCur->pKey); - pCur->pKey = 0; - assert( CURSOR_VALID==pCur->eState || CURSOR_INVALID==pCur->eState ); + if( pCur->eState==CURSOR_REQUIRESEEK ){ + assert( sqlite3ThreadDataReadOnly()->useSharedData ); + if( doSeek ){ + rc = sqlite3BtreeMoveto(pCur, pCur->pKey, pCur->nKey, &pCur->skip); + }else{ + pCur->eState = CURSOR_INVALID; + } + if( rc==SQLITE_OK ){ + sqliteFree(pCur->pKey); + pCur->pKey = 0; + assert( CURSOR_VALID==pCur->eState || CURSOR_INVALID==pCur->eState ); + } } return rc; } -#define restoreOrClearCursorPosition(p,x) \ - (p->eState==CURSOR_REQUIRESEEK?restoreOrClearCursorPositionX(p,x):SQLITE_OK) - /* ** Query to see if btree handle p may obtain a lock of type eLock ** (READ_LOCK or WRITE_LOCK) on the table with root-page iTab. Return ** SQLITE_OK if the lock may be obtained (by calling lockTable()), or ** SQLITE_LOCKED if not. @@ -2709,10 +2707,11 @@ if( pCur==0 ){ rc = SQLITE_NOMEM; goto create_cursor_exception; } pCur->pgnoRoot = (Pgno)iTable; + pCur->pPage = 0; /* For exit-handler, in case getAndInitPage() fails. */ if( iTable==1 && sqlite3pager_pagecount(pBt->pPager)==0 ){ rc = SQLITE_EMPTY; goto create_cursor_exception; } rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->pPage, 0); @@ -2726,14 +2725,17 @@ */ pCur->xCompare = xCmp ? xCmp : dfltCompare; pCur->pArg = pArg; pCur->pBtree = p; pCur->wrFlag = wrFlag; + pCur->idx = 0; + memset(&pCur->info, 0, sizeof(pCur->info)); pCur->pNext = pBt->pCursor; if( pCur->pNext ){ pCur->pNext->pPrev = pCur; } + pCur->pPrev = 0; pBt->pCursor = pCur; pCur->eState = CURSOR_INVALID; *ppCur = pCur; return SQLITE_OK; @@ -2764,11 +2766,11 @@ ** Close a cursor. The read lock on the database file is released ** when the last cursor is closed. */ int sqlite3BtreeCloseCursor(BtCursor *pCur){ BtShared *pBt = pCur->pBtree->pBt; - restoreOrClearCursorPosition(pCur, 0); + restoreCursorPosition(pCur, 0); if( pCur->pPrev ){ pCur->pPrev->pNext = pCur->pNext; }else{ pBt->pCursor = pCur->pNext; } @@ -2831,11 +2833,11 @@ ** ** For a table with the INTKEY flag set, this routine returns the key ** itself, not the number of bytes in the key. */ int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){ - int rc = restoreOrClearCursorPosition(pCur, 1); + int rc = restoreCursorPosition(pCur, 1); if( rc==SQLITE_OK ){ assert( pCur->eState==CURSOR_INVALID || pCur->eState==CURSOR_VALID ); if( pCur->eState==CURSOR_INVALID ){ *pSize = 0; }else{ @@ -2852,11 +2854,11 @@ ** Failure is not possible. If the cursor is not currently ** pointing to an entry (which can happen, for example, if ** the database is empty) then *pSize is set to 0. */ int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){ - int rc = restoreOrClearCursorPosition(pCur, 1); + int rc = restoreCursorPosition(pCur, 1); if( rc==SQLITE_OK ){ assert( pCur->eState==CURSOR_INVALID || pCur->eState==CURSOR_VALID ); if( pCur->eState==CURSOR_INVALID ){ /* Not pointing at a valid entry - set *pSize to 0. */ *pSize = 0; @@ -2897,11 +2899,12 @@ pBt = pCur->pBtree->pBt; pPage = pCur->pPage; pageIntegrity(pPage); assert( pCur->idx>=0 && pCur->idxnCell ); getCellInfo(pCur); - aPayload = pCur->info.pCell + pCur->info.nHeader; + aPayload = pCur->info.pCell; + aPayload += pCur->info.nHeader; if( pPage->intKey ){ nKey = 0; }else{ nKey = pCur->info.nKey; } @@ -2966,11 +2969,11 @@ ** Return SQLITE_OK on success or an error code if anything goes ** wrong. An error is returned if "offset+amt" is larger than ** the available payload. */ int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ - int rc = restoreOrClearCursorPosition(pCur, 1); + int rc = restoreCursorPosition(pCur, 1); if( rc==SQLITE_OK ){ assert( pCur->eState==CURSOR_VALID ); assert( pCur->pPage!=0 ); if( pCur->pPage->intKey ){ return SQLITE_CORRUPT_BKPT; @@ -2990,11 +2993,11 @@ ** Return SQLITE_OK on success or an error code if anything goes ** wrong. An error is returned if "offset+amt" is larger than ** the available payload. */ int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ - int rc = restoreOrClearCursorPosition(pCur, 1); + int rc = restoreCursorPosition(pCur, 1); if( rc==SQLITE_OK ){ assert( pCur->eState==CURSOR_VALID ); assert( pCur->pPage!=0 ); assert( pCur->idx>=0 && pCur->idxpPage->nCell ); rc = getPayload(pCur, offset, amt, pBuf, 1); @@ -3160,29 +3163,23 @@ /* ** Move the cursor to the root page */ static int moveToRoot(BtCursor *pCur){ MemPage *pRoot; - int rc = SQLITE_OK; + int rc; BtShared *pBt = pCur->pBtree->pBt; - restoreOrClearCursorPosition(pCur, 0); - assert( pCur->pPage ); - pRoot = pCur->pPage; - if( pRoot->pgno==pCur->pgnoRoot ){ - assert( pRoot->isInit ); - }else{ - if( - SQLITE_OK!=(rc = getAndInitPage(pBt, pCur->pgnoRoot, &pRoot, 0)) - ){ - pCur->eState = CURSOR_INVALID; - return rc; - } - releasePage(pCur->pPage); - pageIntegrity(pRoot); - pCur->pPage = pRoot; - } + if( + SQLITE_OK!=(rc = restoreCursorPosition(pCur, 0)) || + SQLITE_OK!=(rc = getAndInitPage(pBt, pCur->pgnoRoot, &pRoot, 0)) + ){ + pCur->eState = CURSOR_INVALID; + return rc; + } + releasePage(pCur->pPage); + pageIntegrity(pRoot); + pCur->pPage = pRoot; pCur->idx = 0; pCur->info.nSize = 0; if( pRoot->nCell==0 && !pRoot->leaf ){ Pgno subpage; assert( pRoot->pgno==1 ); @@ -3196,13 +3193,10 @@ } /* ** Move the cursor down to the left-most leaf entry beneath the ** entry to which it is currently pointing. -** -** The left-most leaf is the one with the smallest key - the first -** in ascending order. */ static int moveToLeftmost(BtCursor *pCur){ Pgno pgno; int rc; MemPage *pPage; @@ -3221,13 +3215,10 @@ ** Move the cursor down to the right-most leaf entry beneath the ** page to which it is currently pointing. Notice the difference ** between moveToLeftmost() and moveToRightmost(). moveToLeftmost() ** finds the left-most entry beneath the *entry* whereas moveToRightmost() ** finds the right-most entry beneath the *page*. -** -** The right-most entry is the one with the largest key - the last -** key in ascending order. */ static int moveToRightmost(BtCursor *pCur){ Pgno pgno; int rc; MemPage *pPage; @@ -3309,16 +3300,14 @@ ** *pRes>0 The cursor is left pointing at an entry that ** is larger than pKey. */ int sqlite3BtreeMoveto(BtCursor *pCur, const void *pKey, i64 nKey, int *pRes){ int rc; - int tryRightmost; rc = moveToRoot(pCur); if( rc ) return rc; assert( pCur->pPage ); assert( pCur->pPage->isInit ); - tryRightmost = pCur->pPage->intKey; if( pCur->eState==CURSOR_INVALID ){ *pRes = -1; assert( pCur->pPage->nCell==0 ); return SQLITE_OK; } @@ -3335,34 +3324,31 @@ pageIntegrity(pPage); while( lwr<=upr ){ void *pCellKey; i64 nCellKey; pCur->idx = (lwr+upr)/2; - pCur->info.nSize = 0; if( pPage->intKey ){ - u8 *pCell; - if( tryRightmost ){ - pCur->idx = upr; - } - pCell = findCell(pPage, pCur->idx) + pPage->childPtrSize; + u8 *pCell = findCell(pPage, pCur->idx); + pCell += pPage->childPtrSize; if( pPage->hasData ){ int dummy; pCell += getVarint32(pCell, &dummy); } getVarint(pCell, &nCellKey); + pCur->info.nSize = 0; if( nCellKeynKey ){ c = +1; - tryRightmost = 0; }else{ c = 0; } }else{ int available; - pCellKey = (void *)fetchPayload(pCur, &available, 0); + parseCell(pPage, pCur->idx, &pCur->info); nCellKey = pCur->info.nKey; + pCellKey = (void *)fetchPayload(pCur, &available, 0); if( available>=nCellKey ){ c = pCur->xCompare(pCur->pArg, nCellKey, pCellKey, nKey, pKey); }else{ pCellKey = sqliteMallocRaw( nCellKey ); if( pCellKey==0 ) return SQLITE_NOMEM; @@ -3436,11 +3422,11 @@ int sqlite3BtreeNext(BtCursor *pCur, int *pRes){ int rc; MemPage *pPage = pCur->pPage; #ifndef SQLITE_OMIT_SHARED_CACHE - rc = restoreOrClearCursorPosition(pCur, 1); + rc = restoreCursorPosition(pCur, 1); if( rc!=SQLITE_OK ){ return rc; } if( pCur->skip>0 ){ pCur->skip = 0; @@ -3503,11 +3489,11 @@ int rc; Pgno pgno; MemPage *pPage; #ifndef SQLITE_OMIT_SHARED_CACHE - rc = restoreOrClearCursorPosition(pCur, 1); + rc = restoreCursorPosition(pCur, 1); if( rc!=SQLITE_OK ){ return rc; } if( pCur->skip<0 ){ pCur->skip = 0; @@ -5173,12 +5159,12 @@ if( checkReadLocks(pBt, pCur->pgnoRoot, pCur) ){ return SQLITE_LOCKED; /* The table pCur points to has a read lock */ } /* Save the positions of any other cursors open on this table */ - restoreOrClearCursorPosition(pCur, 0); if( + SQLITE_OK!=(rc = restoreCursorPosition(pCur, 0)) || SQLITE_OK!=(rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur)) || SQLITE_OK!=(rc = sqlite3BtreeMoveto(pCur, pKey, nKey, &loc)) ){ return rc; } @@ -5260,11 +5246,11 @@ ** CURSOR_REQUIRESEEK state) and save the positions of any other cursors ** open on the same table. Then call sqlite3pager_write() on the page ** that the entry will be deleted from. */ if( - (rc = restoreOrClearCursorPosition(pCur, 1)) || + (rc = restoreCursorPosition(pCur, 1)) || (rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur)) || (rc = sqlite3pager_write(pPage->aData)) ){ return rc; } @@ -5742,11 +5728,11 @@ ** Return the flag byte at the beginning of the page that the cursor ** is currently pointing to. */ int sqlite3BtreeFlags(BtCursor *pCur){ /* TODO: What about CURSOR_REQUIRESEEK state? Probably need to call - ** restoreOrClearCursorPosition() here. + ** restoreCursorPosition() here. */ MemPage *pPage = pCur->pPage; return pPage ? pPage->aData[pPage->hdrOffset] : 0; } @@ -5877,11 +5863,11 @@ int sqlite3BtreeCursorInfo(BtCursor *pCur, int *aResult, int upCnt){ int cnt, idx; MemPage *pPage = pCur->pPage; BtCursor tmpCur; - int rc = restoreOrClearCursorPosition(pCur, 1); + int rc = restoreCursorPosition(pCur, 1); if( rc!=SQLITE_OK ){ return rc; } pageIntegrity(pPage); Index: src/build.c ================================================================== --- src/build.c +++ src/build.c @@ -20,11 +20,11 @@ ** creating ID lists ** BEGIN TRANSACTION ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.379 2006/01/13 06:33:24 danielk1977 Exp $ +** $Id: build.c,v 1.378 2006/01/12 01:56:44 drh Exp $ */ #include "sqliteInt.h" #include /* @@ -1171,11 +1171,11 @@ if( (p = pParse->pNewTable)==0 ) return; i = p->nCol-1; if( sqlite3LocateCollSeq(pParse, zType, nType) ){ Index *pIdx; - p->aCol[i].zColl = sqliteStrNDup(zType, nType); + p->aCol[i].zColl = sqlite3StrNDup(zType, nType); /* If the column is declared as " PRIMARY KEY COLLATE ", ** then an index may have been created on this column before the ** collation type was added. Correct this if it is the case. */ @@ -3151,11 +3151,11 @@ return; }else if( pName2==0 || pName2->z==0 ){ assert( pName1->z ); pColl = sqlite3FindCollSeq(db, ENC(db), (char*)pName1->z, pName1->n, 0); if( pColl ){ - char *z = sqliteStrNDup(pName1->z, pName1->n); + char *z = sqlite3StrNDup(pName1->z, pName1->n); if( z ){ reindexDatabases(pParse, z); sqliteFree(z); } return; Index: src/date.c ================================================================== --- src/date.c +++ src/date.c @@ -14,11 +14,11 @@ ** ** There is only one exported symbol in this file - the function ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: date.c,v 1.50 2006/01/13 01:17:21 drh Exp $ +** $Id: date.c,v 1.49 2006/01/09 00:18:03 drh Exp $ ** ** NOTES: ** ** SQLite processes all times and dates as Julian Day numbers. The ** dates and times are stored as the number of days since noon @@ -115,11 +115,10 @@ } *pVal = val; zDate++; cnt++; }while( nextC ); - va_end(ap); return cnt; } /* ** Read text from z[] and convert into a floating point number. Return Index: src/expr.c ================================================================== --- src/expr.c +++ src/expr.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.249 2006/01/13 06:33:24 danielk1977 Exp $ +** $Id: expr.c,v 1.248 2006/01/11 21:41:22 drh Exp $ */ #include "sqliteInt.h" #include /* @@ -353,11 +353,11 @@ } if( i>=pParse->nVarExpr ){ pExpr->iTable = ++pParse->nVar; if( pParse->nVarExpr>=pParse->nVarExprAlloc-1 ){ pParse->nVarExprAlloc += pParse->nVarExprAlloc + 10; - sqliteReallocOrFree((void**)&pParse->apVarExpr, + sqlite3ReallocOrFree((void**)&pParse->apVarExpr, pParse->nVarExprAlloc*sizeof(pParse->apVarExpr[0]) ); } if( !sqlite3ThreadDataReadOnly()->mallocFailed ){ assert( pParse->apVarExpr!=0 ); pParse->apVarExpr[pParse->nVarExpr++] = pExpr; Index: src/func.c ================================================================== --- src/func.c +++ src/func.c @@ -14,11 +14,11 @@ ** ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.116 2006/01/12 22:17:50 drh Exp $ +** $Id: func.c,v 1.115 2006/01/09 16:12:05 danielk1977 Exp $ */ #include "sqliteInt.h" #include /* #include */ #include @@ -821,17 +821,11 @@ int cnt; /* Number of elements summed */ u8 seenFloat; /* True if there has been any floating point value */ }; /* -** Routines used to compute the sum, average, and total. -** -** The SUM() function follows the (broken) SQL standard which means -** that it returns NULL if it sums over no inputs. TOTAL returns -** 0.0 in that case. In addition, TOTAL always returns a float where -** SUM might return an integer if it never encounters a floating point -** value. +** Routines used to compute the sum or average. */ static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){ SumCtx *p; int type; assert( argc==1 ); @@ -861,15 +855,10 @@ p = sqlite3_aggregate_context(context, 0); if( p && p->cnt>0 ){ sqlite3_result_double(context, p->sum/(double)p->cnt); } } -static void totalFinalize(sqlite3_context *context){ - SumCtx *p; - p = sqlite3_aggregate_context(context, 0); - sqlite3_result_double(context, p ? p->sum : 0.0); -} /* ** An instance of the following structure holds the context of a ** variance or standard deviation computation. */ @@ -1009,11 +998,10 @@ void (*xFinalize)(sqlite3_context*); } aAggs[] = { { "min", 1, 0, 1, minmaxStep, minMaxFinalize }, { "max", 1, 2, 1, minmaxStep, minMaxFinalize }, { "sum", 1, 0, 0, sumStep, sumFinalize }, - { "total", 1, 0, 0, sumStep, totalFinalize }, { "avg", 1, 0, 0, sumStep, avgFinalize }, { "count", 0, 0, 0, countStep, countFinalize }, { "count", 1, 0, 0, countStep, countFinalize }, }; int i; Index: src/os_common.h ================================================================== --- src/os_common.h +++ src/os_common.h @@ -130,20 +130,11 @@ ** sqlite3GenericAllocationSize ** ** Implementation of the os level dynamic memory allocation interface in terms ** of the standard malloc(), realloc() and free() found in many operating ** systems. No rocket science here. -** -** There are two versions of these four functions here. The version -** implemented here is only used if memory-management or memory-debugging is -** enabled. This version allocates an extra 8-bytes at the beginning of each -** block and stores the size of the allocation there. -** -** If neither memory-management or debugging is enabled, the second -** set of implementations is used instead. */ -#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || defined (SQLITE_MEMDEBUG) void *sqlite3GenericMalloc(int n){ char *p = (char *)malloc(n+8); assert(n>0); assert(sizeof(int)<=8); if( p ){ @@ -165,25 +156,5 @@ free((void *)((char *)p - 8)); } int sqlite3GenericAllocationSize(void *p){ return p ? *(int *)((char *)p - 8) : 0; } -#else -void *sqlite3GenericMalloc(int n){ - char *p = (char *)malloc(n); - return (void *)p; -} -void *sqlite3GenericRealloc(void *p, int n){ - assert(n>0); - p = realloc(p, n); - return p; -} -void sqlite3GenericFree(void *p){ - assert(p); - free(p); -} -#if 0 /* Never actually invoked */ -int sqlite3GenericAllocationSize(void *p){ - assert(0); -} -#endif -#endif Index: src/os_win.c ================================================================== --- src/os_win.c +++ src/os_win.c @@ -932,11 +932,11 @@ zFull = sqliteMalloc( nByte ); if( zFull==0 ) return 0; if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0; #elif OS_WINCE /* WinCE has no concept of a relative pathname, or so I am told. */ - zFull = sqliteStrDup(zRelative); + zFull = sqlite3StrDup(zRelative); #else char *zNotUsed; WCHAR *zWide; int nByte; zWide = utf8ToUnicode(zRelative); Index: src/prepare.c ================================================================== --- src/prepare.c +++ src/prepare.c @@ -11,11 +11,11 @@ ************************************************************************* ** This file contains the implementation of the sqlite3_prepare() ** interface, and routines that contribute to loading the database schema ** from disk. ** -** $Id: prepare.c,v 1.22 2006/01/13 06:33:24 danielk1977 Exp $ +** $Id: prepare.c,v 1.21 2006/01/12 12:43:36 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include @@ -320,13 +320,12 @@ ** Initialize all database files - the main database file, the file ** used to store temporary tables, and any additional database files ** created using ATTACH statements. Return a success code. If an ** error occurs, write an error message into *pzErrMsg. ** -** After a database is initialized, the DB_SchemaLoaded bit is set -** bit is set in the flags field of the Db structure. If the database -** file was of zero-length, then the DB_Empty flag is also set. +** After the database is initialized, the SQLITE_Initialized +** bit is set in the flags field of the sqlite structure. */ int sqlite3Init(sqlite3 *db, char **pzErrMsg){ int i, rc; int called_initone = 0; Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.294 2006/01/13 06:33:24 danielk1977 Exp $ +** $Id: select.c,v 1.293 2006/01/11 21:41:22 drh Exp $ */ #include "sqliteInt.h" /* @@ -1032,11 +1032,11 @@ zType = sqliteStrDup(columnType(&sNC, p)); pCol->zType = zType; pCol->affinity = sqlite3ExprAffinity(p); pColl = sqlite3ExprCollSeq(pParse, p); if( pColl ){ - pCol->zColl = sqliteStrDup(pColl->zName); + pCol->zColl = sqlite3StrDup(pColl->zName); } } pTab->iPKey = -1; return pTab; } Index: src/sqliteInt.h ================================================================== --- src/sqliteInt.h +++ src/sqliteInt.h @@ -9,11 +9,11 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.467 2006/01/13 06:33:24 danielk1977 Exp $ +** @(#) $Id: sqliteInt.h,v 1.466 2006/01/12 17:20:51 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ /* @@ -282,11 +282,10 @@ #endif #define sqliteFree(x) sqlite3FreeX(x) #define sqliteAllocSize(x) sqlite3AllocSize(x) - /* ** An instance of this structure might be allocated to store information ** specific to a single thread. ** Index: src/utf.c ================================================================== --- src/utf.c +++ src/utf.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file contains routines used to translate between UTF-8, ** UTF-16, UTF-16BE, and UTF-16LE. ** -** $Id: utf.c,v 1.36 2006/01/13 06:33:24 danielk1977 Exp $ +** $Id: utf.c,v 1.35 2005/12/15 22:34:01 drh Exp $ ** ** Notes on UTF-8: ** ** Byte-0 Byte-1 Byte-2 Byte-3 Value ** 0xxxxxxx 00000000 00000000 0xxxxxxx @@ -462,11 +462,11 @@ memset(&m, 0, sizeof(m)); sqlite3VdbeMemSetStr(&m, z, nByte, SQLITE_UTF16NATIVE, SQLITE_STATIC); sqlite3VdbeChangeEncoding(&m, SQLITE_UTF8); assert( m.flags & MEM_Term ); assert( m.flags & MEM_Str ); - return (m.flags & MEM_Dyn)!=0 ? m.z : sqliteStrDup(m.z); + return (m.flags & MEM_Dyn)!=0 ? m.z : sqlite3StrDup(m.z); } /* ** pZ is a UTF-16 encoded unicode string. If nChar is less than zero, ** return the number of bytes up to (but not including), the first pair Index: src/util.c ================================================================== --- src/util.c +++ src/util.c @@ -12,11 +12,11 @@ ** Utility functions used throughout sqlite. ** ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.170 2006/01/13 06:33:24 danielk1977 Exp $ +** $Id: util.c,v 1.169 2006/01/12 01:25:18 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include #include @@ -645,15 +645,13 @@ ** The number of bytes allocated does not include any overhead inserted by ** any malloc() wrapper functions that may be called. So the value returned ** is the number of bytes that were available to SQLite using pointer p, ** regardless of how much memory was actually allocated. */ -#if 0 /* This is never actually used */ int sqlite3AllocSize(void *p){ return OSSIZEOF(p); } -#endif /* ** Make a copy of a string in memory obtained from sqliteMalloc(). These ** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This ** is because when memory debugging is turned on, these two functions are Index: src/vacuum.c ================================================================== --- src/vacuum.c +++ src/vacuum.c @@ -12,11 +12,11 @@ ** This file contains code used to implement the VACUUM command. ** ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** -** $Id: vacuum.c,v 1.57 2006/01/13 01:48:59 drh Exp $ +** $Id: vacuum.c,v 1.56 2006/01/11 16:10:20 danielk1977 Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" #include "os.h" @@ -99,10 +99,11 @@ int nFilename; /* number of characters in zFilename[] */ char *zTemp = 0; /* a temporary file in same directory as zFilename */ Btree *pMain; /* The database being vacuumed */ Btree *pTemp; char *zSql = 0; + int rc2; int saved_flags; /* Saved value of the db->flags */ Db *pDb = 0; /* Database to detach at end of vacuum */ /* Save the current value of the write-schema flag before setting it. */ saved_flags = db->flags; Index: src/vdbe.c ================================================================== --- src/vdbe.c +++ src/vdbe.c @@ -41,11 +41,11 @@ ** documentation, headers files, or other derived files. The formatting ** of the code in this file is, therefore, important. See other comments ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.527 2006/01/13 06:33:24 danielk1977 Exp $ +** $Id: vdbe.c,v 1.525 2006/01/12 17:20:51 drh Exp $ */ #include "sqliteInt.h" #include "os.h" #include #include "vdbeInt.h" @@ -99,26 +99,10 @@ ** will fit but this routine always mallocs for space. ** Return non-zero if we run out of memory. */ #define Dynamicify(P,enc) sqlite3VdbeMemDynamicify(P) -/* -** The header of a record consists of a sequence variable-length integers. -** These integers are almost always small and are encoded as a single byte. -** The following macro takes advantage this fact to provide a fast decode -** of the integers in a record header. It is faster for the common case -** where the integer is a single byte. It is a little slower when the -** integer is two or more bytes. But overall it is faster. -** -** The following expressions are equivalent: -** -** x = sqlite3GetVarint32( A, &B ); -** -** x = GetVarint( A, B ); -** -*/ -#define GetVarint(A,B) ((B = *(A))<=0x7f ? 1 : sqlite3GetVarint32(A, &B)) /* ** An ephemeral string value (signified by the MEM_Ephem flag) contains ** a pointer to a dynamically allocated string where some other entity ** is responsible for deallocating that string. Because the stack entry @@ -2005,11 +1989,11 @@ pC->aRow = (u8*)zData; }else{ pC->aRow = 0; } } - idx = GetVarint((u8*)zData, szHdr); + idx = sqlite3GetVarint32((u8*)zData, &szHdr); /* The KeyFetch() or DataFetch() above are fast and will get the entire ** record header in most cases. But they will fail to get the complete ** record header if the record header does not fit on a single page @@ -2032,11 +2016,11 @@ offset = szHdr; assert( offset>0 ); i = 0; while( idx=0 ); /* FIX ME: This should be allocated as part of the vdbe at compile-time */ if( i>=p->contextStackDepth ){ p->contextStackDepth = i+1; - sqliteReallocOrFree((void**)&p->contextStack, sizeof(Context)*(i+1)); + sqlite3ReallocOrFree((void**)&p->contextStack, sizeof(Context)*(i+1)); if( p->contextStack==0 ) goto no_mem; } pContext = &p->contextStack[i]; pContext->lastRowid = db->lastRowid; pContext->nChange = p->nChange; Index: src/vdbeaux.c ================================================================== --- src/vdbeaux.c +++ src/vdbeaux.c @@ -145,11 +145,11 @@ int i; i = p->nLabel++; assert( p->magic==VDBE_MAGIC_INIT ); if( i>=p->nLabelAlloc ){ p->nLabelAlloc = p->nLabelAlloc*2 + 10; - sqliteReallocOrFree((void**)&p->aLabel, + sqlite3ReallocOrFree((void**)&p->aLabel, p->nLabelAlloc*sizeof(p->aLabel[0])); } if( p->aLabel ){ p->aLabel[i] = -1; } Index: src/where.c ================================================================== --- src/where.c +++ src/where.c @@ -14,11 +14,11 @@ ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** -** $Id: where.c,v 1.196 2006/01/13 13:01:19 danielk1977 Exp $ +** $Id: where.c,v 1.194 2006/01/11 21:41:22 drh Exp $ */ #include "sqliteInt.h" /* ** The number of bits in a Bitmask. "BMS" means "BitMask Size". @@ -1162,28 +1162,18 @@ ** Generate code that builds a probe for an index. Details: ** ** * Check the top nColumn entries on the stack. If any ** of those entries are NULL, jump immediately to brk, ** which is the loop exit, since no index entry will match -** if any part of the key is NULL. Pop (nColumn+nExtra) -** elements from the stack. +** if any part of the key is NULL. ** ** * Construct a probe entry from the top nColumn entries in -** the stack with affinities appropriate for index pIdx. -** Only nColumn elements are popped from the stack in this case -** (by OP_MakeRecord). -** +** the stack with affinities appropriate for index pIdx. */ -static void buildIndexProbe( - Vdbe *v, - int nColumn, - int nExtra, - int brk, - Index *pIdx -){ +static void buildIndexProbe(Vdbe *v, int nColumn, int brk, Index *pIdx){ sqlite3VdbeAddOp(v, OP_NotNull, -nColumn, sqlite3VdbeCurrentAddr(v)+3); - sqlite3VdbeAddOp(v, OP_Pop, nColumn+nExtra, 0); + sqlite3VdbeAddOp(v, OP_Pop, nColumn, 0); sqlite3VdbeAddOp(v, OP_Goto, 0, brk); sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0); sqlite3IndexAffinityStr(v, pIdx); } @@ -1218,11 +1208,11 @@ sqlite3CodeSubselect(pParse, pX); iTab = pX->iTable; sqlite3VdbeAddOp(v, OP_Rewind, iTab, brk); VdbeComment((v, "# %.*s", pX->span.n, pX->span.z)); pLevel->nIn++; - sqliteReallocOrFree((void**)&pLevel->aInLoop, + sqlite3ReallocOrFree((void**)&pLevel->aInLoop, sizeof(pLevel->aInLoop[0])*3*pLevel->nIn); aIn = pLevel->aInLoop; if( aIn ){ aIn += pLevel->nIn*3 - 3; aIn[0] = OP_Next; @@ -1791,11 +1781,11 @@ topEq = 1; } if( testOp!=OP_Noop ){ int nCol = nEq + topLimit; pLevel->iMem = pParse->nMem++; - buildIndexProbe(v, nCol, nEq, brk, pIdx); + buildIndexProbe(v, nCol, brk, pIdx); if( bRev ){ int op = topEq ? OP_MoveLe : OP_MoveLt; sqlite3VdbeAddOp(v, op, iIdxCur, brk); }else{ sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1); @@ -1826,11 +1816,11 @@ }else{ btmEq = 1; } if( nEq>0 || btmLimit ){ int nCol = nEq + btmLimit; - buildIndexProbe(v, nCol, 0, brk, pIdx); + buildIndexProbe(v, nCol, brk, pIdx); if( bRev ){ pLevel->iMem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1); testOp = OP_IdxLT; }else{ @@ -1880,11 +1870,11 @@ codeAllEqualityTerms(pParse, pLevel, &wc, notReady, brk); /* Generate a single key that will be used to both start and terminate ** the search */ - buildIndexProbe(v, nEq, 0, brk, pIdx); + buildIndexProbe(v, nEq, brk, pIdx); sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 0); /* Generate code (1) to move to the first matching element of the table. ** Then generate code (2) that jumps to "brk" after the cursor is past ** the last matching element of the table. The code (1) is executed Index: test/auth.test ================================================================== --- test/auth.test +++ test/auth.test @@ -10,11 +10,11 @@ #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script is testing the ATTACH and DETACH commands # and related functionality. # -# $Id: auth.test,v 1.30 2006/01/13 13:55:45 drh Exp $ +# $Id: auth.test,v 1.29 2005/07/29 15:36:15 drh Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -2205,22 +2205,11 @@ execsql { SELECT count(a) AS cnt FROM t4 ORDER BY cnt } } {1} -# Ticket #1607 -# -do_test auth-5.2 { - execsql { - SELECT name FROM ( - SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) - WHERE type='table' - ORDER BY name - } -} {sqlite_stat1 t1 t2 t3 t4 tx v1chng} - rename proc {} rename proc_real proc finish_test Index: test/capi3.test ================================================================== --- test/capi3.test +++ test/capi3.test @@ -9,11 +9,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script testing the callback-free C/C++ API. # -# $Id: capi3.test,v 1.38 2006/01/13 01:25:06 drh Exp $ +# $Id: capi3.test,v 1.37 2006/01/09 23:40:25 drh Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -85,46 +85,34 @@ do_test capi3-1.7 { sqlite3_errmsg $DB } {no such column: namex} ifcapable {utf16} { - do_test capi3-2.1 { - set sql16 [utf16 {SELECT name FROM sqlite_master}] - set STMT [sqlite3_prepare16 $DB $sql16 -1 ::TAIL] - sqlite3_finalize $STMT - utf8 $::TAIL - } {} - do_test capi3-2.2 { - set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}] - set STMT [sqlite3_prepare16 $DB $sql -1 TAIL] - sqlite3_finalize $STMT - utf8 $TAIL - } {SELECT 10} - do_test capi3-2.3 { - set sql [utf16 {SELECT namex FROM sqlite_master}] - catch { - set STMT [sqlite3_prepare16 $DB $sql -1 TAIL] - } - } {1} - do_test capi3-2.4 { - sqlite3_errcode $DB - } {SQLITE_ERROR} - do_test capi3-2.5 { - sqlite3_errmsg $DB - } {no such column: namex} - do_test capi3-2.6 { - execsql {CREATE TABLE tablename(x)} - set sql16 [utf16 {PRAGMA table_info("TableName")}] - set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL] - sqlite3_step $STMT - } SQLITE_ROW - do_test capi3-2.7 { - sqlite3_step $STMT - } SQLITE_DONE - do_test capi3-2.8 { - sqlite3_finalize $STMT - } SQLITE_OK +do_test capi3-2.1 { + set sql16 [utf16 {SELECT name FROM sqlite_master}] + set STMT [sqlite3_prepare16 $DB $sql16 -1 ::TAIL] + sqlite3_finalize $STMT + utf8 $::TAIL +} {} +do_test capi3-2.2 { + set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}] + set STMT [sqlite3_prepare16 $DB $sql -1 TAIL] + sqlite3_finalize $STMT + utf8 $TAIL +} {SELECT 10} +do_test capi3-2.3 { + set sql [utf16 {SELECT namex FROM sqlite_master}] + catch { + set STMT [sqlite3_prepare16 $DB $sql -1 TAIL] + } +} {1} +do_test capi3-2.4 { + sqlite3_errcode $DB +} {SQLITE_ERROR} +do_test capi3-2.5 { + sqlite3_errmsg $DB +} {no such column: namex} } ;# endif utf16 # rename sqlite3_open sqlite3_open_old # proc sqlite3_open {fname options} {sqlite3_open_new $fname $options} Index: test/null.test ================================================================== --- test/null.test +++ test/null.test @@ -100,18 +100,10 @@ select count(*), count(b), count(c), sum(b), sum(c), avg(b), avg(c), min(b), max(b) from t1; } } {7 4 6 2 3 0.5 0.5 0 1} -# The sum of zero entries is a NULL, but the total of zero entries is 0. -# -do_test null-3.2 { - execsql { - SELECT sum(b), total(b) FROM t1 WHERE b<0 - } -} {{} 0.0} - # Check to see how WHERE clauses handle NULL values. A NULL value # is the same as UNKNOWN. The WHERE clause should only select those # rows that are TRUE. FALSE and UNKNOWN rows are rejected. # do_test null-4.1 { Index: test/select1.test ================================================================== --- test/select1.test +++ test/select1.test @@ -9,11 +9,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the SELECT statement. # -# $Id: select1.test,v 1.46 2006/01/13 13:01:20 danielk1977 Exp $ +# $Id: select1.test,v 1.45 2005/12/15 10:11:32 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Try to select on a non-existant table. @@ -799,31 +799,6 @@ } } {x 1 x 3} } ;# ifcapable compound -# Check for a VDBE stack growth problem that existed at one point. -# -do_test select1-13.1 { - execsql { - BEGIN; - create TABLE abc(a, b, c, PRIMARY KEY(a, b)); - INSERT INTO abc VALUES(1, 1, 1); - } - for {set i 0} {$i<10} {incr i} { - execsql { - INSERT INTO abc SELECT a+(select max(a) FROM abc), - b+(select max(a) FROM abc), c+(select max(a) FROM abc) FROM abc; - } - } - execsql {COMMIT} - - # This used to seg-fault when the problem existed. - execsql { - SELECT count( - (SELECT a FROM abc WHERE a = NULL AND b >= upper.c) - ) FROM abc AS upper; - } -} {0} - finish_test - Index: www/lang.tcl ================================================================== --- www/lang.tcl +++ www/lang.tcl @@ -1,9 +1,9 @@ # # Run this Tcl script to generate the lang-*.html files. # -set rcsid {$Id: lang.tcl,v 1.105 2006/01/12 22:17:50 drh Exp $} +set rcsid {$Id: lang.tcl,v 1.104 2006/01/04 15:58:29 drh Exp $} source common.tcl if {[llength $argv]>0} { set outputdir [lindex $argv 0] } else { @@ -1393,19 +1393,19 @@ The usual sort order is used to determine the minimum. NULL is only returned if all values in the group are NULL. -sum(X)
total(X) +sum(X) Return the numeric sum of all numeric values in the group. - If there are no input rows or all values are NULL, then sum() returns - NULL but total() returns zero. + If there are no input rows or all values are NULL, then NULL is returned. NULL is not a helpful result in that case (the correct answer should be - zero) but the SQL standard requires that behavior from sum() and that is how - most other SQL database engines implement sum() so SQLite does it that way - in order to be compatible. The non-standard total() function is provided - as a convenient way + zero) but it is what the SQL standard requires and how + most other SQL database engines operate so SQLite does it that way + in order to be compatible. + You will probably want to use + "coalesce(sum(X),0)" instead of just "sum(X)" to work around this design problem in the SQL language. }