| | @@ -15,11 +15,11 @@ |
| 15 | 15 | ** of the embedded sqlite3.h header file.) Additional code files may be needed |
| 16 | 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | 19 | ** |
| 20 | | -** This amalgamation was generated on 2009-09-09 16:11:06 UTC. |
| 20 | +** This amalgamation was generated on 2009-09-10 22:23:14 UTC. |
| 21 | 21 | */ |
| 22 | 22 | #define SQLITE_CORE 1 |
| 23 | 23 | #define SQLITE_AMALGAMATION 1 |
| 24 | 24 | #ifndef SQLITE_PRIVATE |
| 25 | 25 | # define SQLITE_PRIVATE static |
| | @@ -275,11 +275,15 @@ |
| 275 | 275 | |
| 276 | 276 | /* |
| 277 | 277 | ** Maximum depth of recursion for triggers. |
| 278 | 278 | */ |
| 279 | 279 | #ifndef SQLITE_MAX_TRIGGER_DEPTH |
| 280 | +#if defined(SQLITE_SMALL_STACK) |
| 281 | +# define SQLITE_MAX_TRIGGER_DEPTH 10 |
| 282 | +#else |
| 280 | 283 | # define SQLITE_MAX_TRIGGER_DEPTH 1000 |
| 284 | +#endif |
| 281 | 285 | #endif |
| 282 | 286 | |
| 283 | 287 | /************** End of sqliteLimit.h *****************************************/ |
| 284 | 288 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 285 | 289 | |
| | @@ -643,11 +647,11 @@ |
| 643 | 647 | ** |
| 644 | 648 | ** Requirements: [H10011] [H10014] |
| 645 | 649 | */ |
| 646 | 650 | #define SQLITE_VERSION "3.6.18" |
| 647 | 651 | #define SQLITE_VERSION_NUMBER 3006018 |
| 648 | | -#define SQLITE_SOURCE_ID "2009-09-09 16:10:51 f0c72a53c5d57d7487b48a06a40816153f47aaac" |
| 652 | +#define SQLITE_SOURCE_ID "2009-09-10 20:23:30 f42ec993ac9d42ca31305f26b09924108c36d9f4" |
| 649 | 653 | |
| 650 | 654 | /* |
| 651 | 655 | ** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100> |
| 652 | 656 | ** KEYWORDS: sqlite3_version |
| 653 | 657 | ** |
| | @@ -7506,11 +7510,11 @@ |
| 7506 | 7510 | SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int,int,int); |
| 7507 | 7511 | SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*); |
| 7508 | 7512 | SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int); |
| 7509 | 7513 | SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*); |
| 7510 | 7514 | #ifdef SQLITE_DEBUG |
| 7511 | | -SQLITE_PRIVATE int sqlite3VdbeMayAbort(Vdbe*); |
| 7515 | +SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int); |
| 7512 | 7516 | SQLITE_PRIVATE void sqlite3VdbeTrace(Vdbe*,FILE*); |
| 7513 | 7517 | #endif |
| 7514 | 7518 | SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*); |
| 7515 | 7519 | SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*); |
| 7516 | 7520 | SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int); |
| | @@ -11373,11 +11377,11 @@ |
| 11373 | 11377 | x.s = s; |
| 11374 | 11378 | } |
| 11375 | 11379 | x.tz = 0; |
| 11376 | 11380 | x.validJD = 0; |
| 11377 | 11381 | computeJD(&x); |
| 11378 | | - t = x.iJD/1000 - 21086676*(i64)10000; |
| 11382 | + t = (time_t)(x.iJD/1000 - 21086676*(i64)10000); |
| 11379 | 11383 | #ifdef HAVE_LOCALTIME_R |
| 11380 | 11384 | { |
| 11381 | 11385 | struct tm sLocal; |
| 11382 | 11386 | localtime_r(&t, &sLocal); |
| 11383 | 11387 | y.Y = sLocal.tm_year + 1900; |
| | @@ -14368,10 +14372,20 @@ |
| 14368 | 14372 | ** This file contains code that is common across all mutex implementations. |
| 14369 | 14373 | |
| 14370 | 14374 | ** |
| 14371 | 14375 | ** $Id: mutex.c,v 1.31 2009/07/16 18:21:18 drh Exp $ |
| 14372 | 14376 | */ |
| 14377 | + |
| 14378 | +#if defined(SQLITE_DEBUG) && !defined(SQLITE_MUTEX_OMIT) |
| 14379 | +/* |
| 14380 | +** For debugging purposes, record when the mutex subsystem is initialized |
| 14381 | +** and uninitialized so that we can assert() if there is an attempt to |
| 14382 | +** allocate a mutex while the system is uninitialized. |
| 14383 | +*/ |
| 14384 | +static SQLITE_WSD int mutexIsInit = 0; |
| 14385 | +#endif /* SQLITE_DEBUG */ |
| 14386 | + |
| 14373 | 14387 | |
| 14374 | 14388 | #ifndef SQLITE_MUTEX_OMIT |
| 14375 | 14389 | /* |
| 14376 | 14390 | ** Initialize the mutex system. |
| 14377 | 14391 | */ |
| | @@ -14392,10 +14406,14 @@ |
| 14392 | 14406 | sizeof(*pTo) - offsetof(sqlite3_mutex_methods, xMutexFree)); |
| 14393 | 14407 | pTo->xMutexAlloc = pFrom->xMutexAlloc; |
| 14394 | 14408 | } |
| 14395 | 14409 | rc = sqlite3GlobalConfig.mutex.xMutexInit(); |
| 14396 | 14410 | } |
| 14411 | + |
| 14412 | +#ifdef SQLITE_DEBUG |
| 14413 | + GLOBAL(int, mutexIsInit) = 1; |
| 14414 | +#endif |
| 14397 | 14415 | |
| 14398 | 14416 | return rc; |
| 14399 | 14417 | } |
| 14400 | 14418 | |
| 14401 | 14419 | /* |
| | @@ -14405,10 +14423,15 @@ |
| 14405 | 14423 | SQLITE_PRIVATE int sqlite3MutexEnd(void){ |
| 14406 | 14424 | int rc = SQLITE_OK; |
| 14407 | 14425 | if( sqlite3GlobalConfig.mutex.xMutexEnd ){ |
| 14408 | 14426 | rc = sqlite3GlobalConfig.mutex.xMutexEnd(); |
| 14409 | 14427 | } |
| 14428 | + |
| 14429 | +#ifdef SQLITE_DEBUG |
| 14430 | + GLOBAL(int, mutexIsInit) = 0; |
| 14431 | +#endif |
| 14432 | + |
| 14410 | 14433 | return rc; |
| 14411 | 14434 | } |
| 14412 | 14435 | |
| 14413 | 14436 | /* |
| 14414 | 14437 | ** Retrieve a pointer to a static mutex or allocate a new dynamic one. |
| | @@ -14422,10 +14445,11 @@ |
| 14422 | 14445 | |
| 14423 | 14446 | SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){ |
| 14424 | 14447 | if( !sqlite3GlobalConfig.bCoreMutex ){ |
| 14425 | 14448 | return 0; |
| 14426 | 14449 | } |
| 14450 | + assert( GLOBAL(int, mutexIsInit) ); |
| 14427 | 14451 | return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
| 14428 | 14452 | } |
| 14429 | 14453 | |
| 14430 | 14454 | /* |
| 14431 | 14455 | ** Free a dynamic mutex. |
| | @@ -22403,11 +22427,21 @@ |
| 22403 | 22427 | } |
| 22404 | 22428 | if( pOpen->pNext ){ |
| 22405 | 22429 | assert( pOpen->pNext->pPrev==pOpen ); |
| 22406 | 22430 | pOpen->pNext->pPrev = pOpen->pPrev; |
| 22407 | 22431 | } |
| 22408 | | - assert( !pOpen->pUnused ); |
| 22432 | +#if SQLITE_THREADSAFE && defined(__linux__) |
| 22433 | + assert( !pOpen->pUnused || threadsOverrideEachOthersLocks==0 ); |
| 22434 | +#endif |
| 22435 | + |
| 22436 | + /* If pOpen->pUnused is not null, then memory and file-descriptors |
| 22437 | + ** are leaked. |
| 22438 | + ** |
| 22439 | + ** This will only happen if, under Linuxthreads, the user has opened |
| 22440 | + ** a transaction in one thread, then attempts to close the database |
| 22441 | + ** handle from another thread (without first unlocking the db file). |
| 22442 | + ** This is a misuse. */ |
| 22409 | 22443 | sqlite3_free(pOpen); |
| 22410 | 22444 | } |
| 22411 | 22445 | } |
| 22412 | 22446 | } |
| 22413 | 22447 | |
| | @@ -27555,21 +27589,21 @@ |
| 27555 | 27589 | |
| 27556 | 27590 | if (!pFile->hMutex) return TRUE; |
| 27557 | 27591 | winceMutexAcquire(pFile->hMutex); |
| 27558 | 27592 | |
| 27559 | 27593 | /* Wanting an exclusive lock? */ |
| 27560 | | - if (dwFileOffsetLow == SHARED_FIRST |
| 27561 | | - && nNumberOfBytesToLockLow == SHARED_SIZE){ |
| 27594 | + if (dwFileOffsetLow == (DWORD)SHARED_FIRST |
| 27595 | + && nNumberOfBytesToLockLow == (DWORD)SHARED_SIZE){ |
| 27562 | 27596 | if (pFile->shared->nReaders == 0 && pFile->shared->bExclusive == 0){ |
| 27563 | 27597 | pFile->shared->bExclusive = TRUE; |
| 27564 | 27598 | pFile->local.bExclusive = TRUE; |
| 27565 | 27599 | bReturn = TRUE; |
| 27566 | 27600 | } |
| 27567 | 27601 | } |
| 27568 | 27602 | |
| 27569 | 27603 | /* Want a read-only lock? */ |
| 27570 | | - else if (dwFileOffsetLow == SHARED_FIRST && |
| 27604 | + else if (dwFileOffsetLow == (DWORD)SHARED_FIRST && |
| 27571 | 27605 | nNumberOfBytesToLockLow == 1){ |
| 27572 | 27606 | if (pFile->shared->bExclusive == 0){ |
| 27573 | 27607 | pFile->local.nReaders ++; |
| 27574 | 27608 | if (pFile->local.nReaders == 1){ |
| 27575 | 27609 | pFile->shared->nReaders ++; |
| | @@ -27577,21 +27611,21 @@ |
| 27577 | 27611 | bReturn = TRUE; |
| 27578 | 27612 | } |
| 27579 | 27613 | } |
| 27580 | 27614 | |
| 27581 | 27615 | /* Want a pending lock? */ |
| 27582 | | - else if (dwFileOffsetLow == PENDING_BYTE && nNumberOfBytesToLockLow == 1){ |
| 27616 | + else if (dwFileOffsetLow == (DWORD)PENDING_BYTE && nNumberOfBytesToLockLow == 1){ |
| 27583 | 27617 | /* If no pending lock has been acquired, then acquire it */ |
| 27584 | 27618 | if (pFile->shared->bPending == 0) { |
| 27585 | 27619 | pFile->shared->bPending = TRUE; |
| 27586 | 27620 | pFile->local.bPending = TRUE; |
| 27587 | 27621 | bReturn = TRUE; |
| 27588 | 27622 | } |
| 27589 | 27623 | } |
| 27590 | 27624 | |
| 27591 | 27625 | /* Want a reserved lock? */ |
| 27592 | | - else if (dwFileOffsetLow == RESERVED_BYTE && nNumberOfBytesToLockLow == 1){ |
| 27626 | + else if (dwFileOffsetLow == (DWORD)RESERVED_BYTE && nNumberOfBytesToLockLow == 1){ |
| 27593 | 27627 | if (pFile->shared->bReserved == 0) { |
| 27594 | 27628 | pFile->shared->bReserved = TRUE; |
| 27595 | 27629 | pFile->local.bReserved = TRUE; |
| 27596 | 27630 | bReturn = TRUE; |
| 27597 | 27631 | } |
| | @@ -27619,22 +27653,22 @@ |
| 27619 | 27653 | |
| 27620 | 27654 | if (!pFile->hMutex) return TRUE; |
| 27621 | 27655 | winceMutexAcquire(pFile->hMutex); |
| 27622 | 27656 | |
| 27623 | 27657 | /* Releasing a reader lock or an exclusive lock */ |
| 27624 | | - if (dwFileOffsetLow == SHARED_FIRST){ |
| 27658 | + if (dwFileOffsetLow == (DWORD)SHARED_FIRST){ |
| 27625 | 27659 | /* Did we have an exclusive lock? */ |
| 27626 | 27660 | if (pFile->local.bExclusive){ |
| 27627 | | - assert(nNumberOfBytesToUnlockLow == SHARED_SIZE); |
| 27661 | + assert(nNumberOfBytesToUnlockLow == (DWORD)SHARED_SIZE); |
| 27628 | 27662 | pFile->local.bExclusive = FALSE; |
| 27629 | 27663 | pFile->shared->bExclusive = FALSE; |
| 27630 | 27664 | bReturn = TRUE; |
| 27631 | 27665 | } |
| 27632 | 27666 | |
| 27633 | 27667 | /* Did we just have a reader lock? */ |
| 27634 | 27668 | else if (pFile->local.nReaders){ |
| 27635 | | - assert(nNumberOfBytesToUnlockLow == 1); |
| 27669 | + assert(nNumberOfBytesToUnlockLow == (DWORD)SHARED_SIZE || nNumberOfBytesToUnlockLow == 1); |
| 27636 | 27670 | pFile->local.nReaders --; |
| 27637 | 27671 | if (pFile->local.nReaders == 0) |
| 27638 | 27672 | { |
| 27639 | 27673 | pFile->shared->nReaders --; |
| 27640 | 27674 | } |
| | @@ -27641,19 +27675,19 @@ |
| 27641 | 27675 | bReturn = TRUE; |
| 27642 | 27676 | } |
| 27643 | 27677 | } |
| 27644 | 27678 | |
| 27645 | 27679 | /* Releasing a pending lock */ |
| 27646 | | - else if (dwFileOffsetLow == PENDING_BYTE && nNumberOfBytesToUnlockLow == 1){ |
| 27680 | + else if (dwFileOffsetLow == (DWORD)PENDING_BYTE && nNumberOfBytesToUnlockLow == 1){ |
| 27647 | 27681 | if (pFile->local.bPending){ |
| 27648 | 27682 | pFile->local.bPending = FALSE; |
| 27649 | 27683 | pFile->shared->bPending = FALSE; |
| 27650 | 27684 | bReturn = TRUE; |
| 27651 | 27685 | } |
| 27652 | 27686 | } |
| 27653 | 27687 | /* Releasing a reserved lock */ |
| 27654 | | - else if (dwFileOffsetLow == RESERVED_BYTE && nNumberOfBytesToUnlockLow == 1){ |
| 27688 | + else if (dwFileOffsetLow == (DWORD)RESERVED_BYTE && nNumberOfBytesToUnlockLow == 1){ |
| 27655 | 27689 | if (pFile->local.bReserved) { |
| 27656 | 27690 | pFile->local.bReserved = FALSE; |
| 27657 | 27691 | pFile->shared->bReserved = FALSE; |
| 27658 | 27692 | bReturn = TRUE; |
| 27659 | 27693 | } |
| | @@ -27677,13 +27711,13 @@ |
| 27677 | 27711 | UNUSED_PARAMETER(dwReserved); |
| 27678 | 27712 | UNUSED_PARAMETER(nNumberOfBytesToLockHigh); |
| 27679 | 27713 | |
| 27680 | 27714 | /* If the caller wants a shared read lock, forward this call |
| 27681 | 27715 | ** to winceLockFile */ |
| 27682 | | - if (lpOverlapped->Offset == SHARED_FIRST && |
| 27716 | + if (lpOverlapped->Offset == (DWORD)SHARED_FIRST && |
| 27683 | 27717 | dwFlags == 1 && |
| 27684 | | - nNumberOfBytesToLockLow == SHARED_SIZE){ |
| 27718 | + nNumberOfBytesToLockLow == (DWORD)SHARED_SIZE){ |
| 27685 | 27719 | return winceLockFile(phFile, SHARED_FIRST, 0, 1, 0); |
| 27686 | 27720 | } |
| 27687 | 27721 | return FALSE; |
| 27688 | 27722 | } |
| 27689 | 27723 | /* |
| | @@ -47373,11 +47407,11 @@ |
| 47373 | 47407 | |
| 47374 | 47408 | return pRet; |
| 47375 | 47409 | } |
| 47376 | 47410 | |
| 47377 | 47411 | /* |
| 47378 | | -** Return true if the program stored in the VM passed as an argument may |
| 47412 | +** Check if the program stored in the VM associated with pParse may |
| 47379 | 47413 | ** throw an ABORT exception (causing the statement, but not transaction |
| 47380 | 47414 | ** to be rolled back). This condition is true if the main program or any |
| 47381 | 47415 | ** sub-programs contains any of the following: |
| 47382 | 47416 | ** |
| 47383 | 47417 | ** * OP_Halt with P1=SQLITE_CONSTRAINT and P2=OE_Abort. |
| | @@ -47384,14 +47418,19 @@ |
| 47384 | 47418 | ** * OP_HaltIfNull with P1=SQLITE_CONSTRAINT and P2=OE_Abort. |
| 47385 | 47419 | ** * OP_Destroy |
| 47386 | 47420 | ** * OP_VUpdate |
| 47387 | 47421 | ** * OP_VRename |
| 47388 | 47422 | ** |
| 47389 | | -** This function is only used as part of an assert() statement. |
| 47423 | +** Then check that the value of Parse.mayAbort is true if an |
| 47424 | +** ABORT may be thrown, or false otherwise. Return true if it does |
| 47425 | +** match, or false otherwise. This function is intended to be used as |
| 47426 | +** part of an assert statement in the compiler. Similar to: |
| 47427 | +** |
| 47428 | +** assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) ); |
| 47390 | 47429 | */ |
| 47391 | | -SQLITE_PRIVATE int sqlite3VdbeMayAbort(Vdbe *v){ |
| 47392 | | - int mayAbort = 0; |
| 47430 | +SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){ |
| 47431 | + int hasAbort = 0; |
| 47393 | 47432 | Op *pOp; |
| 47394 | 47433 | VdbeOpIter sIter; |
| 47395 | 47434 | memset(&sIter, 0, sizeof(sIter)); |
| 47396 | 47435 | sIter.v = v; |
| 47397 | 47436 | |
| | @@ -47399,17 +47438,22 @@ |
| 47399 | 47438 | int opcode = pOp->opcode; |
| 47400 | 47439 | if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename |
| 47401 | 47440 | || ((opcode==OP_Halt || opcode==OP_HaltIfNull) |
| 47402 | 47441 | && (pOp->p1==SQLITE_CONSTRAINT && pOp->p2==OE_Abort)) |
| 47403 | 47442 | ){ |
| 47404 | | - mayAbort = 1; |
| 47443 | + hasAbort = 1; |
| 47405 | 47444 | break; |
| 47406 | 47445 | } |
| 47407 | 47446 | } |
| 47408 | | - |
| 47409 | 47447 | sqlite3DbFree(v->db, sIter.apSub); |
| 47410 | | - return mayAbort; |
| 47448 | + |
| 47449 | + /* Return true if hasAbort==mayAbort. Or if a malloc failure occured. |
| 47450 | + ** If malloc failed, then the while() loop above may not have iterated |
| 47451 | + ** through all opcodes and hasAbort may be set incorrectly. Return |
| 47452 | + ** true for this case to prevent the assert() in the callers frame |
| 47453 | + ** from failing. */ |
| 47454 | + return ( v->db->mallocFailed || hasAbort==mayAbort ); |
| 47411 | 47455 | } |
| 47412 | 47456 | #endif |
| 47413 | 47457 | |
| 47414 | 47458 | /* |
| 47415 | 47459 | ** Loop through the program looking for P2 values that are negative |
| | @@ -48365,11 +48409,11 @@ |
| 48365 | 48409 | int nVar, /* Number of '?' see in the SQL statement */ |
| 48366 | 48410 | int nMem, /* Number of memory cells to allocate */ |
| 48367 | 48411 | int nCursor, /* Number of cursors to allocate */ |
| 48368 | 48412 | int nArg, /* Maximum number of args in SubPrograms */ |
| 48369 | 48413 | int isExplain, /* True if the EXPLAIN keywords is present */ |
| 48370 | | - int usesStmtJournal /* True to set Vdbe.usesStmtJournal */ |
| 48414 | + int usesStmtJournal /* True to set Vdbe.usesStmtJournal */ |
| 48371 | 48415 | ){ |
| 48372 | 48416 | int n; |
| 48373 | 48417 | sqlite3 *db = p->db; |
| 48374 | 48418 | |
| 48375 | 48419 | assert( p!=0 ); |
| | @@ -48401,11 +48445,11 @@ |
| 48401 | 48445 | if( nVar>=0 && ALWAYS(db->mallocFailed==0) ){ |
| 48402 | 48446 | u8 *zCsr = (u8 *)&p->aOp[p->nOp]; |
| 48403 | 48447 | u8 *zEnd = (u8 *)&p->aOp[p->nOpAlloc]; |
| 48404 | 48448 | int nByte; |
| 48405 | 48449 | resolveP2Values(p, &nArg); |
| 48406 | | - p->usesStmtJournal = usesStmtJournal; |
| 48450 | + p->usesStmtJournal = (u8)usesStmtJournal; |
| 48407 | 48451 | if( isExplain && nMem<10 ){ |
| 48408 | 48452 | nMem = 10; |
| 48409 | 48453 | } |
| 48410 | 48454 | memset(zCsr, 0, zEnd-zCsr); |
| 48411 | 48455 | zCsr += (zCsr - (u8*)0)&7; |
| | @@ -55382,18 +55426,22 @@ |
| 55382 | 55426 | } |
| 55383 | 55427 | } |
| 55384 | 55428 | |
| 55385 | 55429 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 55386 | 55430 | if( pOp->p3 ){ |
| 55431 | + /* Assert that P3 is a valid memory cell. */ |
| 55432 | + assert( pOp->p3>0 ); |
| 55387 | 55433 | if( p->pFrame ){ |
| 55388 | 55434 | for(u.be.pFrame=p->pFrame; u.be.pFrame->pParent; u.be.pFrame=u.be.pFrame->pParent); |
| 55435 | + /* Assert that P3 is a valid memory cell. */ |
| 55436 | + assert( pOp->p3<=u.be.pFrame->nMem ); |
| 55389 | 55437 | u.be.pMem = &u.be.pFrame->aMem[pOp->p3]; |
| 55390 | 55438 | }else{ |
| 55439 | + /* Assert that P3 is a valid memory cell. */ |
| 55440 | + assert( pOp->p3<=p->nMem ); |
| 55391 | 55441 | u.be.pMem = &p->aMem[pOp->p3]; |
| 55392 | 55442 | } |
| 55393 | | - /* Assert that P3 is a valid memory cell. */ |
| 55394 | | - assert( pOp->p3>0 && pOp->p3<=(p->pFrame ? u.be.pFrame->nMem : p->nMem) ); |
| 55395 | 55443 | |
| 55396 | 55444 | REGISTER_TRACE(pOp->p3, u.be.pMem); |
| 55397 | 55445 | sqlite3VdbeMemIntegerify(u.be.pMem); |
| 55398 | 55446 | assert( (u.be.pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */ |
| 55399 | 55447 | if( u.be.pMem->u.i==MAX_ROWID || u.be.pC->useRandomRowid ){ |
| | @@ -65441,11 +65489,12 @@ |
| 65441 | 65489 | |
| 65442 | 65490 | /* Begin by generating some termination code at the end of the |
| 65443 | 65491 | ** vdbe program |
| 65444 | 65492 | */ |
| 65445 | 65493 | v = sqlite3GetVdbe(pParse); |
| 65446 | | - assert( pParse->isMultiWrite==0 || sqlite3VdbeMayAbort(v)==pParse->mayAbort ); |
| 65494 | + assert( !pParse->isMultiWrite |
| 65495 | + || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort)); |
| 65447 | 65496 | if( v ){ |
| 65448 | 65497 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 65449 | 65498 | |
| 65450 | 65499 | /* The cookie mask contains one bit for each database file open. |
| 65451 | 65500 | ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are |
| | @@ -77658,11 +77707,11 @@ |
| 77658 | 77707 | Table *pTab = 0; /* Table structure column is extracted from */ |
| 77659 | 77708 | Select *pS = 0; /* Select the column is extracted from */ |
| 77660 | 77709 | int iCol = pExpr->iColumn; /* Index of column in pTab */ |
| 77661 | 77710 | testcase( pExpr->op==TK_AGG_COLUMN ); |
| 77662 | 77711 | testcase( pExpr->op==TK_COLUMN ); |
| 77663 | | - while( ALWAYS(pNC) && !pTab ){ |
| 77712 | + while( pNC && !pTab ){ |
| 77664 | 77713 | SrcList *pTabList = pNC->pSrcList; |
| 77665 | 77714 | for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++); |
| 77666 | 77715 | if( j<pTabList->nSrc ){ |
| 77667 | 77716 | pTab = pTabList->a[j].pTab; |
| 77668 | 77717 | pS = pTabList->a[j].pSelect; |
| | @@ -77669,22 +77718,32 @@ |
| 77669 | 77718 | }else{ |
| 77670 | 77719 | pNC = pNC->pNext; |
| 77671 | 77720 | } |
| 77672 | 77721 | } |
| 77673 | 77722 | |
| 77674 | | - if( NEVER(pTab==0) ){ |
| 77723 | + if( pTab==0 ){ |
| 77675 | 77724 | /* At one time, code such as "SELECT new.x" within a trigger would |
| 77676 | 77725 | ** cause this condition to run. Since then, we have restructured how |
| 77677 | 77726 | ** trigger code is generated and so this condition is no longer |
| 77678 | | - ** possible. But it seems prudent to keep the test in place in |
| 77679 | | - ** case something else changes. |
| 77680 | | - */ |
| 77681 | | - zType = "TEXT"; |
| 77727 | + ** possible. However, it can still be true for statements like |
| 77728 | + ** the following: |
| 77729 | + ** |
| 77730 | + ** CREATE TABLE t1(col INTEGER); |
| 77731 | + ** SELECT (SELECT t1.col) FROM FROM t1; |
| 77732 | + ** |
| 77733 | + ** when columnType() is called on the expression "t1.col" in the |
| 77734 | + ** sub-select. In this case, set the column type to NULL, even |
| 77735 | + ** though it should really be "INTEGER". |
| 77736 | + ** |
| 77737 | + ** This is not a problem, as the column type of "t1.col" is never |
| 77738 | + ** used. When columnType() is called on the expression |
| 77739 | + ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT |
| 77740 | + ** branch below. */ |
| 77682 | 77741 | break; |
| 77683 | 77742 | } |
| 77684 | 77743 | |
| 77685 | | - assert( pTab ); |
| 77744 | + assert( pTab && pExpr->pTab==pTab ); |
| 77686 | 77745 | if( pS ){ |
| 77687 | 77746 | /* The "table" is actually a sub-select or a view in the FROM clause |
| 77688 | 77747 | ** of the SELECT statement. Return the declaration type and origin |
| 77689 | 77748 | ** data for the result-set column of the sub-select. |
| 77690 | 77749 | */ |
| | @@ -77694,11 +77753,11 @@ |
| 77694 | 77753 | ** test case misc2.2.2) - it always evaluates to NULL. |
| 77695 | 77754 | */ |
| 77696 | 77755 | NameContext sNC; |
| 77697 | 77756 | Expr *p = pS->pEList->a[iCol].pExpr; |
| 77698 | 77757 | sNC.pSrcList = pS->pSrc; |
| 77699 | | - sNC.pNext = 0; |
| 77758 | + sNC.pNext = pNC; |
| 77700 | 77759 | sNC.pParse = pNC->pParse; |
| 77701 | 77760 | zType = columnType(&sNC, p, &zOriginDb, &zOriginTab, &zOriginCol); |
| 77702 | 77761 | } |
| 77703 | 77762 | }else if( ALWAYS(pTab->pSchema) ){ |
| 77704 | 77763 | /* A real table */ |
| 77705 | 77764 | |