From: stephan Date: Wed, 2 Jul 2025 13:24:50 +0000 (+0000) Subject: Per /chat and forum discussions: (A) Remove the value type output pointer from text... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a90c87269223f57fbbbfdb00ba1a96b5e88baa34;p=thirdparty%2Fsqlite.git Per /chat and forum discussions: (A) Remove the value type output pointer from text/blob_v2(). (B) Teach blob_v2() to return an opaque non-NULL pointer for length-0 blobs. FossilOrigin-Name: c96539beb5ca3c6a467e5388b942767765a3f071e009c1767d3b4f1b0fb5da9c --- diff --git a/ext/wasm/api/sqlite3-api-glue.c-pp.js b/ext/wasm/api/sqlite3-api-glue.c-pp.js index 8caf4066c0..da600a96a1 100644 --- a/ext/wasm/api/sqlite3-api-glue.c-pp.js +++ b/ext/wasm/api/sqlite3-api-glue.c-pp.js @@ -113,7 +113,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ["sqlite3_clear_bindings","int", "sqlite3_stmt*"], ["sqlite3_collation_needed", "int", "sqlite3*", "*", "*"/*=>v(ppis)*/], ["sqlite3_column_blob","*", "sqlite3_stmt*", "int"], - ["sqlite3_column_blob_v2", "int", "sqlite3_stmt*", "int", "**", "*", "*"], + ["sqlite3_column_blob_v2", "int", "sqlite3_stmt*", "int", "**", "*"], ["sqlite3_column_bytes","int", "sqlite3_stmt*", "int"], ["sqlite3_column_count", "int", "sqlite3_stmt*"], ["sqlite3_column_decltype", "string", "sqlite3_stmt*", "int"], @@ -121,7 +121,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ["sqlite3_column_int","int", "sqlite3_stmt*", "int"], ["sqlite3_column_name","string", "sqlite3_stmt*", "int"], ["sqlite3_column_text","string", "sqlite3_stmt*", "int"], - ["sqlite3_column_text_v2", "int", "sqlite3_stmt*", "int", "**", "*", "*"], + ["sqlite3_column_text_v2", "int", "sqlite3_stmt*", "int", "**", "*"], ["sqlite3_column_type","int", "sqlite3_stmt*", "int"], ["sqlite3_column_value","sqlite3_value*", "sqlite3_stmt*", "int"], ["sqlite3_commit_hook", "void*", [ @@ -307,7 +307,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ["sqlite3_uri_parameter", "string", "sqlite3_filename", "string"], ["sqlite3_user_data","void*", "sqlite3_context*"], ["sqlite3_value_blob", "*", "sqlite3_value*"], - ["sqlite3_value_blob_v2", "int", "sqlite3_value*", "**", "*", "*"], + ["sqlite3_value_blob_v2", "int", "sqlite3_value*", "**", "*"], ["sqlite3_value_bytes","int", "sqlite3_value*"], ["sqlite3_value_double","f64", "sqlite3_value*"], ["sqlite3_value_dup", "sqlite3_value*", "sqlite3_value*"], @@ -319,7 +319,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ["sqlite3_value_pointer", "*", "sqlite3_value*", "string:static"], ["sqlite3_value_subtype", "int", "sqlite3_value*"], ["sqlite3_value_text", "string", "sqlite3_value*"], - ["sqlite3_value_text_v2", "int", "sqlite3_value*", "**", "*", "*"], + ["sqlite3_value_text_v2", "int", "sqlite3_value*", "**", "*"], ["sqlite3_value_type", "int", "sqlite3_value*"], ["sqlite3_vfs_find", "*", "string"], ["sqlite3_vfs_register", "int", "sqlite3_vfs*", "int"], diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index 90e79931d4..f1e18c3d50 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -3352,20 +3352,20 @@ globalThis.sqlite3InitModule = sqlite3InitModule; try { let sv, rc; q = db.prepare("select a, b from t order by a"); - let [ppOut, pnOut, pType] = P.allocPtr(3); + let [ppOut, pnOut] = P.allocPtr(2); const clearPtrs = ()=>{ - wasm.pokePtr(ppOut, 0).poke32(pnOut, 0).poke32(pType, 0); + wasm.pokePtr(ppOut, 0).poke32(pnOut, 0); }; const next = ()=>{ T.assert( q.step() ); sv = capi.sqlite3_column_value(q, 1); T.assert( sv ); clearPtrs(); - rc = capi.sqlite3_value_text_v2(sv, ppOut, pnOut, pType); + rc = capi.sqlite3_value_text_v2(sv, ppOut, pnOut); T.assert( 0===rc ); return sv; }; - const cmp = function(type,expect){ + const cmp = function(expect){ const blob = wasm.peekPtr(ppOut); const len = wasm.peek32(pnOut); //log("blob=",wasm.cstrToJs(blob)); @@ -3381,20 +3381,20 @@ globalThis.sqlite3InitModule = sqlite3InitModule; .assert( str===expect, "String mismatch: got [" +str+"] expected ["+expect+"]"); }; - const cmp2 = (type,expect)=>{ + const cmp2 = (expect)=>{ next(); - cmp(type,expect); + cmp(expect); clearPtrs(); - const rc = capi.sqlite3_column_text_v2(q, 1, ppOut, pnOut, pType); + const rc = capi.sqlite3_column_text_v2(q, 1, ppOut, pnOut); T.assert( 0==rc, "expecting column_text_v2() rc 0 but got "+rc ); - cmp(type,expect); + cmp(expect); }; - cmp2(capi.SQLITE_INTEGER,'123'); - cmp2(capi.SQLITE_NULL,null); - cmp2(capi.SQLITE_TEXT,'hi world'); - cmp2(capi.SQLITE_BLOB, '#*'); - cmp2(capi.SQLITE_TEXT, ''); // empty strings are not null + cmp2('123'); + cmp2(null); + cmp2('hi world'); + cmp2('#*'); + cmp2(''); // empty strings are not null const checkRc = (name, descr, rc)=>{ T.assert( capi[name] === rc, @@ -3408,25 +3408,22 @@ globalThis.sqlite3InitModule = sqlite3InitModule; // This does not set a persistent error flag on q: checkRc('SQLITE_RANGE', "column_text_v2() bad index", - capi.sqlite3_column_text_v2(q, 11, ppOut, pnOut, 0) ); + capi.sqlite3_column_text_v2(q, 11, ppOut, pnOut) ); checkRc('SQLITE_OK', "column_text_v2() valid index", - capi.sqlite3_column_text_v2(q, 1, ppOut, 0, 0)); + capi.sqlite3_column_text_v2(q, 1, ppOut, 0)); checkRc('SQLITE_OK', "column null pnOut", - capi.sqlite3_column_text_v2(q, 1, ppOut, 0, 0)); + capi.sqlite3_column_text_v2(q, 1, ppOut, 0)); /* The MISUSE returns only apply because we build with SQLITE_ENABLE_API_ARMOR. Without API_ARMOR, these result in null pointer dereferences. */ checkRc('SQLITE_MISUSE', "value null ppOut", - capi.sqlite3_value_text_v2(sv, 0, pnOut, 0)); + capi.sqlite3_value_text_v2(sv, 0, pnOut)); checkRc('SQLITE_MISUSE', "value null arg0", - capi.sqlite3_value_text_v2(0, ppOut, pnOut, 0)); + capi.sqlite3_value_text_v2(0, ppOut, pnOut)); checkRc('SQLITE_MISUSE', "column null ppOut", - capi.sqlite3_column_text_v2(q, 1, 0, pnOut, 0)); - /* But a 0 pnOut is always okay. */ - checkRc('SQLITE_OK', "value null pnOut", - capi.sqlite3_value_text_v2(sv, ppOut, 0, 0)); + capi.sqlite3_column_text_v2(q, 1, 0, pnOut)); }finally{ if( q ) q.finalize(); @@ -3446,52 +3443,50 @@ globalThis.sqlite3InitModule = sqlite3InitModule; try { let sv, rc; q = db.prepare("select a, b from t order by a"); - let [ppOut, pnOut, pType] = P.allocPtr(3); + let [ppOut, pnOut] = P.allocPtr(2); const clearPtrs = ()=>{ - wasm.pokePtr(ppOut, 0).poke32(pnOut, 0).poke32(pType, 0); + wasm.pokePtr(ppOut, 0).poke32(pnOut, 0); }; const next = ()=>{ + ++next.n; T.assert( q.step() ); sv = capi.sqlite3_column_value(q, 1); T.assert( sv ); clearPtrs(); - rc = capi.sqlite3_value_blob_v2(sv, ppOut, pnOut, pType); + T.assert( !wasm.peekPtr(ppOut) ); + rc = capi.sqlite3_value_blob_v2(sv, ppOut, pnOut); T.assert( 0==rc, "expecting value_blob_v2() rc 0 but got "+rc ); return sv; }; - const cmp = (type,byteList)=>{ + next.n = 0; + const cmp = (byteList)=>{ const blob = wasm.peekPtr(ppOut); const len = wasm.peek32(pnOut); - //log("blob=",wasm.cstrToJs(blob)); - T.assert(len === byteList.length, "Lengths don't match") - T.assert( len ? !!blob : !blob, - "Expecting len=non-0/blob=non-null or len=0/blob=null. "+ - "Got len="+len+" blob=@"+blob ); - T.assert( type === wasm.peek32(pType), - "Expecting value_blob_v2 type "+type+" but got " - +wasm.peek32(pType)+". Value="+wasm.cstrToJs(blob)); + T.assert(len === byteList.length, "Lengths don't match: " + +len +" != " + byteList.length) for( let i = 0; i < len; ++i ){ T.assert( byteList[i] === wasm.peek8(blob+i), "mismatch at offset "+i+": "+byteList[i] +"!=="+wasm.peek8(blob+i) ); } }; - const cmp2 = (type,byteList)=>{ + const cmp2 = (byteList)=>{ next(); - cmp(type,byteList); + cmp(byteList); clearPtrs(); - const rc = capi.sqlite3_column_blob_v2(q, 1, ppOut, pnOut, pType); + const rc = capi.sqlite3_column_blob_v2(q, 1, ppOut, pnOut); T.assert( 0==rc, "expecting column_blob_v2() rc 0 but got "+rc); - cmp(type,byteList); + cmp(byteList); }; - cmp2(capi.SQLITE_INTEGER, [49,50,51]); // 123 - cmp2(capi.SQLITE_NULL, []); // null - cmp2(capi.SQLITE_TEXT, [104,105]); // "hi" - cmp2(capi.SQLITE_BLOB, [0x23, 0, 0x2a]); // X'23002A' - cmp2(capi.SQLITE_TEXT, []) /* length-0 non-NULL blobs are NULL - but this one has type TEXT */; + cmp2([49,50,51]); // 123 + cmp2([]); // null + T.assert( !wasm.peekPtr(ppOut), "Expecting NULL in row "+next.n); + cmp2([104,105]); // "hi" + cmp2([0x23, 0, 0x2a]); // X'23002A' + cmp2([]) /* length-0 blob */; + T.assert( wasm.peekPtr(ppOut), "Expecting non-NULL in row "+next.n); /** Tests which cover the same code paths for both text_v2 and blob_v2 are in the previous test group. */ diff --git a/manifest b/manifest index 67d5cd38b8..d946f373dd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\stest1.c\stcl\sbindings\sfor\ssqlite3_column_text/blob_v2().\sReplace,\sessentially\srandomly,\ssome\sof\sthe\sv1\sAPI\scalls\sin\scapi2.test\sand\scapi2.test\swith\sthe\sv2\scalls\sto\sensure\sidentical\sresults.\sAdd\sa\scouple\snew\stests\scomparing\sresults\sbetween\sv1\sand\sv2. -D 2025-07-02T07:52:30.801 +C Per\s/chat\sand\sforum\sdiscussions:\s(A)\sRemove\sthe\svalue\stype\soutput\spointer\sfrom\stext/blob_v2().\s(B)\sTeach\sblob_v2()\sto\sreturn\san\sopaque\snon-NULL\spointer\sfor\slength-0\sblobs. +D 2025-07-02T13:24:50.303 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -640,7 +640,7 @@ F ext/wasm/api/post-js-footer.js 365405929f41ca0e6d389ed8a8da3f3c93e11d3ef43a90a F ext/wasm/api/post-js-header.js 53740d824e5d9027eb1e6fd59e216abbd2136740ce260ea5f0699ff2acb0a701 F ext/wasm/api/pre-js.c-pp.js a614a2c82b12c4d96d8e3ba77330329efc53c4d56a8a7e60ade900f341866cfb F ext/wasm/api/sqlite3-api-cleanup.js 3ac1786e461ada63033143be8c3b00b26b939540661f3e839515bb92f2e35359 -F ext/wasm/api/sqlite3-api-glue.c-pp.js 2df4571b131726b1d9333d2ec8c8ce05d5b0872dad5ed08969791107d3b1616f +F ext/wasm/api/sqlite3-api-glue.c-pp.js 0394eda4f8dc499d6fb77743a5d307d786991e599a552bdd5bc9e4b92e6f4ab1 F ext/wasm/api/sqlite3-api-oo1.c-pp.js c68d6da0088c2527156fca9163a721abe08e7bd077b15404fd8d292f4612adc1 F ext/wasm/api/sqlite3-api-prologue.js 8708570165f5b4bce9a78ccd91bc9ddf8735970ac1c4d659e36c9a7d9a644bb4 F ext/wasm/api/sqlite3-api-worker1.c-pp.js f646a65257973b8c4481f8a6a216370b85644f23e64b126e7ae113570587c0ab @@ -698,7 +698,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js 43e1971f905bbb1bf2a13a80fbde41e579d051d2e008cfff1d0208e8aa48442c +F ext/wasm/tester1.c-pp.js 485d73c57836684c0f447c44182ef36a1bb3f78b8dd65eae3fe95823597a1376 F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -787,16 +787,16 @@ F src/resolve.c d40fe18d7c2fd0339f5846ffcf7d6809866e380acdf14c76fb2af87e9fe13f64 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 882d739e0d5e6c7a8b46a3cca3ada37fe1a56301f1360d6b141312c666bbe482 F src/shell.c.in 4f14a1f5196b6006abc8e73cc8fd6c1a62cf940396f8ba909d6711f35f074bb6 -F src/sqlite.h.in e3301b5f2e2d9b50160c9f185a4dfd7c5e44abb754e8bd837a96a6678b5f91be +F src/sqlite.h.in 48eb0bbedff52af04d86b74127bb6d7939e460f3ddbc9040a7482848d2057f65 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479 F src/sqlite3ext.h 0bfd049bb2088cc44c2ad54f2079d1c6e43091a4e1ce8868779b75f6c1484f1e -F src/sqliteInt.h 21c089759415895c86220d35c22cd17fdc6ca27653e1ec0c744d1e6808d0545a +F src/sqliteInt.h 461d39b85ee97d8f1496388f5d6884e8a240cabaea26b915ac7fd59e7a2ef727 F src/sqliteLimit.h 6d817c28a8f19af95e6f4921933b7fbbca48a962bce0eb0ec81e8bb3ef38e68b F src/status.c 0e72e4f6be6ccfde2488eb63210297e75f569f3ce9920f6c3d77590ec6ce5ffd F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 F src/tclsqlite.c 3c604c49e6cf4211960a9ddb9505280fd22cde32175f40884c641c0f5a286036 F src/tclsqlite.h 65e2c761446e1c9fa0342b7d2612a703483643c8b6a316d12a65b745a4727395 -F src/test1.c bcd021fadc242b29a5e3e5e552231ca87d1ccb87c282d3a4a2c6a4203eeed8f8 +F src/test1.c 73efbbb7dfbf4c8753064dab1ad14c4587d7fd58f6a0f77160dfc9663967df78 F src/test2.c 62f0830958f9075692c29c6de51b495ae8969e1bef85f239ffcd9ba5fb44a5ff F src/test3.c 432646f581d8af1bb495e58fc98234380250954f5d5535e507fc785eccc3987a F src/test4.c 0ac87fc13cdb334ab3a71823f99b6c32a6bebe5d603cd6a71d84c823d43a25a0 @@ -855,10 +855,10 @@ F src/vacuum.c 1bacdd0a81d2b5dc1c508fbf0d938c89fa78dd8d5b46ec92686d44030d4f4789 F src/vdbe.c 7e29623ca387880b8893e69135a0ff240c3dcaf0710f7a46a5f95b062cf93883 F src/vdbe.h 93761ed7c6b8bc19524912fd9b9b587d41bf4f1d0ade650a00dadc10518d8958 F src/vdbeInt.h 0bc581a9763be385e3af715e8c0a503ba8422c2b7074922faf4bb0d6ae31b15e -F src/vdbeapi.c 3dac6a9561aec2c02f2b10493f7c9a940b8a3989aaf0739daf8881efbdb07028 +F src/vdbeapi.c 8e147b96e11a72079788ac01080812fb272cdb10e58e2c123099ddda99f8b818 F src/vdbeaux.c fd2c6b19a8892c31a2adc719f156f313560f9cc490cdbd04ff08fdae5d7aedb7 F src/vdbeblob.c b1b4032cac46b41e44b957c4d00aee9851f862dfd85ecb68116ba49884b03dfd -F src/vdbemem.c 96d0b3b38e7dad62e8a177ab4c4d175972b609a21d1f00a5c207339e73d1390f +F src/vdbemem.c 9f35b9363563c9f1816e776bc5f5571785116e86d8320d62d2ecb6165b90199a F src/vdbesort.c cb6f472e83ca12c46aa7de0ac0a9d11458b357986f2617a1c90dfb19a542ecbe F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823 F src/vdbevtab.c fc46b9cbd759dc013f0b3724549cc0d71379183c667df3a5988f7e2f1bd485f3 @@ -2208,8 +2208,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0363c430b5ab8eb8cec526933da2b32263b1959c8a2210bb0e0b1529e72c6f63 -R 5cf8215b0655d83f9ed207972481e36d +P a3ca0adbaf7da8d79341fa88919b11d49a040e5125c67962b93a98ea43f539c9 +R 7dd1e4528a9739c7b931a9c56ffcf3fd U stephan -Z e957b7302d7d68762f67142fbbafbcac +Z 82614930fab8dbf419d006977ce34bbd # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 69e441cc4d..43835e9a4f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a3ca0adbaf7da8d79341fa88919b11d49a040e5125c67962b93a98ea43f539c9 +c96539beb5ca3c6a467e5388b942767765a3f071e009c1767d3b4f1b0fb5da9c diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 2e2802e903..0c89d34623 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5289,19 +5289,6 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** ^The number of columns in the result can be determined using ** [sqlite3_column_count()]. ** -** ^The sqlite3_column_text_v2() and sqlite3_column_blob_v2() -** interfaces deliver most of their output via their 3rd, 4th, and 5th -** output-pointer arguments. The 3rd is an output pointer to the -** resulting memory (the same pointer which would be returned by their -** non-v2 counterparts). The 4th is an integer pointer into which, if -** it is not NULL, the length of the memory, in bytes, is written. The -** 5th argument is an integer pointer which, if not NULL, gets set to -** the [SQLITE_INTEGER | column's SQL type]. On success these -** interfaces return 0. On error they do not modify any of their -** output pointers and return SQLITE_NOMEM on allocation error and -** SQLITE_RANGE if the given column index is out of range. Results are -** undefined if either of their 1st or 3rd arguments are NULL. -** ** If the SQL statement does not currently point to a valid row, or if the ** column index is out of range, the result is undefined. ** These routines may only be called when the most recent call to @@ -5320,10 +5307,10 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** if the query returns an integer but the sqlite3_column_text() interface ** is used to extract the value) then an automatic type conversion is performed. ** -** ^The interfaces (_text_v2, _blob_v2) interally function identically -** to their non-_v2 counterparts but have different interfaces. Their -** internal behaviors are the same for purposes of the following -** documentation except where specifically noted otherwise. +** ^The (_blob_v2, _text_v2) interfaces behave like +** sqlite3_value_blob_v2() and sqlite3_value_text_v2(), with one +** exception: they return SQLITE_RANGE if the column index is out of +** bounds. ** ** ^The sqlite3_column_type() routine returns the ** [SQLITE_INTEGER | datatype code] for the initial data type @@ -5495,12 +5482,12 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** out-of-memory conditions. */ const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); -int sqlite3_column_blob_v2(sqlite3_stmt*, int iCol, const void **, int*, int*); +int sqlite3_column_blob_v2(sqlite3_stmt*, int iCol, const void **, int*); double sqlite3_column_double(sqlite3_stmt*, int iCol); int sqlite3_column_int(sqlite3_stmt*, int iCol); sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); -int sqlite3_column_text_v2(sqlite3_stmt*, int iCol, const unsigned char **, int*, int*); +int sqlite3_column_text_v2(sqlite3_stmt*, int iCol, const unsigned char **, int*); const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); int sqlite3_column_bytes(sqlite3_stmt*, int iCol); @@ -5954,6 +5941,16 @@ SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), ** SQLITE_TEXT. Whether or not a persistent internal datatype conversion ** occurs is undefined and may change from one release of SQLite to the next. ** +** ^sqlite3_value_blob_v2() and sqlite3_value_text_v2() interfaces +** return their content via their 2nd and 3rd arguments, output +** pointers. They behave the same as their "v1" counterparts with one +** exception: sqlite3_value_blob_v2() resolves length-0 blobs to an +** opaque non-NULL pointer instead of NULL. Their 3rd argument, if not +** NULL, will get the length of the returned blob assigned to it. If +** these functions fail they return non-0 and do not modify their +** output pointers. On success they return 0 and will update their 2nd +** and (if not NULL) 3rd output pointer arguments. +** ** ^(The sqlite3_value_numeric_type() interface attempts to apply ** numeric affinity to the value. This means that an attempt is ** made to convert the value to an integer or floating point. If @@ -5981,10 +5978,11 @@ SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), ** or an expression, then sqlite3_value_frombind(X) returns zero. ** ** Please pay particular attention to the fact that the pointer returned -** from [sqlite3_value_blob()], [sqlite3_value_text()], or +** from [sqlite3_value_blob()], [sqlite3_value_blob_v2()], +** [sqlite3_value_text()], [sqlite3_value_text_v2()], or ** [sqlite3_value_text16()] can be invalidated by a subsequent call to ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], -** or [sqlite3_value_text16()]. +** [sqlite3_value_text_v2()], or [sqlite3_value_text16()]. ** ** These routines must be called from the same thread as ** the SQL function that supplied the [sqlite3_value*] parameters. @@ -6018,13 +6016,13 @@ SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), ** out-of-memory conditions. */ const void *sqlite3_value_blob(sqlite3_value*); -int sqlite3_value_blob_v2(sqlite3_value*, const void **, int*, int*); +int sqlite3_value_blob_v2(sqlite3_value*, const void **, int*); double sqlite3_value_double(sqlite3_value*); int sqlite3_value_int(sqlite3_value*); sqlite3_int64 sqlite3_value_int64(sqlite3_value*); void *sqlite3_value_pointer(sqlite3_value*, const char*); const unsigned char *sqlite3_value_text(sqlite3_value*); -int sqlite3_value_text_v2(sqlite3_value*, const unsigned char **, int*, int*); +int sqlite3_value_text_v2(sqlite3_value*, const unsigned char **, int*); const void *sqlite3_value_text16(sqlite3_value*); const void *sqlite3_value_text16le(sqlite3_value*); const void *sqlite3_value_text16be(sqlite3_value*); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 021b9f7acf..305a2aef8f 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -5399,7 +5399,7 @@ void sqlite3FileSuffix3(const char*, char*); u8 sqlite3GetBoolean(const char *z,u8); const void *sqlite3ValueText(sqlite3_value*, u8); -int sqlite3ValueTextV2(sqlite3_value*, u8, const void **, int*, int*); +int sqlite3ValueTextV2(sqlite3_value*, u8, const void **, int*); int sqlite3ValueIsOfClass(const sqlite3_value*, void(*)(void*)); int sqlite3ValueBytes(sqlite3_value*, u8); diff --git a/src/test1.c b/src/test1.c index e29a290a64..b363a6c530 100644 --- a/src/test1.c +++ b/src/test1.c @@ -5634,7 +5634,7 @@ static int SQLITE_TCLAPI test_column_blob_v2( if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; - rc = sqlite3_column_blob_v2(pStmt, col, &pBlob, &len, 0); + rc = sqlite3_column_blob_v2(pStmt, col, &pBlob, &len); if( rc ) return TCL_ERROR; Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pBlob, len)); return TCL_OK; @@ -5755,7 +5755,7 @@ static int SQLITE_TCLAPI test_stmt_utf8_v2( if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; - if( sqlite3_column_text_v2(pStmt, col, &zRet, &len, 0) ){ + if( sqlite3_column_text_v2(pStmt, col, &zRet, &len) ){ return TCL_ERROR; } if( zRet ){ diff --git a/src/vdbeapi.c b/src/vdbeapi.c index 060b1a310b..831832c7ea 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -191,9 +191,10 @@ const void *sqlite3_value_blob(sqlite3_value *pVal){ return sqlite3_value_text(pVal); } } -int sqlite3_value_blob_v2(sqlite3_value *pVal, const void **pOut, - int *pnOut, int *pType){ +int sqlite3_value_blob_v2(sqlite3_value *pVal, const void **pOut, int *pnOut){ + static const unsigned char aZeroLength[] = {0,0}; Mem *p = (Mem*)pVal; + #ifdef SQLITE_ENABLE_API_ARMOR if( pVal==0 || pOut==0 ) return SQLITE_MISUSE_BKPT; #endif @@ -203,13 +204,11 @@ int sqlite3_value_blob_v2(sqlite3_value *pVal, const void **pOut, return SQLITE_NOMEM_BKPT; } p->flags |= MEM_Blob; - *pOut = p->n ? p->z : 0; + *pOut = p->n ? p->z : (const void *)&aZeroLength[0]; if( pnOut ) *pnOut = p->n; - if( pType ) *pType = sqlite3_value_type(pVal); return 0; } - return sqlite3_value_text_v2(pVal, (const unsigned char **)pOut, - pnOut, pType); + return sqlite3_value_text_v2(pVal, (const unsigned char **)pOut, pnOut); } int sqlite3_value_bytes(sqlite3_value *pVal){ return sqlite3ValueBytes(pVal, SQLITE_UTF8); @@ -246,15 +245,14 @@ void *sqlite3_value_pointer(sqlite3_value *pVal, const char *zPType){ const unsigned char *sqlite3_value_text(sqlite3_value *pVal){ return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8); } -int sqlite3_value_text_v2(sqlite3_value *pVal, - const unsigned char **pOut, - int *pnOut, int *pType){ +int sqlite3_value_text_v2(sqlite3_value *pVal, const unsigned char **pOut, + int *pnOut){ int n = 0; #ifdef SQLITE_ENABLE_API_ARMOR if( pVal==0 || pOut==0 ) return SQLITE_MISUSE_BKPT; #endif return sqlite3ValueTextV2(pVal, SQLITE_UTF8, (const void **)pOut, - pnOut ? pnOut : &n, pType); + pnOut ? pnOut : &n); } #ifndef SQLITE_OMIT_UTF16 const void *sqlite3_value_text16(sqlite3_value* pVal){ @@ -1370,7 +1368,7 @@ static Mem *columnMem(sqlite3_stmt *pStmt, int i){ ** This is expected to only be called by sqlite3_column_blob_v2(), ** sqlite3_column_text_v2(), or APIs with similar semantics. ** -** Design notes: per /chat discussion: +** Design notes based on /chat discussions: ** ** sqlite3_column_text/blob_v2() can report SQLITE_RANGE and ** SQLITE_MISUSE, but must not perist those errors and must not take @@ -1380,7 +1378,7 @@ static Mem *columnMem(sqlite3_stmt *pStmt, int i){ ** not call columnMallocFailure() to avoid calling sqlite3ApiExit(). */ static int columnMemV2(sqlite3_stmt *pStmt, int iCol, int bBlob, - const void **pOut, int * pnOut, int *pType){ + const void **pOut, int * pnOut){ int rc = 0; Vdbe * const pVm = (Vdbe*)pStmt; @@ -1392,9 +1390,9 @@ static int columnMemV2(sqlite3_stmt *pStmt, int iCol, int bBlob, if( pVm->pResultRow!=0 && iColnResColumn && iCol>=0 ){ Mem * const pMem = &pVm->pResultRow[iCol]; rc = bBlob - ? sqlite3_value_blob_v2(pMem, pOut, pnOut, pType) + ? sqlite3_value_blob_v2(pMem, pOut, pnOut) : sqlite3_value_text_v2(pMem, (const unsigned char **)pOut, - pnOut, pType); + pnOut); }else{ rc = pVm->pResultRow==0 ? SQLITE_MISUSE_BKPT : SQLITE_RANGE; } @@ -1451,8 +1449,8 @@ const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){ return val; } int sqlite3_column_blob_v2(sqlite3_stmt *pStmt, int iCol, - const void **pOut, int *pnOut, int *pType){ - return columnMemV2(pStmt, iCol, 1, pOut, pnOut, pType); + const void **pOut, int *pnOut){ + return columnMemV2(pStmt, iCol, 1, pOut, pnOut); } int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){ int val = sqlite3_value_bytes( columnMem(pStmt,i) ); @@ -1485,9 +1483,8 @@ const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){ return val; } int sqlite3_column_text_v2(sqlite3_stmt *pStmt, int iCol, - const unsigned char **pOut, int *pnOut, - int *pType){ - return columnMemV2(pStmt, iCol, 0, (const void **)pOut, pnOut, pType); + const unsigned char **pOut, int *pnOut){ + return columnMemV2(pStmt, iCol, 0, (const void **)pOut, pnOut); } sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){ Mem *pOut = columnMem(pStmt, i); diff --git a/src/vdbemem.c b/src/vdbemem.c index 95f60174eb..4a591faadb 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -1360,10 +1360,9 @@ static SQLITE_NOINLINE const void *valueToText(sqlite3_value* pVal, u8 enc){ ** This works like valueToText() but returns its result using ** different semantics. On success, return 0, set *pOut to a ** zero-terminated version of that string, and set *pnOut (which must -** not be NULL to the string-length of that memory. If pType is not -** NULL, it will be set to the sqlite3_value_type() of pVal. +** not be NULL to the string-length of that memory. ** -** On error, return non-0 and do not modify pOut, pnOut, or pType. +** On error, return non-0 and do not modify pOut or pnOut. ** ** Maintenance note: this is almost a copy/paste clone of ** valueToText(), but the two should probably not be consolidated. The @@ -1371,8 +1370,7 @@ static SQLITE_NOINLINE const void *valueToText(sqlite3_value* pVal, u8 enc){ ** CPU cycles doubled. */ static SQLITE_NOINLINE int valueToTextV2(sqlite3_value* pVal, u8 enc, - const void **pOut, int *pnOut, - int *pType){ + const void **pOut, int *pnOut){ assert( pVal!=0 ); assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) ); assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) ); @@ -1407,7 +1405,6 @@ static SQLITE_NOINLINE int valueToTextV2(sqlite3_value* pVal, u8 enc, assert( sqlite3VdbeMemValidStrRep(pVal) ); *pOut = pVal->z; *pnOut = pVal->n; - if( pType ) *pType = sqlite3_value_type(pVal); return 0; } return (pVal->db && pVal->db->mallocFailed) @@ -1445,15 +1442,12 @@ const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){ ** ** On success, returns 0, sets *pOut to the underlying value (or NULL ** in the case of NULL), and sets *pnOut to the memory's usable -** length. If *pType is not NULL, it is set to the -** sqlite3_value_type() of pVal. On error, neither *pOut nor *pnOut -** nor *pType are modified. +** length. On error, neither *pOut nor *pnOut are modified. ** -** Results are undefined if pVal, pOut, or pnOut are NULL. pType may -** be NULL. +** Results are undefined if pVal, pOut, or pnOut are NULL. */ int sqlite3ValueTextV2(sqlite3_value* pVal, u8 enc, const void **pOut, - int *pnOut, int *pType){ + int *pnOut){ /*if( !pVal ) return SQLITE_MISUSE_BKPT;*/ assert( pVal!=0 ); assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) ); @@ -1465,16 +1459,14 @@ int sqlite3ValueTextV2(sqlite3_value* pVal, u8 enc, const void **pOut, assert( sqlite3VdbeMemValidStrRep(pVal) ); *pOut = pVal->z; *pnOut = pVal->n; - if( pType ) *pType = sqlite3_value_type( pVal ); return 0; } if( pVal->flags&MEM_Null ){ *pOut = 0; *pnOut = 0; - if( pType ) *pType = sqlite3_value_type( pVal ); return 0; } - return valueToTextV2(pVal, enc, pOut, pnOut, pType); + return valueToTextV2(pVal, enc, pOut, pnOut); } /* Return true if sqlit3_value object pVal is a string or blob value