]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add tests for CAST expressions to e_expr.test. More to come.
authordan <dan@noemail.net>
Thu, 26 Aug 2010 19:05:23 +0000 (19:05 +0000)
committerdan <dan@noemail.net>
Thu, 26 Aug 2010 19:05:23 +0000 (19:05 +0000)
FossilOrigin-Name: ba6119d1e9300de9ce7448cfa0acd579e8e69e41

manifest
manifest.uuid
test/e_expr.test

index fd1ec430113ee102f8c1fca8d0daccd935a6b56a..55b98d011a2b2894dbe897d58456e5b0ec3addb9 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,5 @@
------BEGIN PGP SIGNED MESSAGE-----
-Hash: SHA1
-
-C Add\sEXTERN\smacros\sbefore\sentry\spoints\sin\stclsqlite.c.\s\sThis\sundoes\sthe\nchange\s[b4d3e0d528c7d17fa3d05]\son\s[2006-03-06\s23:30:52].
-D 2010-08-26T16:46:58
+C Add\stests\sfor\sCAST\sexpressions\sto\se_expr.test.\sMore\sto\scome.
+D 2010-08-26T19:05:24
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 543f91f24cd7fee774ecc0a61c19704c0c3e78fd
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -345,7 +342,7 @@ F test/descidx2.test 9f1a0c83fd57f8667c82310ca21b30a350888b5d
 F test/descidx3.test fe720e8b37d59f4cef808b0bf4e1b391c2e56b6f
 F test/diskfull.test 0cede7ef9d8f415d9d3944005c76be7589bb5ebb
 F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376
-F test/e_expr.test 1c531745c94f091445157fb7953a2cc3f256f8e4
+F test/e_expr.test cdf7e80d43fbbbb2112ecb2739f36acca55a2411
 F test/e_fkey.test 6721a741c6499b3ab7e5385923233343c8f1ad05
 F test/e_fts3.test 75bb0aee26384ef586165e21018a17f7cd843469
 F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
@@ -850,14 +847,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 1975a27cdec09e1dad4ca8281a87dd7754c02c3e
-R f25d441688f62b1bff0d009ddc9b05f0
-U drh
-Z 9a37771618dd7265a40873a32109b615
------BEGIN PGP SIGNATURE-----
-Version: GnuPG v1.4.6 (GNU/Linux)
-
-iD8DBQFMdpqGoxKgR168RlERAgpjAKCERLBDfs1cXus2KLEcDb9piX9h0ACeNdCt
-sppF4YYqwSPmRWJwYVXibNc=
-=57pg
------END PGP SIGNATURE-----
+P 8b2cf9d492901a65942d0e0b87c568d1539deece
+R 0d519dfc0382f559c3cea0304f62bcc2
+U dan
+Z ba07e15a41f6520ebcfaaaf0e0a6ab47
index e64cb054d42f9f9f77f7187b1566019e097a6c84..9c16e117f0c144e51d7dde8c90793d419c5b996a 100644 (file)
@@ -1 +1 @@
-8b2cf9d492901a65942d0e0b87c568d1539deece
\ No newline at end of file
+ba6119d1e9300de9ce7448cfa0acd579e8e69e41
\ No newline at end of file
index 6b18c3019e6ea9b5e3f92c8dd2be5ce7d35fbf76..98148dace84a35bb0b7f72d50d6996dc7290e666 100644 (file)
@@ -1378,4 +1378,120 @@ do_execsql_test e_expr-26.1.6 {
 } {R1 R2 R3}
 do_test e_expr-26.1.6 { set ::evalcount } {5}
 
