]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add some UTF-8 test infrastructure. Treat NaN as NULL. The printf routines
authordrh <drh@noemail.net>
Thu, 10 May 2007 17:23:11 +0000 (17:23 +0000)
committerdrh <drh@noemail.net>
Thu, 10 May 2007 17:23:11 +0000 (17:23 +0000)
print infinity as "Inf" not as "NaN".  Ticket #2345. (CVS 3972)

FossilOrigin-Name: ffe615a71107a38b6f60c7baf4284a5b0aecdc22

manifest
manifest.uuid
src/printf.c
src/sqliteInt.h
src/test_hexio.c
src/utf.c
src/vdbe.c
src/vdbemem.c
test/bind.test
test/expr.test
test/printf.test

index d7a3b1c058dbb307bdd13538b8551885c14b3ab4..e5d1e3964dc440c7a747409b16e41483cee3ee58 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\snew\stest\sfile\sfuzz.test,\sto\stest\sSQLite\swith\sfuzzily\sgenerated\sSQL.\s(CVS\s3971)
-D 2007-05-10T15:37:53
+C Add\ssome\sUTF-8\stest\sinfrastructure.\s\sTreat\sNaN\sas\sNULL.\s\sThe\sprintf\sroutines\nprint\sinfinity\sas\s"Inf"\snot\sas\s"NaN".\s\sTicket\s#2345.\s(CVS\s3972)
+D 2007-05-10T17:23:12
 F Makefile.in 87b200ad9970907f76df734d29dff3d294c10935
 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -97,14 +97,14 @@ F src/pager.h 94110a5570dca30d54a883e880a3633b2e4c05ae
 F src/parse.y 39b25cc7f9e1a1a999f367545192c35db644610d
 F src/pragma.c 0703152b9edd6601eea95e1d474b3bc2962d7920
 F src/prepare.c 87c23644986b5e41a58bc76f05abebd899e00089
-F src/printf.c 67de0dcb40ef3297f4a047b434b81585c0f7062d
+F src/printf.c 05b233c7a39aec4c54c79ef87af24f0a6591175d
 F src/random.c 6119474a6f6917f708c1dee25b9a8e519a620e88
 F src/select.c d43bbdedb843a91b728531c831f3ed04846b920d
 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
 F src/shell.c d07ae326b3815d80f71c69b3c7584382e47f6447
 F src/sqlite.h.in 664b8702c27dc742584788823c548491ac8935d6
 F src/sqlite3ext.h 7d0d363ea7327e817ef0dfe1b7eee1f171b72890
-F src/sqliteInt.h 7e7faee79b811ff54796d71bf8aa3dc76b1b1a95
+F src/sqliteInt.h ff1cfd5ac09dc43f55ad4994daef9a0ce876f043
 F src/table.c a8de75bcedf84d4060d804264b067ab3b1a3561d
 F src/tclsqlite.c f425c7583665ef78dd8397b2de0b8e0028e80ce2
 F src/test1.c 16938b7e76469abf957745743dd0287d5dee476d
@@ -120,7 +120,7 @@ F src/test_async.c 9d326ceda4306bcab252b8f7e8e480ed45d7ccb6
 F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436
 F src/test_btree.c 882d59acad48bab3b1fe3daf3645059b590cfc79
 F src/test_config.c 14080fbd60d334c17bf9610c8ac31814a7ad3832
-F src/test_hexio.c 32204b5ce281ebc85f789c69c4ec725129e7e7f5
+F src/test_hexio.c 14c007252285c6dabcec4a28fcf08e9177e85178
 F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
 F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3
 F src/test_schema.c ced72140a3a25c148975428e170ec1850d3c3a7d
@@ -129,17 +129,17 @@ F src/test_tclvar.c 315e77c17f128ff8c06b38c08617fd07c825a95b
 F src/tokenize.c be3524e7f626340032108f40eecd6f6eb39b4b73
 F src/trigger.c 420192efe3e6f03addf7897c60c3c8bf913d3493
 F src/update.c 3359041db390a8f856d67272f299600e2104f350
