From: drh <> Date: Thu, 5 Jan 2023 13:41:11 +0000 (+0000) Subject: Fix a problem with applying integer affinity to a MEM_IntReal value. [forum:/forumpos... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c2e40ba4011230387b97f750932db53e58c3aa93;p=thirdparty%2Fsqlite.git Fix a problem with applying integer affinity to a MEM_IntReal value. [forum:/forumpost/d270125fae|Forum post d270125fae]. FossilOrigin-Name: d28d9398a55e0071789087d36ec147ecb207681651a83a0e2da71bc25d689012 --- diff --git a/manifest b/manifest index 1abe1101ac..804e8ec4c7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Increase\sthe\sversion\snumber\sto\s3.40.2. -D 2023-01-05T01:32:39.445 +C Fix\sa\sproblem\swith\sapplying\sinteger\saffinity\sto\sa\sMEM_IntReal\svalue.\s[forum:/forumpost/d270125fae|Forum\spost\sd270125fae]. +D 2023-01-05T13:41:11.566 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -709,13 +709,13 @@ F src/upsert.c 5303dc6c518fa7d4b280ec65170f465c7a70b7ac2b22491598f6d0b4875b3145 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0 F src/util.c 0be191521ff6d2805995f4910f0b6231b42843678b2efdc1abecaf39929a673f F src/vacuum.c 84ce7f01f8a7a08748e107a441db83bcec13970190ddcb0c9ff522adbc1c23fd -F src/vdbe.c 0c7cb1b934ad8611e14e7efaf2c3a95df7dd3f7964d63ea07fef42a23df86131 +F src/vdbe.c cc5a30359a73a26f89443da27fe291fc58332914dcd7be1c438a4f78255a595b F src/vdbe.h 58675f47dcf3105bab182c3ad3726efd60ffd003e954386904ac9107d0d2b743 F src/vdbeInt.h 17b7461ffcf9ee760d1341731715a419f6b8c763089a7ece25c2e8098d702b3f F src/vdbeapi.c 1e8713d0b653acb43cd1bdf579c40e005c4844ea90f414f065946a83db3c27fb F src/vdbeaux.c 8ebe337e82d99cf3b01cd4fd67103a5b0054d53fee8456b90dbeba46ebf97ceb F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd -F src/vdbemem.c 6cfed43758d57b6e3b99d9cdedfeccd86e45a07e427b22d8487cbdbebb6c522a +F src/vdbemem.c 3386a47198bed3a4227928aef087995206ba135c2589ca63a2e29a3248df43b3 F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c f99b275366c5fc5e2d99f734729880994ab9500bdafde7fae3b02d562b9d323c @@ -1221,7 +1221,7 @@ F test/intarray.test bb976b0b3df0ebb6a2eddfb61768280440e672beba5460ed49679ea984c F test/interrupt.test 16ea879ec728cb76414c148c5f24afd5d1f91054 F test/interrupt2.test e4408ca770a6feafbadb0801e54a0dcd1a8d108d F test/intpkey.test aee694afed1a65c86c4e69ad030224b3fc268113d00685234d40079fca16bad3 -F test/intreal.test 2a87e85a5949bd55e41ef04c58f5800587c5380bdbc559ff1c79b614b0e6a533 +F test/intreal.test 68829a8bb073ee1610ca3f8f9e0f99b0371fb36e0fa64862dd5ced4ef03c2343 F test/io.test f138f3fe696d1ed8c51dfea5b325910d319a1b29e1d25ea57231a02092f02cca F test/ioerr.test 530d05801ff1b6327018b2e140da34a74effa2773a844ddb8dc79c32e9567318 F test/ioerr2.test 2593563599e2cc6b6b4fcf5878b177bdd5d8df26 @@ -2055,8 +2055,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e4de5777578d27aede463c1e2c2437249e3ab7194401266473587572e0f203a5 -R eef2811bd6c2d76c6fa70f3c76bf77ca +P 43375ef8a796d1fba9d43e052420cb744853917f978d2db4688d3ea2704b0461 +Q +e58bba93717cd6ff950c6f9e077b4327b59b1956dd5f6668be3de9509584b8fe +R b29c1f4ac26897dfd31b12e6cc3ab88f U drh -Z 9b2f5b7ae2cc2d180997d8d81388feee +Z 1899d75b1af3e16ce12c027a48237238 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2ce96415a3..9f7458413b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -43375ef8a796d1fba9d43e052420cb744853917f978d2db4688d3ea2704b0461 \ No newline at end of file +d28d9398a55e0071789087d36ec147ecb207681651a83a0e2da71bc25d689012 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 4eb1c03271..bc57b6eba0 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -387,7 +387,7 @@ static void applyAffinity( assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL || affinity==SQLITE_AFF_NUMERIC ); if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/ - if( (pRec->flags & MEM_Real)==0 ){ + if( (pRec->flags & (MEM_Real|MEM_IntReal))==0 ){ if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1); }else{ sqlite3VdbeIntegerAffinity(pRec); diff --git a/src/vdbemem.c b/src/vdbemem.c index f14599def6..93d1861376 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -676,32 +676,35 @@ int sqlite3VdbeBooleanValue(Mem *pMem, int ifNull){ } /* -** The MEM structure is already a MEM_Real. Try to also make it a -** MEM_Int if we can. +** The MEM structure is already a MEM_Real or MEM_IntReal. Try to +** make it a MEM_Int if we can. */ void sqlite3VdbeIntegerAffinity(Mem *pMem){ - i64 ix; assert( pMem!=0 ); - assert( pMem->flags & MEM_Real ); + assert( pMem->flags & (MEM_Real|MEM_IntReal) ); assert( !sqlite3VdbeMemIsRowSet(pMem) ); assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); assert( EIGHT_BYTE_ALIGNMENT(pMem) ); - ix = doubleToInt64(pMem->u.r); - - /* Only mark the value as an integer if - ** - ** (1) the round-trip conversion real->int->real is a no-op, and - ** (2) The integer is neither the largest nor the smallest - ** possible integer (ticket #3922) - ** - ** The second and third terms in the following conditional enforces - ** the second condition under the assumption that addition overflow causes - ** values to wrap around. - */ - if( pMem->u.r==ix && ix>SMALLEST_INT64 && ixu.i = ix; + if( pMem->flags & MEM_IntReal ){ MemSetTypeFlag(pMem, MEM_Int); + }else{ + i64 ix = doubleToInt64(pMem->u.r); + + /* Only mark the value as an integer if + ** + ** (1) the round-trip conversion real->int->real is a no-op, and + ** (2) The integer is neither the largest nor the smallest + ** possible integer (ticket #3922) + ** + ** The second and third terms in the following conditional enforces + ** the second condition under the assumption that addition overflow causes + ** values to wrap around. + */ + if( pMem->u.r==ix && ix>SMALLEST_INT64 && ixu.i = ix; + MemSetTypeFlag(pMem, MEM_Int); + } } } diff --git a/test/intreal.test b/test/intreal.test index 1a3db0a234..d9ffe9909e 100644 --- a/test/intreal.test +++ b/test/intreal.test @@ -95,4 +95,22 @@ do_execsql_test 3.0 { PRAGMA integrity_check; } {a {} ok} + +reset_db +do_execsql_test 4.0 { + CREATE TABLE t1(a REAL, b AS ('expr') ); +} +do_execsql_test 4.1 { + INSERT INTO t1 VALUES( REPLACE(0, '', 'expr') ); +} +do_execsql_test 4.2 { + INSERT INTO t1 SELECT REPLACE(4, '', 'expr'); +} +do_execsql_test 4.3 { + SELECT typeof(a), a FROM t1; +} { + real 0.0 + real 4.0 +} + finish_test