From 35bb9d026ed7cfd96d11210a18233321c8ec6774 Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Mon, 24 May 2004 12:55:54 +0000 Subject: [PATCH] Update the typeof() operator to respect manifest types. (CVS 1450) FossilOrigin-Name: 162cf42e33691f4c9ec3a25abcaa2bdcdca2b5e0 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/func.c | 12 ++++++++++-- src/sqliteInt.h | 4 ++-- test/bind.test | 26 +++++++++++++------------- test/table.test | 9 +++++---- test/types.test | 24 ++++++++++++------------ 7 files changed, 53 insertions(+), 44 deletions(-) diff --git a/manifest b/manifest index f969f54ce2..a9715549a3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Non-aggregate\sSQL\sfunctions\suse\ssqlite_value*\sinstead\sof\sconst\schar\s*\sfor\nargument\svalues.\s(CVS\s1449) -D 2004-05-24T12:39:02 +C Update\sthe\stypeof()\soperator\sto\srespect\smanifest\stypes.\s(CVS\s1450) +D 2004-05-24T12:55:55 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -32,7 +32,7 @@ F src/date.c 64fd7169c7d599ec8eaa99121d59e27ddf3d783d F src/delete.c 2e1dda38345416a1ea1c0a6468589a7472334dac F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37 F src/expr.c 5b283e68bd6df365b7c2ad10bd04cc54c2b4b07c -F src/func.c 3690069d7490b8486f5e54da5c2064b747245730 +F src/func.c c33bad759fa3088612b07caa268d4beb4cc92a38 F src/hash.c 440c2f8cb373ee1b4e13a0988489c7cd95d55b6f F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb F src/insert.c e510d62d23b4de4d901e7ccbbe7833b7fb3b9570 @@ -55,7 +55,7 @@ F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3 F src/select.c 7d77a8bed7eeac23216d42fc1be006fb4352fcdc F src/shell.c ed4d237b3e52a0a42512bfcc53530e46de20c28f F src/sqlite.h.in 258c3a11c9c47cf7302cd4e94c1cac296275bb9b -F src/sqliteInt.h e1191166ac9055d6c99c97771d3f35212ef2cff2 +F src/sqliteInt.h 6498bd799288f0501527f7593356edee02e1b0a1 F src/table.c af14284fa36c8d41f6829e3f2819dce07d3e2de2 F src/tclsqlite.c c8b511645f98051f41b5e0d6c3a99feeed9aeeec F src/test1.c 27a5994f6ce76d62162dac6d1d926deee70c73dd @@ -80,7 +80,7 @@ F test/attach2.test 5472d442bb2ef1ee587e0ae7472bb68b52509a38 F test/auth.test 5c4d95cdaf539c0c236e20ce1f71a93e7dde9185 F test/bigfile.test ea904b853ce2d703b16c5ce90e2b54951bc1ae81 F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578 -F test/bind.test 87a6c083da06b05c87a2a507ca5f566af0b53602 +F test/bind.test 947eea896241b90bae0928e3a655bb5d7f0680bb F test/btree.test 08e4093c78d2bc1d54e27266f8d17fed14751125 F test/btree2.test aa4a6d05b1ea90b1acaf83ba89039dd302a88635 F test/btree4.test 3797b4305694c7af6828675b0f4b1424b8ca30e4 @@ -140,7 +140,7 @@ F test/select5.test c2a6c4a003316ee42cbbd689eebef8fdce0db2ac F test/select6.test a9e31906e700e7c7592c4d0acfc022808f718baf F test/sort.test 0ed7ff33d8435dde289342d0a5fed662f762f700 F test/subselect.test f0fea8cf9f386d416d64d152e3c65f9116d0f50f -F test/table.test 50e4534552d0385a0e59b3a6d7dde059ced02f83 +F test/table.test 71f808817b50ae3a9a693a88b3ea003f1031cdbb F test/tableapi.test e0c4cce61e58343caa84dab33fa6823cb35fe1e1 F test/tclsqlite.test a684fc191b81e6cded8a81263663d5a130fbb013 F test/temptable.test a770ba6308d7f7332fce985086b8e06bed6430c2 @@ -153,7 +153,7 @@ F test/trigger1.test 4538c1c7d6bbca5dfe619ea6e1682b07ece95b21 F test/trigger2.test 0767ab30cb5a2c8402c8524f3d566b410b6f5263 F test/trigger3.test a95ccace88291449f5eae7139ec438a42f90654d F test/trigger4.test 542afce45774e8f8e1130b96b8675f414d6e4bd8 -F test/types.test e1e0d71c8e65f8aa5d9a36751f4c8cbce6f01f7a +F test/types.test 8fa51489d4765b8baa2d3c92de32aba06315a655 F test/types2.test 5d725fcb68dbd032c6d4950d568d75fa33872687 F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b F test/update.test b29bd9061a1150426dab6959806fcc73a41b1217 @@ -202,7 +202,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P a554bf6c7075839f760a2ff944ac61b32cab0821 -R 584e2db8cb6f2477ffc6bd281b266ab4 +P 1e47d7384d5fdfceb6ec737c656f70be59ba5b01 +R e2f680e7baa92e0e16b93c2c89142f17 U danielk1977 -Z 579d136717a5636755a59ce43f57b420 +Z e9ca420be0cdabd35afa6fc3433fc6b4 diff --git a/manifest.uuid b/manifest.uuid index 4daa42614d..864e491c33 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e47d7384d5fdfceb6ec737c656f70be59ba5b01 \ No newline at end of file +162cf42e33691f4c9ec3a25abcaa2bdcdca2b5e0 \ No newline at end of file diff --git a/src/func.c b/src/func.c index ea30997a33..a5ded41f51 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.50 2004/05/24 12:39:02 danielk1977 Exp $ +** $Id: func.c,v 1.51 2004/05/24 12:55:55 danielk1977 Exp $ */ #include #include @@ -59,8 +59,16 @@ static void minmaxFunc(sqlite_func *context, int argc, sqlite3_value **argv){ ** Return the type of the argument. */ static void typeofFunc(sqlite_func *context, int argc, sqlite3_value **argv){ + const char *z = 0; assert( argc==2 ); - sqlite3_set_result_string(context, sqlite3_value_data(argv[1]), -1); + switch( sqlite3_value_type(argv[0]) ){ + case SQLITE3_NULL: z = "null" ; break; + case SQLITE3_INTEGER: z = "integer" ; break; + case SQLITE3_TEXT: z = "text" ; break; + case SQLITE3_FLOAT: z = "real" ; break; + case SQLITE3_BLOB: z = "blob" ; break; + } + sqlite3_set_result_string(context, z, -1); } /* diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 1c99bd80ee..7a518ca8e1 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.248 2004/05/24 07:04:26 danielk1977 Exp $ +** @(#) $Id: sqliteInt.h,v 1.249 2004/05/24 12:55:55 danielk1977 Exp $ */ #include "config.h" #include "sqlite.h" @@ -464,7 +464,7 @@ struct sqlite { ** points to a linked list of these structures. */ struct FuncDef { - void (*xFunc)(sqlite_func*,int,const char**); /* Regular function */ + void (*xFunc)(sqlite_func*,int,sqlite3_value**); /* Regular function */ void (*xStep)(sqlite_func*,int,const char**); /* Aggregate function step */ void (*xFinalize)(sqlite_func*); /* Aggregate function finializer */ signed char nArg; /* Number of arguments. -1 means unlimited */ diff --git a/test/bind.test b/test/bind.test index 76b36d6710..cd5c21a0bc 100644 --- a/test/bind.test +++ b/test/bind.test @@ -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.6 2004/05/21 10:08:55 danielk1977 Exp $ +# $Id: bind.test,v 1.7 2004/05/24 12:55:55 danielk1977 Exp $ # set testdir [file dirname $argv0] @@ -92,8 +92,8 @@ do_test bind-2.3 { execsql {SELECT rowid, * FROM t1} } {1 123 456 789 2 123 -2000000000 2000000000} do_test bind-2.4 { - execsql {SELECT classof(a), classof(b), classof(c) FROM t1} -} {INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER} + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {integer integer integer integer integer integer} do_test bind-2.5 { execsql { DELETE FROM t1; @@ -110,8 +110,8 @@ do_test bind-3.1 { execsql {SELECT rowid, * FROM t1} } {1 32 -2000000000000 2000000000000} do_test bind-3.2 { - execsql {SELECT classof(a), classof(b), classof(c) FROM t1} -} {INTEGER INTEGER INTEGER} + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {integer integer integer} do_test bind-3.3 { execsql { DELETE FROM t1; @@ -128,8 +128,8 @@ do_test bind-4.1 { execsql {SELECT rowid, * FROM t1} } {1 1234.1234 1e-05 123456789} do_test bind-4.2 { - execsql {SELECT classof(a), classof(b), classof(c) FROM t1} -} {REAL REAL REAL} + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {real real real} do_test bind-4.3 { execsql { DELETE FROM t1; @@ -146,8 +146,8 @@ do_test bind-5.1 { execsql {SELECT rowid, * FROM t1} } {1 {} {} {}} do_test bind-5.2 { - execsql {SELECT classof(a), classof(b), classof(c) FROM t1} -} {NULL NULL NULL} + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {null null null} do_test bind-5.3 { execsql { DELETE FROM t1; @@ -164,8 +164,8 @@ do_test bind-6.1 { execsql {SELECT rowid, * FROM t1} } {1 hello . world} do_test bind-6.2 { - execsql {SELECT classof(a), classof(b), classof(c) FROM t1} -} {TEXT TEXT TEXT} + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {text text text} do_test bind-6.3 { execsql { DELETE FROM t1; @@ -182,8 +182,8 @@ do_test bind-7.1 { execsql {SELECT rowid, * FROM t1} } {1 hello {} world} do_test bind-7.2 { - execsql {SELECT classof(a), classof(b), classof(c) FROM t1} -} {TEXT TEXT TEXT} + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {text text text} do_test bind-7.3 { execsql { DELETE FROM t1; diff --git a/test/table.test b/test/table.test index 461179c28d..5367ac4046 100644 --- a/test/table.test +++ b/test/table.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing the CREATE TABLE statement. # -# $Id: table.test,v 1.23 2004/05/19 21:09:32 drh Exp $ +# $Id: table.test,v 1.24 2004/05/24 12:55:55 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -473,7 +473,8 @@ do_test table-10.13 { } {1 {unknown column "x" in foreign key definition}} -# Test for the "typeof" function. +# Test for the "typeof" function. More tests for the +# typeof() function are found in bind.test and types.test. # do_test table-11.1 { execsql { @@ -492,12 +493,12 @@ do_test table-11.1 { typeof(e), typeof(f), typeof(g), typeof(h) FROM t7 LIMIT 1; } -} {numeric numeric text text text numeric text numeric} +} {integer null null null null null null null} do_test table-11.2 { execsql { SELECT typeof(a+b), typeof(a||b), typeof(c+d), typeof(c||d) FROM t7 LIMIT 1; } -} {numeric text numeric text} +} {null null null null} finish_test diff --git a/test/types.test b/test/types.test index e37bdb4753..7d9cbb67d4 100644 --- a/test/types.test +++ b/test/types.test @@ -12,7 +12,7 @@ # it tests that the different storage classes (integer, real, text etc.) # all work correctly. # -# $Id: types.test,v 1.5 2004/05/20 12:41:20 drh Exp $ +# $Id: types.test,v 1.6 2004/05/24 12:55:55 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -52,14 +52,14 @@ do_test types-1.1.0 { # literal were inserted into a column with affinity INTEGER, NUMERIC, TEXT # or NONE, respectively. set values { - { 5.0 INTEGER REAL TEXT REAL } - { 5 INTEGER INTEGER TEXT INTEGER } - { '5.0' INTEGER REAL TEXT TEXT } - { '-5.0' INTEGER REAL TEXT TEXT } - { '-5.0' INTEGER REAL TEXT TEXT } - { '5' INTEGER INTEGER TEXT TEXT } - { 'abc' TEXT TEXT TEXT TEXT } - { NULL NULL NULL NULL NULL } + { 5.0 integer real text real } + { 5 integer integer text integer } + { '5.0' integer real text text } + { '-5.0' integer real text text } + { '-5.0' integer real text text } + { '5' integer integer text text } + { 'abc' text text text text } + { NULL null null null null } } # This code tests that the storage classes specified above (in the $values @@ -75,7 +75,7 @@ foreach val $values { execsql "INSERT INTO t1 VALUES($lit, $lit, $lit, $lit);" do_test types-1.1.$tnum { execsql { - SELECT classof(i), classof(n), classof(t), classof(o) FROM t1; + SELECT typeof(i), typeof(n), typeof(t), typeof(o) FROM t1; } } [lrange $val 1 end] incr tnum @@ -94,7 +94,7 @@ foreach val $values { execsql "INSERT INTO t1 SELECT $lit, $lit, $lit, $lit;" do_test types-1.2.$tnum { execsql { - SELECT classof(i), classof(n), classof(t), classof(o) FROM t1; + SELECT typeof(i), typeof(n), typeof(t), typeof(o) FROM t1; } } [lrange $val 1 end] incr tnum @@ -112,7 +112,7 @@ foreach val $values { execsql "UPDATE t1 SET i = $lit, n = $lit, t = $lit, o = $lit;" do_test types-1.3.$tnum { execsql { - SELECT classof(i), classof(n), classof(t), classof(o) FROM t1; + SELECT typeof(i), typeof(n), typeof(t), typeof(o) FROM t1; } } [lrange $val 1 end] incr tnum