-F src/utf.c 168fe53589e2d0faec053af098c0d02e6a7690a8
+F src/utf.c be7c64eed83fa3c01e0c42905e1c311dcd1be704
 F src/util.c 4f6bbcec2b2b1884d652b82c9f8949ede4618d68
 F src/vacuum.c 8bd895d29e7074e78d4e80f948e35ddc9cf2beef
-F src/vdbe.c a24290221c20a2c5436f79bc52a9271457138416
+F src/vdbe.c a2e2a5d6f9105a36d38cbdd8ff47486ea0ba7c1c
 F src/vdbe.h 001c5b257567c1d3de7feb2203aac71d0d7b16a3
 F src/vdbeInt.h bddb7931fc1216fda6f6720e18d2a9b1e0f8fc96
 F src/vdbeapi.c 120e04492e98e3cfd5545dd7130c76987e40e8b3
 F src/vdbeaux.c 62011e2ccf5fa9b3dcc7fa6ff5f0e0638d324a70
 F src/vdbeblob.c 96f3572fdc45eda5be06e6372b612bc30742d9f0
 F src/vdbefifo.c 3ca8049c561d5d67cbcb94dc909ae9bb68c0bf8f
-F src/vdbemem.c 2d59bc2b6356cf3721077f75da92fedee458c4e1
+F src/vdbemem.c 0fb40f9255ebaa53af0281a6df2bcf5001313081
 F src/vtab.c c5ebebf615b2f29499fbe97a584c4bb342632aa0
 F src/where.c f3920748cc650fc25ac916215500bdb90dee568e
 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
@@ -167,7 +167,7 @@ F test/avtrans.test b77740800de0d2cdcf394ef94d2d61225a1941d8
 F test/between.test 16b1776c6323faadb097a52d673e8e3d8be7d070
 F test/bigfile.test ebc9ce9216e08bead63734ab816d0f27858f3b80
 F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
-F test/bind.test b2c9938805a78adbe5953dbaaee1d6f9afce370b
+F test/bind.test 261fd1603613e7f877a516d29f281c9d8c2ecf52
 F test/bindxfer.test b9a57f66dbd317feeefa28bd65b6576f1592ee98
 F test/blob.test 28c3b25150684ee3d108bb78cfb67a472deef2f0
 F test/btree.test 8b6168980efdd194289798f19d4c81434f6d3a66
@@ -218,7 +218,7 @@ F test/enc3.test 890508efff6677345e93bf2a8adb0489b30df030
 F test/exclusive.test 5bc520ba366ae3d242420af025ab64d465b04706
 F test/exclusive2.test f9738964b01e0bc4d4e5e270e347ca162da51799
 F test/exclusive3.test 0e49c35b7e7cb8e7280b4ce3f0359d30b207d2ff
-F test/expr.test a0b2bb93da2b191e93b34ee048cc03e0b2d8b6a0
+F test/expr.test 93931366f660dc84ba36eaf390f670b27d2c03e8
 F test/filefmt.test 053b622009fbbb74dd37921ffad374d852c13cd8
 F test/fkey1.test dcb4f28eb22d5141f15161d6bdca9a4f58c95729
 F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb
@@ -314,7 +314,7 @@ F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
 F test/pageropt.test b4b38eb3cf76be2be444326856248898bb0e3fc9
 F test/pagesize.test e0a8b3fe80f8b8e808d94a00734c7a18c76c407e
 F test/pragma.test fecb7085f58d9fb5172a5c0b63fd3b25c7bfb414
-F test/printf.test 71047b5fe8e2adfbe514e0d56e10adf12d84deff
+F test/printf.test 69d8cb0771a1a5e4d9d5dece12fc2c16179ac5e5
 F test/progress.test 8b22b4974b0a95272566385f8cb8c341c7130df8 x
 F test/ptrchng.test 1c712dd6516e1377471744fa765e41c79a357da6
 F test/quick.test 9f5bb4e95460472dc379f5dd8932c743407501ef
