| | @@ -1167,11 +1167,11 @@ |
| 1167 | 1167 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1168 | 1168 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1169 | 1169 | */ |
| 1170 | 1170 | #define SQLITE_VERSION "3.29.0" |
| 1171 | 1171 | #define SQLITE_VERSION_NUMBER 3029000 |
| 1172 | | -#define SQLITE_SOURCE_ID "2019-05-23 16:38:12 d2fe370cafa9b11f6c3eb4e1c3be48d9d2610b9d2f9d9ebf9e50267f9079dfc0" |
| 1172 | +#define SQLITE_SOURCE_ID "2019-06-05 14:29:53 7b3a99fce8b4a757f2b2ef2f0b02d68566f2528d9ae1e30628522717f872466c" |
| 1173 | 1173 | |
| 1174 | 1174 | /* |
| 1175 | 1175 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1176 | 1176 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1177 | 1177 | ** |
| | @@ -18730,12 +18730,16 @@ |
| 18730 | 18730 | #else |
| 18731 | 18731 | # define sqlite3MutexWarnOnContention(x) |
| 18732 | 18732 | #endif |
| 18733 | 18733 | |
| 18734 | 18734 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 18735 | +# define EXP754 (((u64)0x7ff)<<52) |
| 18736 | +# define MAN754 ((((u64)1)<<52)-1) |
| 18737 | +# define IsNaN(X) (((X)&EXP754)==EXP754 && ((X)&MAN754)!=0) |
| 18735 | 18738 | SQLITE_PRIVATE int sqlite3IsNaN(double); |
| 18736 | 18739 | #else |
| 18740 | +# define IsNaN(X) 0 |
| 18737 | 18741 | # define sqlite3IsNaN(X) 0 |
| 18738 | 18742 | #endif |
| 18739 | 18743 | |
| 18740 | 18744 | /* |
| 18741 | 18745 | ** An instance of the following structure holds information about SQL |
| | @@ -19103,10 +19107,11 @@ |
| 19103 | 19107 | SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*); |
| 19104 | 19108 | SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*); |
| 19105 | 19109 | SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*); |
| 19106 | 19110 | SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*); |
| 19107 | 19111 | SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*); |
| 19112 | +SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64); |
| 19108 | 19113 | SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8); |
| 19109 | 19114 | SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*); |
| 19110 | 19115 | SQLITE_PRIVATE int sqlite3Atoi(const char*); |
| 19111 | 19116 | #ifndef SQLITE_OMIT_UTF16 |
| 19112 | 19117 | SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar); |
| | @@ -27348,10 +27353,16 @@ |
| 27348 | 27353 | { 'T', 0, 0, etTOKEN, 0, 0 }, |
| 27349 | 27354 | { 'S', 0, 0, etSRCLIST, 0, 0 }, |
| 27350 | 27355 | { 'r', 10, 1, etORDINAL, 0, 0 }, |
| 27351 | 27356 | }; |
| 27352 | 27357 | |
| 27358 | +/* Floating point constants used for rounding */ |
| 27359 | +static const double arRound[] = { |
| 27360 | + 5.0e-01, 5.0e-02, 5.0e-03, 5.0e-04, 5.0e-05, |
| 27361 | + 5.0e-06, 5.0e-07, 5.0e-08, 5.0e-09, 5.0e-10, |
| 27362 | +}; |
| 27363 | + |
| 27353 | 27364 | /* |
| 27354 | 27365 | ** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point |
| 27355 | 27366 | ** conversions will work. |
| 27356 | 27367 | */ |
| 27357 | 27368 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| | @@ -27766,12 +27777,22 @@ |
| 27766 | 27777 | }else{ |
| 27767 | 27778 | prefix = flag_prefix; |
| 27768 | 27779 | } |
| 27769 | 27780 | if( xtype==etGENERIC && precision>0 ) precision--; |
| 27770 | 27781 | testcase( precision>0xfff ); |
| 27771 | | - for(idx=precision&0xfff, rounder=0.5; idx>0; idx--, rounder*=0.1){} |
| 27772 | | - if( xtype==etFLOAT ) realvalue += rounder; |
| 27782 | + idx = precision & 0xfff; |
| 27783 | + rounder = arRound[idx%10]; |
| 27784 | + while( idx>=10 ){ rounder *= 1.0e-10; idx -= 10; } |
| 27785 | + if( xtype==etFLOAT ){ |
| 27786 | + double rx = (double)realvalue; |
| 27787 | + sqlite3_uint64 u; |
| 27788 | + int ex; |
| 27789 | + memcpy(&u, &rx, sizeof(u)); |
| 27790 | + ex = -1023 + (int)((u>>52)&0x7ff); |
| 27791 | + if( precision+(ex/3) < 15 ) rounder += realvalue*3e-16; |
| 27792 | + realvalue += rounder; |
| 27793 | + } |
| 27773 | 27794 | /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */ |
| 27774 | 27795 | exp = 0; |
| 27775 | 27796 | if( sqlite3IsNaN((double)realvalue) ){ |
| 27776 | 27797 | bufpt = "NaN"; |
| 27777 | 27798 | length = 3; |
| | @@ -30270,51 +30291,15 @@ |
| 30270 | 30291 | #endif |
| 30271 | 30292 | |
| 30272 | 30293 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 30273 | 30294 | /* |
| 30274 | 30295 | ** Return true if the floating point value is Not a Number (NaN). |
| 30275 | | -** |
| 30276 | | -** Use the math library isnan() function if compiled with SQLITE_HAVE_ISNAN. |
| 30277 | | -** Otherwise, we have our own implementation that works on most systems. |
| 30278 | 30296 | */ |
| 30279 | 30297 | SQLITE_PRIVATE int sqlite3IsNaN(double x){ |
| 30280 | | - int rc; /* The value return */ |
| 30281 | | -#if !SQLITE_HAVE_ISNAN && !HAVE_ISNAN |
| 30282 | | - /* |
| 30283 | | - ** Systems that support the isnan() library function should probably |
| 30284 | | - ** make use of it by compiling with -DSQLITE_HAVE_ISNAN. But we have |
| 30285 | | - ** found that many systems do not have a working isnan() function so |
| 30286 | | - ** this implementation is provided as an alternative. |
| 30287 | | - ** |
| 30288 | | - ** This NaN test sometimes fails if compiled on GCC with -ffast-math. |
| 30289 | | - ** On the other hand, the use of -ffast-math comes with the following |
| 30290 | | - ** warning: |
| 30291 | | - ** |
| 30292 | | - ** This option [-ffast-math] should never be turned on by any |
| 30293 | | - ** -O option since it can result in incorrect output for programs |
| 30294 | | - ** which depend on an exact implementation of IEEE or ISO |
| 30295 | | - ** rules/specifications for math functions. |
| 30296 | | - ** |
| 30297 | | - ** Under MSVC, this NaN test may fail if compiled with a floating- |
| 30298 | | - ** point precision mode other than /fp:precise. From the MSDN |
| 30299 | | - ** documentation: |
| 30300 | | - ** |
| 30301 | | - ** The compiler [with /fp:precise] will properly handle comparisons |
| 30302 | | - ** involving NaN. For example, x != x evaluates to true if x is NaN |
| 30303 | | - ** ... |
| 30304 | | - */ |
| 30305 | | -#ifdef __FAST_MATH__ |
| 30306 | | -# error SQLite will not work correctly with the -ffast-math option of GCC. |
| 30307 | | -#endif |
| 30308 | | - volatile double y = x; |
| 30309 | | - volatile double z = y; |
| 30310 | | - rc = (y!=z); |
| 30311 | | -#else /* if HAVE_ISNAN */ |
| 30312 | | - rc = isnan(x); |
| 30313 | | -#endif /* HAVE_ISNAN */ |
| 30314 | | - testcase( rc ); |
| 30315 | | - return rc; |
| 30298 | + u64 y; |
| 30299 | + memcpy(&y,&x,sizeof(y)); |
| 30300 | + return IsNaN(y); |
| 30316 | 30301 | } |
| 30317 | 30302 | #endif /* SQLITE_OMIT_FLOATING_POINT */ |
| 30318 | 30303 | |
| 30319 | 30304 | /* |
| 30320 | 30305 | ** Compute a string length that is limited to what can be stored in |
| | @@ -30571,19 +30556,19 @@ |
| 30571 | 30556 | ** This routine only works for values of E between 1 and 341. |
| 30572 | 30557 | */ |
| 30573 | 30558 | static LONGDOUBLE_TYPE sqlite3Pow10(int E){ |
| 30574 | 30559 | #if defined(_MSC_VER) |
| 30575 | 30560 | static const LONGDOUBLE_TYPE x[] = { |
| 30576 | | - 1.0e+001, |
| 30577 | | - 1.0e+002, |
| 30578 | | - 1.0e+004, |
| 30579 | | - 1.0e+008, |
| 30580 | | - 1.0e+016, |
| 30581 | | - 1.0e+032, |
| 30582 | | - 1.0e+064, |
| 30583 | | - 1.0e+128, |
| 30584 | | - 1.0e+256 |
| 30561 | + 1.0e+001L, |
| 30562 | + 1.0e+002L, |
| 30563 | + 1.0e+004L, |
| 30564 | + 1.0e+008L, |
| 30565 | + 1.0e+016L, |
| 30566 | + 1.0e+032L, |
| 30567 | + 1.0e+064L, |
| 30568 | + 1.0e+128L, |
| 30569 | + 1.0e+256L |
| 30585 | 30570 | }; |
| 30586 | 30571 | LONGDOUBLE_TYPE r = 1.0; |
| 30587 | 30572 | int i; |
| 30588 | 30573 | assert( E>=0 && E<=307 ); |
| 30589 | 30574 | for(i=0; E!=0; i++, E >>=1){ |
| | @@ -30609,12 +30594,17 @@ |
| 30609 | 30594 | ** |
| 30610 | 30595 | ** The string z[] is length bytes in length (bytes, not characters) and |
| 30611 | 30596 | ** uses the encoding enc. The string is not necessarily zero-terminated. |
| 30612 | 30597 | ** |
| 30613 | 30598 | ** Return TRUE if the result is a valid real number (or integer) and FALSE |
| 30614 | | -** if the string is empty or contains extraneous text. Valid numbers |
| 30615 | | -** are in one of these formats: |
| 30599 | +** if the string is empty or contains extraneous text. More specifically |
| 30600 | +** return |
| 30601 | +** 1 => The input string is a pure integer |
| 30602 | +** 2 or more => The input has a decimal point or eNNN clause |
| 30603 | +** 0 => The input string is not a valid number |
| 30604 | +** |
| 30605 | +** Valid numbers are in one of these formats: |
| 30616 | 30606 | ** |
| 30617 | 30607 | ** [+-]digits[E[+-]digits] |
| 30618 | 30608 | ** [+-]digits.[digits][E[+-]digits] |
| 30619 | 30609 | ** [+-].digits[E[+-]digits] |
| 30620 | 30610 | ** |
| | @@ -30635,12 +30625,12 @@ |
| 30635 | 30625 | int d = 0; /* adjust exponent for shifting decimal point */ |
| 30636 | 30626 | int esign = 1; /* sign of exponent */ |
| 30637 | 30627 | int e = 0; /* exponent */ |
| 30638 | 30628 | int eValid = 1; /* True exponent is either not used or is well-formed */ |
| 30639 | 30629 | double result; |
| 30640 | | - int nDigits = 0; |
| 30641 | | - int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */ |
| 30630 | + int nDigit = 0; /* Number of digits processed */ |
| 30631 | + int eType = 1; /* 1: pure integer, 2+: fractional -1 or less: bad UTF16 */ |
| 30642 | 30632 | |
| 30643 | 30633 | assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); |
| 30644 | 30634 | *pResult = 0.0; /* Default return value, in case of an error */ |
| 30645 | 30635 | |
| 30646 | 30636 | if( enc==SQLITE_UTF8 ){ |
| | @@ -30647,12 +30637,14 @@ |
| 30647 | 30637 | incr = 1; |
| 30648 | 30638 | }else{ |
| 30649 | 30639 | int i; |
| 30650 | 30640 | incr = 2; |
| 30651 | 30641 | assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 ); |
| 30642 | + testcase( enc==SQLITE_UTF16LE ); |
| 30643 | + testcase( enc==SQLITE_UTF16BE ); |
| 30652 | 30644 | for(i=3-enc; i<length && z[i]==0; i+=2){} |
| 30653 | | - nonNum = i<length; |
| 30645 | + if( i<length ) eType = -100; |
| 30654 | 30646 | zEnd = &z[i^1]; |
| 30655 | 30647 | z += (enc&1); |
| 30656 | 30648 | } |
| 30657 | 30649 | |
| 30658 | 30650 | /* skip leading spaces */ |
| | @@ -30666,39 +30658,43 @@ |
| 30666 | 30658 | }else if( *z=='+' ){ |
| 30667 | 30659 | z+=incr; |
| 30668 | 30660 | } |
| 30669 | 30661 | |
| 30670 | 30662 | /* copy max significant digits to significand */ |
| 30671 | | - while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){ |
| 30663 | + while( z<zEnd && sqlite3Isdigit(*z) ){ |
| 30672 | 30664 | s = s*10 + (*z - '0'); |
| 30673 | | - z+=incr; nDigits++; |
| 30665 | + z+=incr; nDigit++; |
| 30666 | + if( s>=((LARGEST_INT64-9)/10) ){ |
| 30667 | + /* skip non-significant significand digits |
| 30668 | + ** (increase exponent by d to shift decimal left) */ |
| 30669 | + while( z<zEnd && sqlite3Isdigit(*z) ){ z+=incr; d++; } |
| 30670 | + } |
| 30674 | 30671 | } |
| 30675 | | - |
| 30676 | | - /* skip non-significant significand digits |
| 30677 | | - ** (increase exponent by d to shift decimal left) */ |
| 30678 | | - while( z<zEnd && sqlite3Isdigit(*z) ){ z+=incr; nDigits++; d++; } |
| 30679 | 30672 | if( z>=zEnd ) goto do_atof_calc; |
| 30680 | 30673 | |
| 30681 | 30674 | /* if decimal point is present */ |
| 30682 | 30675 | if( *z=='.' ){ |
| 30683 | 30676 | z+=incr; |
| 30677 | + eType++; |
| 30684 | 30678 | /* copy digits from after decimal to significand |
| 30685 | 30679 | ** (decrease exponent by d to shift decimal right) */ |
| 30686 | 30680 | while( z<zEnd && sqlite3Isdigit(*z) ){ |
| 30687 | 30681 | if( s<((LARGEST_INT64-9)/10) ){ |
| 30688 | 30682 | s = s*10 + (*z - '0'); |
| 30689 | 30683 | d--; |
| 30684 | + nDigit++; |
| 30690 | 30685 | } |
| 30691 | | - z+=incr; nDigits++; |
| 30686 | + z+=incr; |
| 30692 | 30687 | } |
| 30693 | 30688 | } |
| 30694 | 30689 | if( z>=zEnd ) goto do_atof_calc; |
| 30695 | 30690 | |
| 30696 | 30691 | /* if exponent is present */ |
| 30697 | 30692 | if( *z=='e' || *z=='E' ){ |
| 30698 | 30693 | z+=incr; |
| 30699 | 30694 | eValid = 0; |
| 30695 | + eType++; |
| 30700 | 30696 | |
| 30701 | 30697 | /* This branch is needed to avoid a (harmless) buffer overread. The |
| 30702 | 30698 | ** special comment alerts the mutation tester that the correct answer |
| 30703 | 30699 | ** is obtained even if the branch is omitted */ |
| 30704 | 30700 | if( z>=zEnd ) goto do_atof_calc; /*PREVENTS-HARMLESS-OVERREAD*/ |
| | @@ -30793,11 +30789,11 @@ |
| 30793 | 30789 | |
| 30794 | 30790 | /* store the result */ |
| 30795 | 30791 | *pResult = result; |
| 30796 | 30792 | |
| 30797 | 30793 | /* return true if number and no extra non-whitespace chracters after */ |
| 30798 | | - return z==zEnd && nDigits>0 && eValid && nonNum==0; |
| 30794 | + return z==zEnd && nDigit>0 && eValid && eType>0 ? eType : 0; |
| 30799 | 30795 | #else |
| 30800 | 30796 | return !sqlite3Atoi64(z, pResult, length, enc); |
| 30801 | 30797 | #endif /* SQLITE_OMIT_FLOATING_POINT */ |
| 30802 | 30798 | } |
| 30803 | 30799 | |
| | @@ -75146,11 +75142,11 @@ |
| 75146 | 75142 | ** |
| 75147 | 75143 | ** For some versions of GCC on 32-bit machines, if you do the more obvious |
| 75148 | 75144 | ** comparison of "r1==(double)i" you sometimes get an answer of false even |
| 75149 | 75145 | ** though the r1 and (double)i values are bit-for-bit the same. |
| 75150 | 75146 | */ |
| 75151 | | -static int sqlite3RealSameAsInt(double r1, sqlite3_int64 i){ |
| 75147 | +SQLITE_PRIVATE int sqlite3RealSameAsInt(double r1, sqlite3_int64 i){ |
| 75152 | 75148 | double r2 = (double)i; |
| 75153 | 75149 | return memcmp(&r1, &r2, sizeof(r1))==0; |
| 75154 | 75150 | } |
| 75155 | 75151 | |
| 75156 | 75152 | /* |
| | @@ -80035,11 +80031,11 @@ |
| 80035 | 80031 | ** This function is implemented as two separate routines for performance. |
| 80036 | 80032 | ** The few cases that require local variables are broken out into a separate |
| 80037 | 80033 | ** routine so that in most cases the overhead of moving the stack pointer |
| 80038 | 80034 | ** is avoided. |
| 80039 | 80035 | */ |
| 80040 | | -static u32 SQLITE_NOINLINE serialGet( |
| 80036 | +static u32 serialGet( |
| 80041 | 80037 | const unsigned char *buf, /* Buffer to deserialize from */ |
| 80042 | 80038 | u32 serial_type, /* Serial type to deserialize */ |
| 80043 | 80039 | Mem *pMem /* Memory cell to write value into */ |
| 80044 | 80040 | ){ |
| 80045 | 80041 | u64 x = FOUR_BYTE_UINT(buf); |
| | @@ -80067,11 +80063,11 @@ |
| 80067 | 80063 | assert( sizeof(r1)==sizeof(t2) && memcmp(&r1, &t2, sizeof(r1))==0 ); |
| 80068 | 80064 | #endif |
| 80069 | 80065 | assert( sizeof(x)==8 && sizeof(pMem->u.r)==8 ); |
| 80070 | 80066 | swapMixedEndianFloat(x); |
| 80071 | 80067 | memcpy(&pMem->u.r, &x, sizeof(x)); |
| 80072 | | - pMem->flags = sqlite3IsNaN(pMem->u.r) ? MEM_Null : MEM_Real; |
| 80068 | + pMem->flags = IsNaN(x) ? MEM_Null : MEM_Real; |
| 80073 | 80069 | } |
| 80074 | 80070 | return 8; |
| 80075 | 80071 | } |
| 80076 | 80072 | SQLITE_PRIVATE u32 sqlite3VdbeSerialGet( |
| 80077 | 80073 | const unsigned char *buf, /* Buffer to deserialize from */ |
| | @@ -83930,10 +83926,34 @@ |
| 83930 | 83926 | sqlite3BtreeCursorZero(pCx->uc.pCursor); |
| 83931 | 83927 | } |
| 83932 | 83928 | } |
| 83933 | 83929 | return pCx; |
| 83934 | 83930 | } |
| 83931 | + |
| 83932 | +/* |
| 83933 | +** The string in pRec is known to look like an integer and to have a |
| 83934 | +** floating point value of rValue. Return true and set *piValue to the |
| 83935 | +** integer value if the string is in range to be an integer. Otherwise, |
| 83936 | +** return false. |
| 83937 | +*/ |
| 83938 | +static int alsoAnInt(Mem *pRec, double rValue, i64 *piValue){ |
| 83939 | + i64 iValue = (double)rValue; |
| 83940 | + if( sqlite3RealSameAsInt(rValue,iValue) ){ |
| 83941 | + testcase( iValue<-2251799813685248 ); |
| 83942 | + testcase( iValue==-2251799813685248 ); |
| 83943 | + testcase( iValue==-2251799813685247 ); |
| 83944 | + testcase( iValue>-2251799813685247 && iValue<+2251799813685247 ); |
| 83945 | + testcase( iValue==+2251799813685247 ); |
| 83946 | + testcase( iValue==+2251799813685248 ); |
| 83947 | + testcase( iValue>+2251799813685248 ); |
| 83948 | + if( iValue > -2251799813685248 && iValue < 2251799813685248 ){ |
| 83949 | + *piValue = iValue; |
| 83950 | + return 1; |
| 83951 | + } |
| 83952 | + } |
| 83953 | + return 0==sqlite3Atoi64(pRec->z, piValue, pRec->n, pRec->enc); |
| 83954 | +} |
| 83935 | 83955 | |
| 83936 | 83956 | /* |
| 83937 | 83957 | ** Try to convert a value into a numeric representation if we can |
| 83938 | 83958 | ** do so without loss of information. In other words, if the string |
| 83939 | 83959 | ** looks like a number, convert it into a number. If it does not |
| | @@ -83948,16 +83968,16 @@ |
| 83948 | 83968 | ** point or exponential notation, the result is only MEM_Real, even |
| 83949 | 83969 | ** if there is an exact integer representation of the quantity. |
| 83950 | 83970 | */ |
| 83951 | 83971 | static void applyNumericAffinity(Mem *pRec, int bTryForInt){ |
| 83952 | 83972 | double rValue; |
| 83953 | | - i64 iValue; |
| 83954 | 83973 | u8 enc = pRec->enc; |
| 83974 | + int rc; |
| 83955 | 83975 | assert( (pRec->flags & (MEM_Str|MEM_Int|MEM_Real|MEM_IntReal))==MEM_Str ); |
| 83956 | | - if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return; |
| 83957 | | - if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){ |
| 83958 | | - pRec->u.i = iValue; |
| 83976 | + rc = sqlite3AtoF(pRec->z, &rValue, pRec->n, enc); |
| 83977 | + if( rc==0 ) return; |
| 83978 | + if( rc==1 && alsoAnInt(pRec, rValue, &pRec->u.i) ){ |
| 83959 | 83979 | pRec->flags |= MEM_Int; |
| 83960 | 83980 | }else{ |
| 83961 | 83981 | pRec->u.r = rValue; |
| 83962 | 83982 | pRec->flags |= MEM_Real; |
| 83963 | 83983 | if( bTryForInt ) sqlite3VdbeIntegerAffinity(pRec); |
| | @@ -113767,14 +113787,14 @@ |
| 113767 | 113787 | r = sqlite3_value_double(argv[0]); |
| 113768 | 113788 | /* If Y==0 and X will fit in a 64-bit int, |
| 113769 | 113789 | ** handle the rounding directly, |
| 113770 | 113790 | ** otherwise use printf. |
| 113771 | 113791 | */ |
| 113772 | | - if( n==0 && r>=0 && r<LARGEST_INT64-1 ){ |
| 113773 | | - r = (double)((sqlite_int64)(r+0.5)); |
| 113774 | | - }else if( n==0 && r<0 && (-r)<LARGEST_INT64-1 ){ |
| 113775 | | - r = -(double)((sqlite_int64)((-r)+0.5)); |
| 113792 | + if( r<-4503599627370496.0 || r>+4503599627370496.0 ){ |
| 113793 | + /* The value has no fractional part so there is nothing to round */ |
| 113794 | + }else if( n==0 ){ |
| 113795 | + r = (double)((sqlite_int64)(r+(r<0?-0.5:+0.5))); |
| 113776 | 113796 | }else{ |
| 113777 | 113797 | zBuf = sqlite3_mprintf("%.*f",n,r); |
| 113778 | 113798 | if( zBuf==0 ){ |
| 113779 | 113799 | sqlite3_result_error_nomem(context); |
| 113780 | 113800 | return; |
| | @@ -127556,10 +127576,11 @@ |
| 127556 | 127576 | /* Make sure there is no ORDER BY or LIMIT clause on prior SELECTs. Only |
| 127557 | 127577 | ** the last (right-most) SELECT in the series may have an ORDER BY or LIMIT. |
| 127558 | 127578 | */ |
| 127559 | 127579 | assert( p && p->pPrior ); /* Calling function guarantees this much */ |
| 127560 | 127580 | assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION ); |
| 127581 | + assert( p->selFlags & SF_Compound ); |
| 127561 | 127582 | db = pParse->db; |
| 127562 | 127583 | pPrior = p->pPrior; |
| 127563 | 127584 | dest = *pDest; |
| 127564 | 127585 | if( pPrior->pOrderBy || pPrior->pLimit ){ |
| 127565 | 127586 | sqlite3ErrorMsg(pParse,"%s clause should come after %s not before", |
| | @@ -129061,14 +129082,14 @@ |
| 129061 | 129082 | x.isLeftJoin = isLeftJoin; |
| 129062 | 129083 | x.pEList = pSub->pEList; |
| 129063 | 129084 | substSelect(&x, pParent, 0); |
| 129064 | 129085 | } |
| 129065 | 129086 | |
| 129066 | | - /* The flattened query is distinct if either the inner or the |
| 129067 | | - ** outer query is distinct. |
| 129068 | | - */ |
| 129069 | | - pParent->selFlags |= pSub->selFlags & SF_Distinct; |
| 129087 | + /* The flattened query is a compound if either the inner or the |
| 129088 | + ** outer query is a compound. */ |
| 129089 | + pParent->selFlags |= pSub->selFlags & SF_Compound; |
| 129090 | + assert( (pSub->selFlags & SF_Distinct)==0 ); /* restriction (17b) */ |
| 129070 | 129091 | |
| 129071 | 129092 | /* |
| 129072 | 129093 | ** SELECT ... FROM (SELECT ... LIMIT a OFFSET b) LIMIT x OFFSET y; |
| 129073 | 129094 | ** |
| 129074 | 129095 | ** One is tempted to try to add a and b to combine the limits. But this |
| | @@ -174772,11 +174793,11 @@ |
| 174772 | 174793 | int nSuffix; /* Size of term suffix in bytes */ |
| 174773 | 174794 | |
| 174774 | 174795 | /* Node must have already been started. There must be a doclist for a |
| 174775 | 174796 | ** leaf node, and there must not be a doclist for an internal node. */ |
| 174776 | 174797 | assert( pNode->n>0 ); |
| 174777 | | - assert( (pNode->a[0]=='\0')==(aDoclist!=0) ); |
| 174798 | + assert_fts3_nc( (pNode->a[0]=='\0')==(aDoclist!=0) ); |
| 174778 | 174799 | |
| 174779 | 174800 | blobGrowBuffer(pPrev, nTerm, &rc); |
| 174780 | 174801 | if( rc!=SQLITE_OK ) return rc; |
| 174781 | 174802 | |
| 174782 | 174803 | nPrefix = fts3PrefixCompress(pPrev->a, pPrev->n, zTerm, nTerm); |
| | @@ -174988,11 +175009,11 @@ |
| 174988 | 175009 | const char *zRhs, int nRhs /* RHS of comparison */ |
| 174989 | 175010 | ){ |
| 174990 | 175011 | int nCmp = MIN(nLhs, nRhs); |
| 174991 | 175012 | int res; |
| 174992 | 175013 | |
| 174993 | | - res = memcmp(zLhs, zRhs, nCmp); |
| 175014 | + res = (nCmp ? memcmp(zLhs, zRhs, nCmp) : 0); |
| 174994 | 175015 | if( res==0 ) res = nLhs - nRhs; |
| 174995 | 175016 | |
| 174996 | 175017 | return res; |
| 174997 | 175018 | } |
| 174998 | 175019 | |
| | @@ -175131,27 +175152,29 @@ |
| 175131 | 175152 | for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){ |
| 175132 | 175153 | NodeReader reader; |
| 175133 | 175154 | pNode = &pWriter->aNodeWriter[i]; |
| 175134 | 175155 | |
| 175135 | 175156 | rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n); |
| 175136 | | - while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader); |
| 175137 | | - blobGrowBuffer(&pNode->key, reader.term.n, &rc); |
| 175138 | | - if( rc==SQLITE_OK ){ |
| 175139 | | - memcpy(pNode->key.a, reader.term.a, reader.term.n); |
| 175140 | | - pNode->key.n = reader.term.n; |
| 175141 | | - if( i>0 ){ |
| 175142 | | - char *aBlock = 0; |
| 175143 | | - int nBlock = 0; |
| 175144 | | - pNode = &pWriter->aNodeWriter[i-1]; |
| 175145 | | - pNode->iBlock = reader.iChild; |
| 175146 | | - rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock, 0); |
| 175147 | | - blobGrowBuffer(&pNode->block, MAX(nBlock, p->nNodeSize), &rc); |
| 175148 | | - if( rc==SQLITE_OK ){ |
| 175149 | | - memcpy(pNode->block.a, aBlock, nBlock); |
| 175150 | | - pNode->block.n = nBlock; |
| 175151 | | - } |
| 175152 | | - sqlite3_free(aBlock); |
| 175157 | + if( reader.aNode ){ |
| 175158 | + while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader); |
| 175159 | + blobGrowBuffer(&pNode->key, reader.term.n, &rc); |
| 175160 | + if( rc==SQLITE_OK ){ |
| 175161 | + memcpy(pNode->key.a, reader.term.a, reader.term.n); |
| 175162 | + pNode->key.n = reader.term.n; |
| 175163 | + if( i>0 ){ |
| 175164 | + char *aBlock = 0; |
| 175165 | + int nBlock = 0; |
| 175166 | + pNode = &pWriter->aNodeWriter[i-1]; |
| 175167 | + pNode->iBlock = reader.iChild; |
| 175168 | + rc = sqlite3Fts3ReadBlock(p, reader.iChild, &aBlock, &nBlock, 0); |
| 175169 | + blobGrowBuffer(&pNode->block, MAX(nBlock, p->nNodeSize), &rc); |
| 175170 | + if( rc==SQLITE_OK ){ |
| 175171 | + memcpy(pNode->block.a, aBlock, nBlock); |
| 175172 | + pNode->block.n = nBlock; |
| 175173 | + } |
| 175174 | + sqlite3_free(aBlock); |
| 175175 | + } |
| 175153 | 175176 | } |
| 175154 | 175177 | } |
| 175155 | 175178 | nodeReaderRelease(&reader); |
| 175156 | 175179 | } |
| 175157 | 175180 | } |
| | @@ -175390,11 +175413,14 @@ |
| 175390 | 175413 | sqlite3_int64 *piBlock /* OUT: Block number in next layer down */ |
| 175391 | 175414 | ){ |
| 175392 | 175415 | NodeReader reader; /* Reader object */ |
| 175393 | 175416 | Blob prev = {0, 0, 0}; /* Previous term written to new node */ |
| 175394 | 175417 | int rc = SQLITE_OK; /* Return code */ |
| 175395 | | - int bLeaf = aNode[0]=='\0'; /* True for a leaf node */ |
| 175418 | + int bLeaf; /* True for a leaf node */ |
| 175419 | + |
| 175420 | + if( nNode<1 ) return FTS_CORRUPT_VTAB; |
| 175421 | + bLeaf = aNode[0]=='\0'; |
| 175396 | 175422 | |
| 175397 | 175423 | /* Allocate required output space */ |
| 175398 | 175424 | blobGrowBuffer(pNew, nNode, &rc); |
| 175399 | 175425 | if( rc!=SQLITE_OK ) return rc; |
| 175400 | 175426 | pNew->n = 0; |
| | @@ -210593,11 +210619,11 @@ |
| 210593 | 210619 | pData = fts5DataRead(p, FTS5_STRUCTURE_ROWID); |
| 210594 | 210620 | if( p->rc==SQLITE_OK ){ |
| 210595 | 210621 | /* TODO: Do we need this if the leaf-index is appended? Probably... */ |
| 210596 | 210622 | memset(&pData->p[pData->nn], 0, FTS5_DATA_PADDING); |
| 210597 | 210623 | p->rc = fts5StructureDecode(pData->p, pData->nn, &iCookie, &pRet); |
| 210598 | | - if( p->rc==SQLITE_OK && pConfig->iCookie!=iCookie ){ |
| 210624 | + if( p->rc==SQLITE_OK && (pConfig->pgsz==0 || pConfig->iCookie!=iCookie) ){ |
| 210599 | 210625 | p->rc = sqlite3Fts5ConfigLoad(pConfig, iCookie); |
| 210600 | 210626 | } |
| 210601 | 210627 | fts5DataRelease(pData); |
| 210602 | 210628 | if( p->rc!=SQLITE_OK ){ |
| 210603 | 210629 | fts5StructureRelease(pRet); |
| | @@ -218831,11 +218857,11 @@ |
| 218831 | 218857 | int nArg, /* Number of args */ |
| 218832 | 218858 | sqlite3_value **apUnused /* Function arguments */ |
| 218833 | 218859 | ){ |
| 218834 | 218860 | assert( nArg==0 ); |
| 218835 | 218861 | UNUSED_PARAM2(nArg, apUnused); |
| 218836 | | - sqlite3_result_text(pCtx, "fts5: 2019-05-23 16:38:12 d2fe370cafa9b11f6c3eb4e1c3be48d9d2610b9d2f9d9ebf9e50267f9079dfc0", -1, SQLITE_TRANSIENT); |
| 218862 | + sqlite3_result_text(pCtx, "fts5: 2019-06-04 18:21:59 4979f138e8c8bef7dd6b5921fb9ca9fea86bbf7ec1419934bb2d1a0d74e77183", -1, SQLITE_TRANSIENT); |
| 218837 | 218863 | } |
| 218838 | 218864 | |
| 218839 | 218865 | /* |
| 218840 | 218866 | ** Return true if zName is the extension on one of the shadow tables used |
| 218841 | 218867 | ** by this module. |
| | @@ -223597,12 +223623,12 @@ |
| 223597 | 223623 | } |
| 223598 | 223624 | #endif /* SQLITE_CORE */ |
| 223599 | 223625 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 223600 | 223626 | |
| 223601 | 223627 | /************** End of stmt.c ************************************************/ |
| 223602 | | -#if __LINE__!=223602 |
| 223628 | +#if __LINE__!=223628 |
| 223603 | 223629 | #undef SQLITE_SOURCE_ID |
| 223604 | | -#define SQLITE_SOURCE_ID "2019-05-23 16:38:12 d2fe370cafa9b11f6c3eb4e1c3be48d9d2610b9d2f9d9ebf9e50267f9079alt2" |
| 223630 | +#define SQLITE_SOURCE_ID "2019-06-05 14:29:53 7b3a99fce8b4a757f2b2ef2f0b02d68566f2528d9ae1e30628522717f872alt2" |
| 223605 | 223631 | #endif |
| 223606 | 223632 | /* Return the source-id for this library */ |
| 223607 | 223633 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 223608 | 223634 | /************************** End of sqlite3.c ******************************/ |
| 223609 | 223635 | |