]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhance the %q, %Q, and %w printf conversions so that the precisions
authordrh <drh@noemail.net>
Wed, 25 Nov 2009 16:53:37 +0000 (16:53 +0000)
committerdrh <drh@noemail.net>
Wed, 25 Nov 2009 16:53:37 +0000 (16:53 +0000)
specifies the length of the input.

FossilOrigin-Name: 3ba773132d3baeb87acaee538b8fb0b0f4293673

manifest
manifest.uuid
src/printf.c
test/printf.test

index ee05369e2ce0910e0b046cb624860bb471f813c5..099aa62bc9bb4e7f5b8e62da934dc877d3db3bae 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C Fix\sa\stracing\smacro\sin\sthe\sVDBE\sin\sthe\sVColumn\sopcode.
-D 2009-11-24T16:26:17
+C Enhance\sthe\s%q,\s%Q,\sand\s%w\sprintf\sconversions\sso\sthat\sthe\sprecisions\s\nspecifies\sthe\slength\sof\sthe\sinput.
+D 2009-11-25T16:53:38
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 7f6c6aa7feeeb5e26e01b344161d9aa1b5d64177
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -161,7 +161,7 @@ F src/pcache.h c683390d50f856d4cd8e24342ae62027d1bb6050
 F src/pcache1.c 2bb2261190b42a348038f5b1c285c8cef415fcc8
 F src/pragma.c 6936d7df5e04b9f996f8f320d15e65b6944b2caa
 F src/prepare.c ad90970bba3aead154266d8bb6faf9fbb5233b94
-F src/printf.c 03fabdd6112a0e23f78f8ac9a1396947ade0273b
+F src/printf.c 51c3b010c6f1bd8bb07d7ea84147eb8f63ce1238
 F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
 F src/resolve.c c52d9e52e11058f4113f6644adc20d3f85141b1d
 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
@@ -520,7 +520,7 @@ F test/pcache2.test 0d85f2ab6963aee28c671d4c71bec038c00a1d16
 F test/permutations.test 1ce2874df8fec876d0b963c7a3ef61c4e9df8827
 F test/pragma.test 5aeb48a442dba3c3e8e38773b121371814ab3b17
 F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
-F test/printf.test 47e9e5bbec8509023479d54ceb71c9d05a95308a
+F test/printf.test 05970cde31b1a9f54bd75af60597be75a5c54fea
 F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301
 F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc
 F test/quick.test 12fdc7656b4d20a537a686fb223eb99b5fe54483
@@ -776,14 +776,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 02ef972a56aab1e61786000283193165d3968842
-R 906efa28fc9f004f544fa83f98fdcd2f
+P cb74b81bb0322efdd66146d7de466c14564b18fd
+R d2fd7cc9116d60ea3bf83caab579713e
 U drh
-Z 2d2b583acdac8f54f65dc7650540653b
+Z bb155b9f1ed8f5cc73b48ffe4ac5abca
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFLDAksoxKgR168RlERAhoZAJ4s2MG81bz6MXkHnY2NUGswNrmvawCfdWH6
-NQdetJi/ySSQPEc42bDGVps=
-=OmlQ
+iD8DBQFLDWEVoxKgR168RlERAjrAAKCB/VKRKhYLK3n+HL8zd1duNxwkxQCfbc2N
+c9b72fb+mD/lcn1IAqU+NZQ=
+=Av30
 -----END PGP SIGNATURE-----