@@ -487,7 +487,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 9c0050a10c6bea75ada902c16eb28eb3cf864718
-R 862728ba028801203dde1e64535d126a
-U danielk1977
-Z 6effd6cb91351315b8bd943713c44c7f
+P 1e9e6fe75d01d8cf4e1a23505c45f28491f1e902
+R 3021e7397e47b6679eee0e86458d86ce
+U drh
+Z 62c7f31e1b53396b98122862f404dfd2
index b3fb4c0eca94949ccf7435e4a37d9ca44c21072f..9f7f1d2ed697bc1b0ca9d678bda668fcc27f96a6 100644 (file)
@@ -1 +1 @@
-1e9e6fe75d01d8cf4e1a23505c45f28491f1e902
\ No newline at end of file
+ffe615a71107a38b6f60c7baf4284a5b0aecdc22
\ No newline at end of file
index 612cae6e527d09ce5dd4ac9d995e94da643a0c53..31c929830f3804ca407d32f22e1557bd4e05f6a5 100644 (file)
@@ -51,6 +51,7 @@
 **
 */
 #include "sqliteInt.h"
+#include <math.h>
 
 /*
 ** Conversion types fall into various categories as defined by the
@@ -453,6 +454,11 @@ static int vxprintf(
         if( xtype==etFLOAT ) realvalue += rounder;
         /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
         exp = 0;
+        if( isnan(realvalue) ){
+          bufpt = "NaN";
+          length = 3;
+          break;
+        }
         if( realvalue>0.0 ){
           while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
           while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
@@ -460,8 +466,14 @@ static int vxprintf(
           while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
           while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
           if( exp>350 || exp<-350 ){
-            bufpt = "NaN";
-            length = 3;
+            if( prefix=='-' ){
+              bufpt = "-Inf";
+            }else if( prefix=='+' ){
+              bufpt = "+Inf";
+            }else{
+              bufpt = "Inf";
+            }
+            length = strlen(bufpt);
             break;
           }
         }
index fc2525f8fcd6d996bc8cd508a78d33e638116063..b980d2281192a4463cdb197dbb49e6f5d2db254e 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.563 2007/05/10 10:46:57 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.564 2007/05/10 17:23:12 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -1840,6 +1840,10 @@ int sqlite3OpenTempDatabase(Parse *);
   #define sqlite3TableLock(v,w,x,y,z)
 #endif
 
+#ifdef SQLITE_TEST
+  int sqlite3Utf8To8(unsigned char*);
+#endif
+
 #ifdef SQLITE_MEMDEBUG
   void sqlite3MallocDisallow(void);
   void sqlite3MallocAllow(void);
index 48748a9e5de41dfba0121e03d8beed286aa9d721..d6931cc276a8a937b95b4a058425f9d05eacbb65 100644 (file)
 ** with historical versions of the "binary" command.  So it seems
 ** easier and safer to build our own mechanism.
 **
-** $Id: test_hexio.c,v 1.2 2007/04/09 20:30:11 drh Exp $
+** $Id: test_hexio.c,v 1.3 2007/05/10 17:23:12 drh Exp $
 */