+
+#-------------------------------------------------------------------------
+# Test statements related to CAST expressions.
+#
+# EVIDENCE-OF: R-65079-31758 Application of a CAST expression is
+# different to application of a column affinity, as with a CAST
+# expression the storage class conversion is forced even if it is lossy
+# and irrreversible.
+#
+do_execsql_test e_expr-27.1.1 {
+  CREATE TABLE t3(a TEXT, b REAL, c INTEGER);
+  INSERT INTO t3 VALUES(X'555655', '1.23abc', 4.5);
+  SELECT typeof(a), a, typeof(b), b, typeof(c), c FROM t3;
+} {blob UVU text 1.23abc real 4.5}
+do_execsql_test e_expr-27.1.2 {
+  SELECT 
+    typeof(CAST(X'555655' as TEXT)), CAST(X'555655' as TEXT),
+    typeof(CAST('1.23abc' as REAL)), CAST('1.23abc' as REAL),
+    typeof(CAST(4.5 as INTEGER)), CAST(4.5 as INTEGER)
+} {text UVU real 1.23 integer 4}
+
+proc do_expr_test {tn expr type value} {
+  uplevel do_execsql_test $tn [list "SELECT typeof($expr), $expr"] [
+    list [list $type $value]
+  ]
+}
+proc do_qexpr_test {tn expr value} {
+  uplevel do_execsql_test $tn [list "SELECT quote($expr)"] [list $value]
+}
+
+# EVIDENCE-OF: R-27225-65050 If the value of <expr> is NULL, then
+# the result of the CAST expression is also NULL.
+#
+do_expr_test e_expr-27.2.1 { CAST(NULL AS integer) } null {}
+do_expr_test e_expr-27.2.2 { CAST(NULL AS text) }    null {}
+do_expr_test e_expr-27.2.3 { CAST(NULL AS blob) }    null {}
+do_expr_test e_expr-27.2.4 { CAST(NULL AS number) }  null {}
+
+# EVIDENCE-OF: R-31076-23575 Casting a value to a <type-name> with
+# no affinity causes the value to be converted into a BLOB.
+#
+do_expr_test e_expr-27.3.1 { CAST('abc' AS blob)       } blob abc
+do_expr_test e_expr-27.3.2 { CAST('def' AS shobblob_x) } blob def
+do_expr_test e_expr-27.3.3 { CAST('ghi' AS abbLOb10)   } blob ghi
+
+# EVIDENCE-OF: R-22956-37754 Casting to a BLOB consists of first casting
+# the value to TEXT in the encoding of the database connection, then
+# interpreting the resulting byte sequence as a BLOB instead of as TEXT.
+#
+do_qexpr_test e_expr-27.4.1 { CAST('ghi' AS blob) } X'676869'
+do_qexpr_test e_expr-27.4.2 { CAST(456 AS blob) }   X'343536'
+do_qexpr_test e_expr-27.4.3 { CAST(1.78 AS blob) }  X'312E3738'
+rename db db2
+sqlite3 db :memory:
+db eval { PRAGMA encoding = 'utf-16le' }
+do_qexpr_test e_expr-27.4.4 { CAST('ghi' AS blob) } X'670068006900'
+do_qexpr_test e_expr-27.4.5 { CAST(456 AS blob) }   X'340035003600'
+do_qexpr_test e_expr-27.4.6 { CAST(1.78 AS blob) }  X'31002E0037003800'
+db close
+sqlite3 db :memory:
+db eval { PRAGMA encoding = 'utf-16be' }
+do_qexpr_test e_expr-27.4.7 { CAST('ghi' AS blob) } X'006700680069'
+do_qexpr_test e_expr-27.4.8 { CAST(456 AS blob) }   X'003400350036'
+do_qexpr_test e_expr-27.4.9 { CAST(1.78 AS blob) }  X'0031002E00370038'
+db close
+rename db2 db
+
+# EVIDENCE-OF: R-04207-37981 To cast a BLOB value to TEXT, the sequence
+# of bytes that make up the BLOB is interpreted as text encoded using
+# the database encoding.
+#
+do_expr_test e_expr-28.1.1 { CAST (X'676869' AS text) } text ghi
+do_expr_test e_expr-28.1.2 { CAST (X'670068006900' AS text) } text g
+rename db db2
+sqlite3 db :memory:
+db eval { PRAGMA encoding = 'utf-16le' }
+do_expr_test e_expr-28.1.3 { CAST (X'676869' AS text) == 'ghi' } integer 0
+do_expr_test e_expr-28.1.4 { CAST (X'670068006900' AS text) } text ghi
+db close
+rename db2 db
+
+# EVIDENCE-OF: R-22235-47006 Casting an INTEGER or REAL value into TEXT
+# renders the value as if via sqlite3_snprintf() except that the
+# resulting TEXT uses the encoding of the database connection.
+#
+do_expr_test e_expr-28.2.1 { CAST (1 AS text)   }     text 1
+do_expr_test e_expr-28.2.2 { CAST (45 AS text)  }     text 45
+do_expr_test e_expr-28.2.3 { CAST (-45 AS text) }     text -45
+do_expr_test e_expr-28.2.4 { CAST (8.8 AS text)    }  text 8.8
+do_expr_test e_expr-28.2.5 { CAST (2.3e+5 AS text) }  text 230000.0
+do_expr_test e_expr-28.2.6 { CAST (-2.3e-5 AS text) } text -2.3e-05
+do_expr_test e_expr-28.2.7 { CAST (0.0 AS text) }     text 0.0
+do_expr_test e_expr-28.2.7 { CAST (0 AS text) }       text 0
+
+# EVIDENCE-OF: R-26346-36443 When casting a BLOB value to a REAL, the
+# value is first converted to TEXT.
+#
+do_expr_test e_expr-29.1.1 { CAST (X'312E3233' AS REAL) } real 1.23
+do_expr_test e_expr-29.1.2 { CAST (X'3233302E30' AS REAL) } real 230.0
+do_expr_test e_expr-29.1.3 { CAST (X'2D392E3837' AS REAL) } real -9.87
+do_expr_test e_expr-29.1.4 { CAST (X'302E30303031' AS REAL) } real 0.0001
+rename db db2
+sqlite3 db :memory:
+db eval { PRAGMA encoding = 'utf-16le' }
+do_expr_test e_expr-29.1.1 { 
+    CAST (X'31002E0032003300' AS REAL) } real 1.23
+do_expr_test e_expr-29.1.2 { 
+    CAST (X'3200330030002E003000' AS REAL) } real 230.0
+do_expr_test e_expr-29.1.3 { 
+    CAST (X'2D0039002E0038003700' AS REAL) } real -9.87
+do_expr_test e_expr-29.1.4 { 
+    CAST (X'30002E003000300030003100' AS REAL) } real 0.0001
+db close
+rename db2 db
+
 finish_test
+