/ Check-in [e1814452]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Additional test cases for the tointeger() and toreal() SQL functions when converting from a BLOB.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | toTypeFuncs
Files: files | file ages | folders
SHA1: e1814452faa698946ef77f06a42665277ee59cc1
User & Date: mistachkin 2013-09-04 00:58:00
Context
2013-09-06
20:30
When converting from a BLOB value in the tointeger() and toreal() SQL functions, make sure that endianness of the machine does not matter. check-in: 94c4cdc5 user: mistachkin tags: toTypeFuncs
2013-09-04
00:58
Additional test cases for the tointeger() and toreal() SQL functions when converting from a BLOB. check-in: e1814452 user: mistachkin tags: toTypeFuncs
2013-09-01
23:36
Merge updates from trunk. check-in: 2982725e user: mistachkin tags: toTypeFuncs
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/func4.test.

    16     16   # expression arguments as double precision floating point values.
    17     17   #
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   set saved_tcl_precision $tcl_precision
    21     21   set tcl_precision 0
    22     22   
           23  +set highPrecision(1) [expr \
           24  +    {[memdbsql {SELECT tointeger(9223372036854775807 + 1);}] eq {{}}}]
           25  +
    23     26   do_execsql_test func4-1.1 {
    24     27     SELECT tointeger(NULL);
    25     28   } {{}}
    26     29   do_execsql_test func4-1.2 {
    27     30     SELECT tointeger('');
    28     31   } {{}}
    29     32   do_execsql_test func4-1.3 {
................................................................................
   124    127   } {2147483648}
   125    128   do_execsql_test func4-1.35 {
   126    129     SELECT tointeger(9223372036854775807 - 1);
   127    130   } {9223372036854775806}
   128    131   do_execsql_test func4-1.36 {
   129    132     SELECT tointeger(9223372036854775807);
   130    133   } {9223372036854775807}
   131         -do_execsql_test func4-1.37 {
   132         -  SELECT tointeger(9223372036854775807 + 1);
   133         -} {{}}
          134  +if {$highPrecision(1)} {
          135  +  do_execsql_test func4-1.37 {
          136  +    SELECT tointeger(9223372036854775807 + 1);
          137  +  } {{}}
          138  +}
   134    139   do_execsql_test func4-1.38 {
   135    140     SELECT tointeger(1.79769313486232e308 - 1);
   136    141   } {{}}
   137    142   do_execsql_test func4-1.39 {
   138    143     SELECT tointeger(1.79769313486232e308);
   139    144   } {{}}
   140    145   do_execsql_test func4-1.40 {
................................................................................
   160    165   } {9007199254740993}
   161    166   do_execsql_test func4-1.47 {
   162    167     SELECT tointeger(9223372036854775807 - 1);
   163    168   } {9223372036854775806}
   164    169   do_execsql_test func4-1.48 {
   165    170     SELECT tointeger(9223372036854775807);
   166    171   } {9223372036854775807}
   167         -do_execsql_test func4-1.49 {
   168         -  SELECT tointeger(9223372036854775807 + 1);
   169         -} {{}}
   170         -do_execsql_test func4-1.50 {
   171         -  SELECT tointeger(9223372036854775808 - 1);
   172         -} {{}}
   173         -do_execsql_test func4-1.51 {
   174         -  SELECT tointeger(9223372036854775808);
   175         -} {{}}
   176         -do_execsql_test func4-1.52 {
   177         -  SELECT tointeger(9223372036854775808 + 1);
   178         -} {{}}
          172  +if {$highPrecision(1)} {
          173  +  do_execsql_test func4-1.49 {
          174  +    SELECT tointeger(9223372036854775807 + 1);
          175  +  } {{}}
          176  +  do_execsql_test func4-1.50 {
          177  +    SELECT tointeger(9223372036854775808 - 1);
          178  +  } {{}}
          179  +  do_execsql_test func4-1.51 {
          180  +    SELECT tointeger(9223372036854775808);
          181  +  } {{}}
          182  +  do_execsql_test func4-1.52 {
          183  +    SELECT tointeger(9223372036854775808 + 1);
          184  +  } {{}}
          185  +}
   179    186   do_execsql_test func4-1.53 {
   180    187     SELECT tointeger(18446744073709551616 - 1);
   181    188   } {{}}
   182    189   do_execsql_test func4-1.54 {
   183    190     SELECT tointeger(18446744073709551616);
   184    191   } {{}}
   185    192   do_execsql_test func4-1.55 {
   186    193     SELECT tointeger(18446744073709551616 + 1);
   187    194   } {{}}
   188    195   
   189    196   ifcapable floatingpoint {
   190         -  set highPrecision [expr \
          197  +  set highPrecision(2) [expr \
   191    198         {[memdbsql {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}]
   192    199   
   193    200     do_execsql_test func4-2.1 {
   194    201       SELECT toreal(NULL);
   195    202     } {{}}
   196    203     do_execsql_test func4-2.2 {
   197    204       SELECT toreal('');
................................................................................
   258    265     } {-Inf}
   259    266     do_execsql_test func4-2.23 {
   260    267       SELECT toreal(-9223372036854775808 - 1);
   261    268     } {-9.223372036854776e+18}
   262    269     do_execsql_test func4-2.24 {
   263    270       SELECT toreal(-9223372036854775808);
   264    271     } {-9.223372036854776e+18}
   265         -  if {$highPrecision} {
          272  +  if {$highPrecision(2)} {
   266    273       do_execsql_test func4-2.25 {
   267    274         SELECT toreal(-9223372036854775808 + 1);
   268    275       } {{}}
   269    276     }
   270    277     do_execsql_test func4-2.26 {
   271    278       SELECT toreal(-9223372036854775807 - 1);
   272    279     } {-9.223372036854776e+18}
   273         -  if {$highPrecision} {
          280  +  if {$highPrecision(2)} {
   274    281       do_execsql_test func4-2.27 {
   275    282         SELECT toreal(-9223372036854775807);
   276    283       } {{}}
   277    284       do_execsql_test func4-2.28 {
   278    285         SELECT toreal(-9223372036854775807 + 1);
   279    286       } {{}}
   280    287     }
................................................................................
   292    299     } {2147483646.0}
   293    300     do_execsql_test func4-2.33 {
   294    301       SELECT toreal(2147483647);
   295    302     } {2147483647.0}
   296    303     do_execsql_test func4-2.34 {
   297    304       SELECT toreal(2147483647 + 1);
   298    305     } {2147483648.0}
   299         -  if {$highPrecision} {
          306  +  if {$highPrecision(2)} {
   300    307       do_execsql_test func4-2.35 {
   301    308         SELECT toreal(9223372036854775807 - 1);
   302    309       } {{}}
   303         -    do_execsql_test func4-2.36 {
   304         -      SELECT toreal(9223372036854775807);
   305         -    } {{}}
          310  +    if {$highPrecision(1)} {
          311  +      do_execsql_test func4-2.36 {
          312  +        SELECT toreal(9223372036854775807);
          313  +      } {{}}
          314  +    }
   306    315     }
   307    316     do_execsql_test func4-2.37 {
   308    317       SELECT toreal(9223372036854775807 + 1);
   309    318     } {9.223372036854776e+18}
   310    319     do_execsql_test func4-2.38 {
   311    320       SELECT toreal(1.79769313486232e308 - 1);
   312    321     } {Inf}
................................................................................
   327    336     } {4503599627370497.0}
   328    337     do_execsql_test func4-2.44 {
   329    338       SELECT toreal(9007199254740992 - 1);
   330    339     } {9007199254740991.0}
   331    340     do_execsql_test func4-2.45 {
   332    341       SELECT toreal(9007199254740992);
   333    342     } {9007199254740992.0}
   334         -  if {$highPrecision} {
          343  +  if {$highPrecision(2)} {
   335    344       do_execsql_test func4-2.46 {
   336    345         SELECT toreal(9007199254740992 + 1);
   337    346       } {{}}
   338    347     }
   339    348     do_execsql_test func4-2.47 {
   340    349       SELECT toreal(9007199254740992 + 2);
   341    350     } {9007199254740994.0}
   342    351     do_execsql_test func4-2.48 {
   343    352       SELECT toreal(tointeger(9223372036854775808) - 1);
   344    353     } {{}}
   345         -  do_execsql_test func4-2.49 {
   346         -    SELECT toreal(tointeger(9223372036854775808));
   347         -  } {{}}
   348         -  do_execsql_test func4-2.50 {
   349         -    SELECT toreal(tointeger(9223372036854775808) + 1);
   350         -  } {{}}
          354  +  if {$highPrecision(1)} {
          355  +    do_execsql_test func4-2.49 {
          356  +      SELECT toreal(tointeger(9223372036854775808));
          357  +    } {{}}
          358  +    do_execsql_test func4-2.50 {
          359  +      SELECT toreal(tointeger(9223372036854775808) + 1);
          360  +    } {{}}
          361  +  }
   351    362     do_execsql_test func4-2.51 {
   352    363       SELECT toreal(tointeger(18446744073709551616) - 1);
   353    364     } {{}}
   354    365     do_execsql_test func4-2.52 {
   355    366       SELECT toreal(tointeger(18446744073709551616));
   356    367     } {{}}
   357    368     do_execsql_test func4-2.53 {
................................................................................
   446    457       }
   447    458     } {0 {}}
   448    459     do_test func4-3.18 {
   449    460       catchsql {
   450    461         INSERT INTO t1 (x) VALUES ('-9223372036854775809');
   451    462       }
   452    463     } {1 {constraint failed}}
   453         -  do_test func4-3.19 {
   454         -    catchsql {
   455         -      INSERT INTO t1 (x) VALUES (9223372036854775808);
   456         -    }
   457         -  } {1 {constraint failed}}
          464  +  if {$highPrecision(1)} {
          465  +    do_test func4-3.19 {
          466  +      catchsql {
          467  +        INSERT INTO t1 (x) VALUES (9223372036854775808);
          468  +      }
          469  +    } {1 {constraint failed}}
          470  +  }
   458    471     do_execsql_test func4-3.20 {
   459    472       SELECT x FROM t1 ORDER BY x;
   460    473     } {1234 1234 1234}
   461    474   
   462    475     ifcapable floatingpoint {
   463    476       do_execsql_test func4-4.1 {
   464    477         CREATE TABLE t2(
................................................................................
   559    572     } {1}
   560    573     do_execsql_test func4-5.6 {
   561    574       SELECT tointeger(toreal(-9223372036854775808 - 1));
   562    575     } {-9223372036854775808}
   563    576     do_execsql_test func4-5.7 {
   564    577       SELECT tointeger(toreal(-9223372036854775808));
   565    578     } {-9223372036854775808}
   566         -  if {$highPrecision} {
          579  +  if {$highPrecision(2)} {
   567    580       do_execsql_test func4-5.8 {
   568    581         SELECT tointeger(toreal(-9223372036854775808 + 1));
   569    582       } {{}}
   570    583     }
   571    584     do_execsql_test func4-5.9 {
   572    585       SELECT tointeger(toreal(-2147483648 - 1));
   573    586     } {-2147483649}
................................................................................
   585    598     } {2147483647}
   586    599     do_execsql_test func4-5.14 {
   587    600       SELECT tointeger(toreal(2147483647 + 1));
   588    601     } {2147483648}
   589    602     do_execsql_test func4-5.15 {
   590    603       SELECT tointeger(toreal(9223372036854775807 - 1));
   591    604     } {{}}
   592         -  do_execsql_test func4-5.16 {
   593         -    SELECT tointeger(toreal(9223372036854775807));
   594         -  } {{}}
   595         -  do_execsql_test func4-5.17 {
   596         -    SELECT tointeger(toreal(9223372036854775807 + 1));
   597         -  } {{}}
          605  +  if {$highPrecision(1)} {
          606  +    do_execsql_test func4-5.16 {
          607  +      SELECT tointeger(toreal(9223372036854775807));
          608  +    } {{}}
          609  +    do_execsql_test func4-5.17 {
          610  +      SELECT tointeger(toreal(9223372036854775807 + 1));
          611  +    } {{}}
          612  +  }
   598    613     do_execsql_test func4-5.18 {
   599    614       SELECT tointeger(toreal(4503599627370496 - 1));
   600    615     } {4503599627370495}
   601    616     do_execsql_test func4-5.19 {
   602    617       SELECT tointeger(toreal(4503599627370496));
   603    618     } {4503599627370496}
   604    619     do_execsql_test func4-5.20 {
................................................................................
   606    621     } {4503599627370497}
   607    622     do_execsql_test func4-5.21 {
   608    623       SELECT tointeger(toreal(9007199254740992 - 1));
   609    624     } {9007199254740991}
   610    625     do_execsql_test func4-5.22 {
   611    626       SELECT tointeger(toreal(9007199254740992));
   612    627     } {9007199254740992}
   613         -  if {$highPrecision} {
          628  +  if {$highPrecision(2)} {
   614    629       do_execsql_test func4-5.23 {
   615    630         SELECT tointeger(toreal(9007199254740992 + 1));
   616    631       } {{}}
   617    632     }
   618    633     do_execsql_test func4-5.24 {
   619    634       SELECT tointeger(toreal(9007199254740992 + 2));
   620    635     } {9007199254740994}
   621         -  do_execsql_test func4-5.25 {
   622         -    SELECT tointeger(toreal(9223372036854775808 - 1));
   623         -  } {{}}
   624         -  do_execsql_test func4-5.26 {
   625         -    SELECT tointeger(toreal(9223372036854775808));
   626         -  } {{}}
   627         -  do_execsql_test func4-5.27 {
   628         -    SELECT tointeger(toreal(9223372036854775808 + 1));
   629         -  } {{}}
          636  +  if {$highPrecision(1)} {
          637  +    do_execsql_test func4-5.25 {
          638  +      SELECT tointeger(toreal(9223372036854775808 - 1));
          639  +    } {{}}
          640  +    do_execsql_test func4-5.26 {
          641  +      SELECT tointeger(toreal(9223372036854775808));
          642  +    } {{}}
          643  +    do_execsql_test func4-5.27 {
          644  +      SELECT tointeger(toreal(9223372036854775808 + 1));
          645  +    } {{}}
          646  +  }
   630    647     do_execsql_test func4-5.28 {
   631    648       SELECT tointeger(toreal(18446744073709551616 - 1));
   632    649     } {{}}
   633    650     do_execsql_test func4-5.29 {
   634    651       SELECT tointeger(toreal(18446744073709551616));
   635    652     } {{}}
   636    653     do_execsql_test func4-5.30 {
   637    654       SELECT tointeger(toreal(18446744073709551616 + 1));
   638    655     } {{}}
   639    656   }
          657  +
          658  +for {set i 0} {$i < 10} {incr i} {
          659  +  if {$i == 8} continue
          660  +  do_execsql_test func4-6.1.$i.1 [subst {
          661  +    SELECT tointeger(x'[string repeat 01 $i]');
          662  +  }] {{}}
          663  +  ifcapable floatingpoint {
          664  +    do_execsql_test func4-6.1.$i.2 [subst {
          665  +      SELECT toreal(x'[string repeat 01 $i]');
          666  +    }] {{}}
          667  +  }
          668  +}
          669  +
          670  +proc swapHexBytes { value } {
          671  +  if {[string length $value] % 2 != 0} {
          672  +    error "value \"$value\" must have an even number of characters"
          673  +  }
          674  +  if {![string is xdigit -strict $value]} then {
          675  +    error "value \"$value\" must contain only hexadecimal digits"
          676  +  }
          677  +  join [lreverse [regexp -all -inline {.{2}} $value]] ""
          678  +}
          679  +
          680  +proc swapIntegerHexBytes { value } {
          681  +  if {![info exists ::tcl_platform(byteOrder)] || \
          682  +      $::tcl_platform(byteOrder) eq "littleEndian"} {
          683  +    return $value
          684  +  }
          685  +  return [swapHexBytes $value]
          686  +}
          687  +
          688  +proc swapDoubleHexBytes { value } {
          689  +  if {![info exists ::tcl_platform(byteOrder)] || \
          690  +      $::tcl_platform(byteOrder) ne "littleEndian"} {
          691  +    return $value
          692  +  }
          693  +  return [swapHexBytes $value]
          694  +}
          695  +
          696  +do_execsql_test func4-6.2.1 [subst {
          697  +  SELECT tointeger(x'[swapIntegerHexBytes 0102030405060708]');
          698  +}] {578437695752307201}
          699  +do_execsql_test func4-6.2.2 [subst {
          700  +  SELECT tointeger(x'[swapIntegerHexBytes 0807060504030201]');
          701  +}] {72623859790382856}
          702  +
          703  +ifcapable floatingpoint {
          704  +  do_execsql_test func4-6.3.1 [subst {
          705  +    SELECT toreal(x'[swapDoubleHexBytes ffefffffffffffff]');
          706  +  }] {-1.7976931348623157e+308}
          707  +  do_execsql_test func4-6.3.2 [subst {
          708  +    SELECT toreal(x'[swapDoubleHexBytes 8010000000000000]');
          709  +  }] {-2.2250738585072014e-308}
          710  +  do_execsql_test func4-6.3.3 [subst {
          711  +    SELECT toreal(x'[swapDoubleHexBytes c000000000000000]');
          712  +  }] {-2.0}
          713  +  do_execsql_test func4-6.3.4 [subst {
          714  +    SELECT toreal(x'[swapDoubleHexBytes bff0000000000000]');
          715  +  }] {-1.0}
          716  +  do_execsql_test func4-6.3.5 [subst {
          717  +    SELECT toreal(x'[swapDoubleHexBytes 8000000000000000]');
          718  +  }] {-0.0}
          719  +  do_execsql_test func4-6.3.6 [subst {
          720  +    SELECT toreal(x'[swapDoubleHexBytes 0000000000000000]');
          721  +  }] {0.0}
          722  +  do_execsql_test func4-6.3.7 [subst {
          723  +    SELECT toreal(x'[swapDoubleHexBytes 3ff0000000000000]');
          724  +  }] {1.0}
          725  +  do_execsql_test func4-6.3.8 [subst {
          726  +    SELECT toreal(x'[swapDoubleHexBytes 4000000000000000]');
          727  +  }] {2.0}
          728  +  do_execsql_test func4-6.3.9 [subst {
          729  +    SELECT toreal(x'[swapDoubleHexBytes 0010000000000000]');
          730  +  }] {2.2250738585072014e-308}
          731  +  do_execsql_test func4-6.3.10 [subst {
          732  +    SELECT toreal(x'[swapDoubleHexBytes 7fefffffffffffff]');
          733  +  }] {1.7976931348623157e+308}
          734  +  do_execsql_test func4-6.3.11 [subst {
          735  +    SELECT toreal(x'[swapDoubleHexBytes 8000000000000001]');
          736  +  }] {-5e-324}
          737  +  do_execsql_test func4-6.3.12 [subst {
          738  +    SELECT toreal(x'[swapDoubleHexBytes 800fffffffffffff]');
          739  +  }] {-2.225073858507201e-308}
          740  +  do_execsql_test func4-6.3.13 [subst {
          741  +    SELECT toreal(x'[swapDoubleHexBytes 0000000000000001]');
          742  +  }] {5e-324}
          743  +  do_execsql_test func4-6.3.14 [subst {
          744  +    SELECT toreal(x'[swapDoubleHexBytes 000fffffffffffff]');
          745  +  }] {2.225073858507201e-308}
          746  +  do_execsql_test func4-6.3.15 [subst {
          747  +    SELECT toreal(x'[swapDoubleHexBytes fff0000000000000]');
          748  +  }] {-Inf}
          749  +  do_execsql_test func4-6.3.16 [subst {
          750  +    SELECT toreal(x'[swapDoubleHexBytes 7ff0000000000000]');
          751  +  }] {Inf}
          752  +  do_execsql_test func4-6.3.17 [subst {
          753  +    SELECT toreal(x'[swapDoubleHexBytes fff8000000000000]');
          754  +  }] {{}}
          755  +  do_execsql_test func4-6.3.18 [subst {
          756  +    SELECT toreal(x'[swapDoubleHexBytes fff0000000000001]');
          757  +  }] {{}}
          758  +  do_execsql_test func4-6.3.19 [subst {
          759  +    SELECT toreal(x'[swapDoubleHexBytes fff7ffffffffffff]');
          760  +  }] {{}}
          761  +  do_execsql_test func4-6.3.20 [subst {
          762  +    SELECT toreal(x'[swapDoubleHexBytes 7ff0000000000001]');
          763  +  }] {{}}
          764  +  do_execsql_test func4-6.3.21 [subst {
          765  +    SELECT toreal(x'[swapDoubleHexBytes 7ff7ffffffffffff]');
          766  +  }] {{}}
          767  +  do_execsql_test func4-6.3.22 [subst {
          768  +    SELECT toreal(x'[swapDoubleHexBytes fff8000000000001]');
          769  +  }] {{}}
          770  +  do_execsql_test func4-6.3.23 [subst {
          771  +    SELECT toreal(x'[swapDoubleHexBytes ffffffffffffffff]');
          772  +  }] {{}}
          773  +  do_execsql_test func4-6.3.24 [subst {
          774  +    SELECT toreal(x'[swapDoubleHexBytes 7ff8000000000000]');
          775  +  }] {{}}
          776  +  do_execsql_test func4-6.3.25 [subst {
          777  +    SELECT toreal(x'[swapDoubleHexBytes 7fffffffffffffff]');
          778  +  }] {{}}
          779  +}
   640    780   
   641    781   set tcl_precision $saved_tcl_precision
   642    782   unset saved_tcl_precision
   643    783   finish_test