+#include "sqliteInt.h"
 #include "tcl.h"
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 
-/*
-hexio_read  filename offset amt
-hexio_write filename offset hexdata
-hexio_get_int  hexdata
-hexio_get_varint  hexdata
-hexio_render_int8  integer
-hexio_render_int16  integer
-hexio_render_int38  integer
-hexio_render_varint  integer
-*/
 
 /*
 ** Convert binary to hex.  The input zBuf[] contains N bytes of
@@ -287,6 +278,37 @@ static int hexio_render_int32(
   return TCL_OK;
 }
 
+/*
+** USAGE:  utf8_to_utf8  HEX
+**
+** The argument is a UTF8 string represented in hexadecimal.
+** The UTF8 might not be well-formed.  Run this string through
+** sqlite3Utf8to8() convert it back to hex and return the result.
+*/
+static int utf8_to_utf8(
+  void * clientData,
+  Tcl_Interp *interp,
+  int objc,
+  Tcl_Obj *CONST objv[]
+){
+  int n;
+  int nOut;
+  const unsigned char *zOrig;
+  unsigned char *z;
+  if( objc!=2 ){
+    Tcl_WrongNumArgs(interp, 1, objv, "HEX");
+    return TCL_ERROR;
+  }
+  zOrig = (unsigned char *)Tcl_GetStringFromObj(objv[1], &n);
+  z = sqlite3_malloc( n+3 );
+  n = hexToBin(zOrig, n, z);
+  z[n] = 0;
+  nOut = sqlite3Utf8To8(z);
+  binToHex(z,nOut);
+  Tcl_AppendResult(interp, (char*)z, 0);
+  sqlite3_free(z);
+  return TCL_OK;
+}
 
 
 /*
@@ -302,6 +324,7 @@ int Sqlitetest_hexio_Init(Tcl_Interp *interp){
      { "hexio_get_int",                hexio_get_int         },
      { "hexio_render_int16",           hexio_render_int16    },
      { "hexio_render_int32",           hexio_render_int32    },
+     { "utf8_to_utf8",                 utf8_to_utf8          },
   };
   int i;
   for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
index f78e600c79b523c794028e095011572a8844d88b..7c113857de17398e57f6113c968bbf68a95a13c4 100644 (file)
--- a/src/utf.c
+++ b/src/utf.c
@@ -12,7 +12,7 @@
 ** This file contains routines used to translate between UTF-8, 
 ** UTF-16, UTF-16BE, and UTF-16LE.
 **
-** $Id: utf.c,v 1.45 2007/05/08 20:37:40 drh Exp $
+** $Id: utf.c,v 1.46 2007/05/10 17:23:12 drh Exp $
 **
 ** Notes on UTF-8:
 **
@@ -573,6 +573,33 @@ void sqlite3Utf16Substr(
   sqlite3_result_text16(context, zStart, zEnd-zStart, SQLITE_TRANSIENT);
 }
 
+#if defined(SQLITE_TEST)
+/*
+** Translate UTF-8 to UTF-8.
+**
+** This has the effect of making sure that the string is well-formed
+** UTF-8.  Miscoded characters are removed.
+**
+** The translation is done in-place (since it is impossible for the
+** correct UTF-8 encoding to be longer than a malformed encoding).
+*/
+int sqlite3Utf8To8(unsigned char *zIn){
+  unsigned char *zOut = zIn;
+  unsigned char *zStart = zIn;
+  int c;
+
+  while(1){
+    READ_UTF8(zIn, c);
+    if( c==0 ) break;
+    if( c!=0xfffd ){
+      WRITE_UTF8(zOut, c);
+    }
+  }
+  *zOut = 0;
+  return zOut - zStart;
+}
+#endif
+
 #if defined(SQLITE_TEST)
 /*
 ** This routine is called from the TCL test function "translate_selftest".
index 611c501c0871dfa08b81f195804cb60f88ac2deb..440e1df358e154466fa4337abd77e217422fdde9 100644 (file)
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.612 2007/05/08 20:59:49 drh Exp $
+** $Id: vdbe.c,v 1.613 2007/05/10 17:23:12 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
 #include <ctype.h>
+#include <math.h>
 #include "vdbeInt.h"
 
 /*
@@ -1178,6 +1179,9 @@ case OP_Remainder: {           /* same as TK_REM, no-push */
         break;
       }
     }
+    if( isnan(b) ){
+      goto divide_by_zero;
+    }
     Release(pTos);
     pTos--;
     Release(pTos);
index 0cde5cf643815f15875d63bfc2dbb8a156847634..259ef126b2a46c2fe15458836ac15dc9978d27de 100644 (file)
@@ -17,6 +17,7 @@
 */
 #include "sqliteInt.h"
 #include "os.h"
+#include <math.h>
 #include <ctype.h>
 #include "vdbeInt.h"
 
