Update date/time functions so that they correctly handle NULL arguments. (CVS 1147)

FossilOrigin-Name: a5a5fbd60153dd068ec2559455146e84da075b90
This commit is contained in:
drh 2003-12-23 16:34:12 +00:00
parent 7091cb0566
commit f586aa8b96
4 changed files with 34 additions and 14 deletions

View File

@ -1,5 +1,5 @@
C Add\slocaltime<-->UTC\sconversions\sto\sthe\sdate\sfunctions.\s(CVS\s1146)
D 2003-12-23T16:22:18
C Update\sdate/time\sfunctions\sso\sthat\sthey\scorrectly\shandle\sNULL\sarguments.\s(CVS\s1147)
D 2003-12-23T16:34:13
F Makefile.in 0515ff9218ad8d5a8f6220f0494b8ef94c67013b
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@ -28,7 +28,7 @@ F src/btree.h 9b7c09f1e64274d7bb74a57bbfc63778f67b1048
F src/btree_rb.c e4084b6a12270674b0cd7034655f55e6a2639c78
F src/build.c a7493c433de5b552f9535d8fa7ed80aaf135491e
F src/copy.c 9e47975ea96751c658bcf1a0c4f0bb7c6ee61e73
F src/date.c 1e3318d8450088f235442ca1cddd2601c0c32d1a
F src/date.c a69da8995eec808151f7e82857cbfbc5c70309e3
F src/delete.c 0f81e6799c089487615d38e042a2de4d2d6192bc
F src/encode.c 25ea901a9cefb3d93774afa4a06b57cb58acf544
F src/expr.c a14401a54e5923f3e52b6d04a83813d150f43f33
@ -84,7 +84,7 @@ F test/btree4rb.test ae6f0438512edcb45cf483471cd6070a765963a9
F test/capi2.test ec96e0e235d87b53cbaef3d8e3e0f8ccf32c71ca
F test/conflict.test 0911bb2f079046914a6e9c3341b36658c4e2103e
F test/copy.test 88dabd4e811b17644b726aa81d404e73b7635c84
F test/date.test 510cf3dbc0bc090fc28b2ae1bc290dcd920f5414
F test/date.test 8fe7fab4e901c4bac2572058b3360a59f25d5f14
F test/delete.test 92256384f1801760180ded129f7427884cf28886
F test/expr.test c4cc292d601019c2f2ce95093caaa5d10284b105
F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7
@ -179,7 +179,7 @@ F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3
F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
P c6c5e07b65ae1c30117f0276a1002d5036697cf1
R bb5987106040b561c6e78128774239d9
P 8482b8c44766e7f80fc449b3dbdd3f37396c332b
R 757f37c1931b5323149da11681dc8f61
U drh
Z cdbbb6875dbb4ed10b1b0f72076527c5
Z 97bbf0c2e5044cc3f77063234413c8db

View File

@ -1 +1 @@
8482b8c44766e7f80fc449b3dbdd3f37396c332b
a5a5fbd60153dd068ec2559455146e84da075b90

View File

@ -16,7 +16,7 @@
** sqliteRegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: date.c,v 1.3 2003/12/23 16:22:18 drh Exp $
** $Id: date.c,v 1.4 2003/12/23 16:34:13 drh Exp $
**
** NOTES:
**
@ -620,9 +620,9 @@ static int parseModifier(const char *zMod, DateTime *p){
static int isDate(int argc, const char **argv, DateTime *p){
int i;
if( argc==0 ) return 1;
if( parseDateOrTime(argv[0], p) ) return 1;
if( argv[0]==0 || parseDateOrTime(argv[0], p) ) return 1;
for(i=1; i<argc; i++){
if( parseModifier(argv[i], p) ) return 1;
if( argv[i]==0 || parseModifier(argv[i], p) ) return 1;
}
return 0;
}
@ -718,7 +718,7 @@ static void strftimeFunc(sqlite_func *context, int argc, const char **argv){
char *z;
const char *zFmt = argv[0];
char zBuf[100];
if( isDate(argc-1, argv+1, &x) ) return;
if( argv[0]==0 || isDate(argc-1, argv+1, &x) ) return;
for(i=0, n=1; zFmt[i]; i++, n++){
if( zFmt[i]=='%' ){
switch( zFmt[i+1] ){
@ -834,7 +834,7 @@ void sqliteRegisterDateTimeFunctions(sqlite *db){
#ifndef SQLITE_OMIT_DATETIME_FUNCS
{ "julianday", -1, SQLITE_NUMERIC, juliandayFunc },
{ "date", -1, SQLITE_TEXT, dateFunc },
{ "time", 1, SQLITE_TEXT, timeFunc },
{ "time", -1, SQLITE_TEXT, timeFunc },
{ "datetime", -1, SQLITE_TEXT, datetimeFunc },
{ "strftime", -1, SQLITE_TEXT, strftimeFunc },
#endif

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing date and time functions.
#
# $Id: date.test,v 1.2 2003/12/23 16:22:18 drh Exp $
# $Id: date.test,v 1.3 2003/12/23 16:34:13 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -152,4 +152,24 @@ if {[clock format 0 -format %Z]=="EST"} {
{2039-07-01 07:00:00}
}
# Date-time functions that contain NULL arguments return a NULL
# result.
#
datetest 7.1 {datetime(null)} NULL
datetest 7.2 {datetime('now',null)} NULL
datetest 7.3 {datetime('now','localtime',null)} NULL
datetest 7.4 {time(null)} NULL
datetest 7.5 {time('now',null)} NULL
datetest 7.6 {time('now','localtime',null)} NULL
datetest 7.7 {date(null)} NULL
datetest 7.8 {date('now',null)} NULL
datetest 7.9 {date('now','localtime',null)} NULL
datetest 7.10 {julianday(null)} NULL
datetest 7.11 {julianday('now',null)} NULL
datetest 7.12 {julianday('now','localtime',null)} NULL
datetest 7.13 {strftime(null,'now')} NULL
datetest 7.14 {strftime('%s',null)} NULL
datetest 7.15 {strftime('%s','now',null)} NULL
datetest 7.16 {strftime('%s','now','localtime',null)} NULL
finish_test