Fix the instr() SQL function so that it makes a copy of its argument

before changing the datatype, since the datatype affects processing.
Also fix the sqlite3_value_text() routine so that it always works even
for values obtained form sqlite3_value_dup().  Ticket [587791f92620090e]

FossilOrigin-Name: 3fb40f518086c1e8d11eb1f4134e965450dbedfa4277bce39ef1e969fc747d38
This commit is contained in:
drh 2019-09-17 03:16:29 +00:00
parent 70738712de
commit 97b0250599
4 changed files with 31 additions and 11 deletions

View File

@ -1,5 +1,5 @@
C Improved\stype\sinformation\sdisplay\swhen\stracing\sVDBE\sexecution.
D 2019-09-16T20:16:17.051
C Fix\sthe\sinstr()\sSQL\sfunction\sso\sthat\sit\smakes\sa\scopy\sof\sits\sargument\nbefore\schanging\sthe\sdatatype,\ssince\sthe\sdatatype\saffects\sprocessing.\nAlso\sfix\sthe\ssqlite3_value_text()\sroutine\sso\sthat\sit\salways\sworks\seven\nfor\svalues\sobtained\sform\ssqlite3_value_dup().\s\sTicket\s[587791f92620090e]
D 2019-09-17T03:16:29.557
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -480,7 +480,7 @@ F src/delete.c d08c9e01a2664afd12edcfa3a9c6578517e8ff8735f35509582693adbe0edeaf
F src/expr.c 10d90c4676047a75276446779d18fb3f7d3a1f9debc8b322e3772d2bd51f52ff
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c 6b79f4c2447691aa9ac86e2a6a774b65f3b3dd053d4220a4893051a0de20f82e
F src/func.c 4ee36219698d50d672a28eca4adb0fd6b92e607a1883d318315e0d2fd5044467
F src/func.c 6960ca6a27460a699326b95484cb7be4d4ab14869a13a356b98e6b379b4f02ed
F src/global.c d7a7a45a78ffe01302d61c271ed50474ef1b9d2d23bf17a46a58c8a1926424ee
F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19
F src/hash.h 9d56a9079d523b648774c1784b74b89bd93fac7b365210157482e4319a468f38
@ -603,7 +603,7 @@ F src/vdbeInt.h e95de5129124d77f01439e6635012adfaf23c0017bff47296126143cf18bd0c6
F src/vdbeapi.c 95001d0f84ee3cda344fed98ca0d7961deb4fc836b83495630d0af1f7cc4789e
F src/vdbeaux.c 7ccf418141df1c7f87b0d69510523ae522abbe47c769d1b2c15120e88fac3eb9
F src/vdbeblob.c 253ed82894924c362a7fa3079551d3554cd1cdace39aa833da77d3bc67e7c1b1
F src/vdbemem.c 920285c3b7f5c64369e02da437dab71e9e91862df9c486541c14633739f91d75
F src/vdbemem.c d8e10d1773806105e62094c4ede0a4684f46caaf07667a45e6d461e94306b530
F src/vdbesort.c da75f505aba230060ce6472605a4aa6494f73eeb1071e1cc2643c3d4035e671b
F src/vdbetrace.c fa3bf238002f0bbbdfb66cc8afb0cea284ff9f148d6439bc1f6f2b4c3b7143f0
F src/vtab.c 5a0b7193d586991b3db30e343d6b59959906bfe8658a6a0a85709b20ca50bb49
@ -1843,7 +1843,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 6fe0367f9a337b7c62886b7771f3ce0642faa13f4e4f3d9a0c848abbab514cd0
R 2c164431f0af1c58cdf456d5668495e4
P ee83d8e30d6f9ca8f1cce653ee094ff151f633f4b6a21dd814ab07e8cfb901eb
R 6e3381f871ce2b10dafa18243e3574b7
U drh
Z bdf482d3367e54574324bb6a241ccba0
Z 4f1601976647ddb4980916cd3d87db80

View File

@ -1 +1 @@
ee83d8e30d6f9ca8f1cce653ee094ff151f633f4b6a21dd814ab07e8cfb901eb
3fb40f518086c1e8d11eb1f4134e965450dbedfa4277bce39ef1e969fc747d38

View File

@ -203,6 +203,8 @@ static void instrFunc(
int N = 1;
int isText;
unsigned char firstChar;
sqlite3_value *pC1 = 0;
sqlite3_value *pC2 = 0;
UNUSED_PARAMETER(argc);
typeHaystack = sqlite3_value_type(argv[0]);
@ -215,12 +217,21 @@ static void instrFunc(
zHaystack = sqlite3_value_blob(argv[0]);
zNeedle = sqlite3_value_blob(argv[1]);
isText = 0;
}else{
}else if( typeHaystack!=SQLITE_BLOB && typeNeedle!=SQLITE_BLOB ){
zHaystack = sqlite3_value_text(argv[0]);
zNeedle = sqlite3_value_text(argv[1]);
isText = 1;
}else{
pC1 = sqlite3_value_dup(argv[0]);
zHaystack = sqlite3_value_text(pC1);
pC2 = sqlite3_value_dup(argv[1]);
zNeedle = sqlite3_value_text(pC2);
isText = 1;
}
if( zNeedle==0 || (nHaystack && zHaystack==0) ){
sqlite3_result_error_nomem(context);
goto endInstr;
}
if( zNeedle==0 || (nHaystack && zHaystack==0) ) return;
firstChar = zNeedle[0];
while( nNeedle<=nHaystack
&& (zHaystack[0]!=firstChar || memcmp(zHaystack, zNeedle, nNeedle)!=0)
@ -234,6 +245,9 @@ static void instrFunc(
if( nNeedle>nHaystack ) N = 0;
}
sqlite3_result_int(context, N);
endInstr:
sqlite3_value_free(pC1);
sqlite3_value_free(pC2);
}
/*

View File

@ -232,7 +232,13 @@ SQLITE_NOINLINE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
assert( pMem->szMalloc==0
|| pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
if( pMem->db ){
pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
}else{
pMem->zMalloc = sqlite3Realloc(pMem->z, n);
if( pMem->zMalloc==0 ) sqlite3_free(pMem->z);
pMem->z = pMem->zMalloc;
}
bPreserve = 0;
}else{
if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);