@@ -406,10 +407,14 @@ void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
 ** manifest type REAL.
 */
 void sqlite3VdbeMemSetDouble(Mem *pMem, double val){
-  sqlite3VdbeMemRelease(pMem);
-  pMem->r = val;
-  pMem->flags = MEM_Real;
-  pMem->type = SQLITE_FLOAT;
+  if( isnan(val) ){
+    sqlite3VdbeMemSetNull(pMem);
+  }else{
+    sqlite3VdbeMemRelease(pMem);
+    pMem->r = val;
+    pMem->flags = MEM_Real;
+    pMem->type = SQLITE_FLOAT;
+  }
 }
 
 /*
index ebd851429cfc21f12ef5b0aaf3acbac8b52c7c12..115734a3116a7eb6efca80a4c51ee3b091d693d6 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script testing the sqlite_bind API.
 #
-# $Id: bind.test,v 1.39 2007/05/09 11:37:23 danielk1977 Exp $
+# $Id: bind.test,v 1.40 2007/05/10 17:23:12 drh Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -211,6 +211,24 @@ do_test bind-4.3 {
     DELETE FROM t1;
   }
 } {}
+do_test bind-4.4 {
+  sqlite3_bind_double $VM 1 NaN
+  sqlite3_bind_double $VM 2 1e300
+  sqlite3_bind_double $VM 3 -1e-300
+  sqlite_step $VM N VALUES COLNAMES
+  sqlite3_reset $VM
+  set x [execsql {SELECT rowid, * FROM t1}]
+  regsub {1e-005} $x {1e-05} y
+  set y
+} {1 {} 1e+300 -1e-300}
+do_test bind-4.5 {
+  execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1}
+} {null real real}
+do_test bind-4.6 {
+  execsql {
+    DELETE FROM t1;
+  }
+} {}
 
 # NULL
 do_test bind-5.1 {
index 2198539bbed0d7bf905d91d87228d2883b9fd984..8d89a0d68471f3668e6b7d14113db78d7d992132 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing expressions.
 #
-# $Id: expr.test,v 1.54 2007/05/08 13:57:34 danielk1977 Exp $
+# $Id: expr.test,v 1.55 2007/05/10 17:23:12 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -165,6 +165,7 @@ test_expr expr-2.22 {r1=1.23, r2=2.34} {min(r1,r2,r1+r2,r1-r2)} {-1.11}
 test_expr expr-2.23 {r1=1.23, r2=2.34} {max(r1,r2,r1+r2,r1-r2)} {3.57}
 test_expr expr-2.24 {r1=25.0, r2=11.0} {r1%r2} 3.0
 test_expr expr-2.25 {r1=1.23, r2=NULL} {coalesce(r1+r2,99.0)} 99.0
+test_expr expr-2.26 {r1=1e300, r2=1e300} {coalesce((r1*r2)*0.0,99.0)} 99.0
 
 test_expr expr-3.1 {t1='abc', t2='xyz'} {t1<t2} 1
 test_expr expr-3.2 {t1='xyz', t2='abc'} {t1<t2} 0
index 2c6671f29b29bec7e3e6970c3d5aec06a7caeaba..fa1255a6c671af770ee0daa00a80bb8f2aeeccb2 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the sqlite_*_printf() interface.
 #
-# $Id: printf.test,v 1.23 2007/05/07 11:24:31 drh Exp $
+# $Id: printf.test,v 1.24 2007/05/10 17:23:12 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -155,7 +155,13 @@ do_test printf-7.2 {
 } {A double: 1e+308}
 do_test printf-7.3 {
   sqlite3_mprintf_scaled {A double: %g} 1.0e307 100.0
-} {A double: NaN}
+} {A double: Inf}
+do_test printf-7.4 {
+  sqlite3_mprintf_scaled {A double: %g} -1.0e307 100.0
+} {A double: -Inf}
+do_test printf-7.5 {
+  sqlite3_mprintf_scaled {A double: %+g} 1.0e307 100.0
+} {A double: +Inf}
 
 do_test printf-8.1 {
   sqlite3_mprintf_int {%u %u %u} 0x7fffffff 0x80000000 0xffffffff
@@ -257,6 +263,15 @@ do_test printf-13.2 {
 do_test printf-13.3 {
   sqlite3_mprintf_hexdouble %.20f 4693b8b5b5056e17
 } {100000000000000000000000000000000.00000000000000000000}
+do_test printf-13.4 {
+  sqlite3_mprintf_hexdouble %.20f 7ff0000000000000
+} {Inf}
+do_test printf-13.5 {
+  sqlite3_mprintf_hexdouble %.20f fff0000000000000
+} {-Inf}
+do_test printf-13.6 {
+  sqlite3_mprintf_hexdouble %.20f fff8000000000000
+} {NaN}
 
 do_test printf-14.1 {
   sqlite3_mprintf_str {abc-%y-123} 0 0 {not used}