index bc1ff1336cf827d176546ebedfb899f64c408725..54c9fe62fa70531a3e483d68dabef09db900003e 100644 (file)
@@ -1 +1 @@
-cb74b81bb0322efdd66146d7de466c14564b18fd
\ No newline at end of file
+3ba773132d3baeb87acaee538b8fb0b0f4293673
\ No newline at end of file
index 5a790a15d7ed47cf4d524e02a9ef1ec62ec80cc7..fdd1222c229b08db0beb5968bbb5769261481c00 100644 (file)
@@ -645,14 +645,15 @@ void sqlite3VXPrintf(
       case etSQLESCAPE:
       case etSQLESCAPE2:
       case etSQLESCAPE3: {
-        int i, j, n, isnull;
+        int i, j, k, n, isnull;
         int needQuote;
         char ch;
         char q = ((xtype==etSQLESCAPE3)?'"':'\'');   /* Quote character */
         char *escarg = va_arg(ap,char*);
         isnull = escarg==0;
         if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
-        for(i=n=0; (ch=escarg[i])!=0; i++){
+        k = precision;
+        for(i=n=0; (ch=escarg[i])!=0 && k!=0; i++, k--){
           if( ch==q )  n++;
         }
         needQuote = !isnull && xtype==etSQLESCAPE2;
@@ -668,15 +669,17 @@ void sqlite3VXPrintf(
         }
         j = 0;
         if( needQuote ) bufpt[j++] = q;
-        for(i=0; (ch=escarg[i])!=0; i++){
-          bufpt[j++] = ch;
+        k = i;
+        for(i=0; i<k; i++){
+          bufpt[j++] = ch = escarg[i];
           if( ch==q ) bufpt[j++] = ch;
         }
         if( needQuote ) bufpt[j++] = q;
         bufpt[j] = 0;
         length = j;
-        /* The precision is ignored on %q and %Q */
-        /* if( precision>=0 && precision<length ) length = precision; */
+        /* The precision in %q and %Q means how many input characters to
+        ** consume, not the length of the output...
+        ** if( precision>=0 && precision<length ) length = precision; */
         break;
       }
       case etTOKEN: {
index 19f857cd101a75cc3421c1948a86e8dffd1b1be6..100ce96b12e066c832a2d1a08ff55f07d6192533 100644 (file)
@@ -3506,6 +3506,43 @@ do_test printf-4.3 {
 do_test printf-4.4 {
   sqlite3_mprintf_str {%d %d A NULL pointer in %%Q: %Q} 1 2
 } {1 2 A NULL pointer in %Q: NULL}
+do_test printf-4.5 {
+  sqlite3_mprintf_str {%d %d A quoted string: '%.10q'} 1 2 {Hi Y'all}
+} {1 2 A quoted string: 'Hi Y''all'}
+do_test printf-4.6 {
+  sqlite3_mprintf_str {%d %d A quoted string: '%.9q'} 1 2 {Hi Y'all}
+} {1 2 A quoted string: 'Hi Y''all'}
+do_test printf-4.7 {
+  sqlite3_mprintf_str {%d %d A quoted string: '%.8q'} 1 2 {Hi Y'all}
+} {1 2 A quoted string: 'Hi Y''all'}
+do_test printf-4.8 {
+  sqlite3_mprintf_str {%d %d A quoted string: '%.7q'} 1 2 {Hi Y'all}
+} {1 2 A quoted string: 'Hi Y''al'}
+do_test printf-4.9 {
+  sqlite3_mprintf_str {%d %d A quoted string: '%.6q'} 1 2 {Hi Y'all}
+} {1 2 A quoted string: 'Hi Y''a'}
+do_test printf-4.10 {
+  sqlite3_mprintf_str {%d %d A quoted string: '%.5q'} 1 2 {Hi Y'all}
+} {1 2 A quoted string: 'Hi Y'''}
+do_test printf-4.11 {
+  sqlite3_mprintf_str {%d %d A quoted string: '%.4q'} 1 2 {Hi Y'all}
+} {1 2 A quoted string: 'Hi Y'}
+do_test printf-4.12 {
+  sqlite3_mprintf_str {%d %d A quoted string: '%.3q'} 1 2 {Hi Y'all}
+} {1 2 A quoted string: 'Hi '}
+do_test printf-4.13 {
+  sqlite3_mprintf_str {%d %d A quoted string: '%.2q'} 1 2 {Hi Y'all}
+} {1 2 A quoted string: 'Hi'}
+do_test printf-4.14 {
+  sqlite3_mprintf_str {%d %d A quoted string: '%.1q'} 1 2 {Hi Y'all}
+} {1 2 A quoted string: 'H'}
+do_test printf-4.15 {
+  sqlite3_mprintf_str {%d %d A quoted string: '%.0q'} 1 2 {Hi Y'all}
+} {1 2 A quoted string: ''}
+do_test printf-4.16 {
+  sqlite3_mprintf_str {%d A quoted string: '%.*q'} 1 6 {Hi Y'all}
+} {1 A quoted string: 'Hi Y''a'}
+
 
 do_test printf-5.1 {
   set x [sqlite3_mprintf_str {%d %d %100000s} 0 0 {Hello}]