1*0e5fba79Sdrh# 2013 March 20 2*0e5fba79Sdrh# 3*0e5fba79Sdrh# The author disclaims copyright to this source code. In place of 4*0e5fba79Sdrh# a legal notice, here is a blessing: 5*0e5fba79Sdrh# 6*0e5fba79Sdrh# May you do good and not evil. 7*0e5fba79Sdrh# May you find forgiveness for yourself and forgive others. 8*0e5fba79Sdrh# May you share freely, never taking more than you give. 9*0e5fba79Sdrh# 10*0e5fba79Sdrh#*********************************************************************** 11*0e5fba79Sdrh# This file implements regression tests for SQLite library. 12*0e5fba79Sdrh# This particular file does testing of casting strings into numeric 13*0e5fba79Sdrh# values. 14*0e5fba79Sdrh# 15*0e5fba79Sdrh 16*0e5fba79Sdrhset testdir [file dirname $argv0] 17*0e5fba79Sdrhsource $testdir/tester.tcl 18*0e5fba79Sdrh 19*0e5fba79Sdrhforeach enc {utf8 utf16le utf16be} { 20*0e5fba79Sdrh do_test numcast-$enc.0 { 21*0e5fba79Sdrh db close 22*0e5fba79Sdrh sqlite3 db :memory: 23*0e5fba79Sdrh db eval "PRAGMA encoding='$enc'" 24*0e5fba79Sdrh set x [db eval {PRAGMA encoding}] 25*0e5fba79Sdrh string map {- {}} [string tolower $x] 26*0e5fba79Sdrh } $enc 27*0e5fba79Sdrh foreach {idx str rval ival} { 28*0e5fba79Sdrh 1 12345.0 12345.0 12345 29*0e5fba79Sdrh 2 12345.0e0 12345.0 12345 30*0e5fba79Sdrh 3 -12345.0e0 -12345.0 -12345 31*0e5fba79Sdrh 4 -12345.25 -12345.25 -12345 32*0e5fba79Sdrh 5 { -12345.0} -12345.0 -12345 33*0e5fba79Sdrh 6 { 876xyz} 876.0 876 34*0e5fba79Sdrh 7 { 456ķ89} 456.0 456 35*0e5fba79Sdrh 8 { Ġ 321.5} 0.0 0 36*0e5fba79Sdrh } { 37*0e5fba79Sdrh do_test numcast-$enc.$idx.1 { 38*0e5fba79Sdrh db eval {SELECT CAST($str AS real)} 39*0e5fba79Sdrh } $rval 40*0e5fba79Sdrh do_test numcast-$enc.$idx.2 { 41*0e5fba79Sdrh db eval {SELECT CAST($str AS integer)} 42*0e5fba79Sdrh } $ival 43*0e5fba79Sdrh } 44*0e5fba79Sdrh} 45*0e5fba79Sdrh 46*0e5fba79Sdrhfinish_test 47