/ Check-in [c5435f71]
Login

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

Overview
Comment:Fix a bug in the RTRIM collating sequence discovered while working on condition/decision branch coverage. Increase test coverage of the date/time functions. (CVS 5010)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c5435f71efa0b34c759bac4a15fdf43abf39ddfc
User & Date: drh 2008-04-15 04:02:41
Context
2008-04-15
12:14
Fix a code generator bug caused by the new CSE optimization. Add test cases to prevent a recurrence. (CVS 5011) check-in: d04246a4 user: drh tags: trunk
04:02
Fix a bug in the RTRIM collating sequence discovered while working on condition/decision branch coverage. Increase test coverage of the date/time functions. (CVS 5010) check-in: c5435f71 user: drh tags: trunk
02:36
Add out-of-range tests on the first parameter to sqlite3_limit(). Add the ability to record tests that have been skipped due to configuration limitations. (CVS 5009) check-in: b7ffc6f0 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/main.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.432 2008/04/15 02:36:34 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
#ifdef SQLITE_ENABLE_FTS3
# include "fts3.h"
#endif

................................................................................
#endif


/*
** Return true if the buffer z[0..n-1] contains all spaces.
*/
static int allSpaces(const char *z, int n){
  while( n>0 && z[--n]==' ' ){}
  return n==0;
}

/*
** This is the default collating function named "BINARY" which is always
** available.
**







|







 







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.433 2008/04/15 04:02:41 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
#ifdef SQLITE_ENABLE_FTS3
# include "fts3.h"
#endif

................................................................................
#endif


/*
** Return true if the buffer z[0..n-1] contains all spaces.
*/
static int allSpaces(const char *z, int n){
  while( n>0 && z[n-1]==' ' ){ n--; }
  return n==0;
}

/*
** This is the default collating function named "BINARY" which is always
** available.
**

Changes to test/collateA.test.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
..
73
74
75
76
77
78
79






























80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
109
110
111
112
113
114
115































116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is the built-in RTRIM collating
# API.
#
# $Id: collateA.test,v 1.2 2008/01/21 16:47:16 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test collateA-1.1 {
  execsql {
    CREATE TABLE t1(
      a INTEGER PRIMARY KEY,
      b TEXT COLLATE BINARY,
      c TEXT COLLATE RTRIM
    );
    INSERT INTO t1 VALUES(1, 'hello','hello');
    INSERT INTO t1 VALUES(2, 'xyzzy ','xyzzy ');
    INSERT INTO t1 VALUES(3, 'xyzzy  ','xyzzy  ');
    INSERT INTO t1 VALUES(4, 'xyzzy   ','xyzzy   ');


    SELECT count(*) FROM t1;
  }
} {4}
do_test collateA-1.2 {
  execsql {SELECT a FROM t1 WHERE b='hello     '}
} {}
do_test collateA-1.3 {
  execsql {SELECT a FROM t1 WHERE c='hello     '}
} {1}
do_test collateA-1.4 {
  execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-1.5 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}
................................................................................
} {1 0 0}
do_test collateA-1.15 {
  execsql {SELECT '  '='      ' COLLATE RTRIM, '  '='        '}
} {1 0}
do_test collateA-1.16 {
  execsql {SELECT ''<>'  ' COLLATE RTRIM, ''<>'  ' COLLATE BINARY, ''<>'  '}
} {0 1 1}
































do_test collateA-2.1 {
  execsql {
    CREATE INDEX i1b ON t1(b);
    CREATE INDEX i1c ON t1(c);
    PRAGMA integrity_check;
  }
} {ok}
do_test collateA-2.2 {
  execsql {SELECT a FROM t1 WHERE b='hello     '}
} {}
do_test collateA-2.3 {
  execsql {SELECT a FROM t1 WHERE c='hello     '}
} {1}
do_test collateA-2.4 {
  execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-2.5 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}
................................................................................
} {2 3 4}
do_test collateA-2.9 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy    '}
} {2 3 4}
do_test collateA-2.10 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy                                  '}
} {2 3 4}
































do_test collateA-3.1 {
  db close
  sqlite3 db test.db
  execsql {
    REINDEX;
    PRAGMA integrity_check;
  }
} {ok}
do_test collateA-3.2 {
  execsql {SELECT a FROM t1 WHERE b='hello     '}
} {}
do_test collateA-3.3 {
  execsql {SELECT a FROM t1 WHERE c='hello     '}
} {1}
do_test collateA-3.4 {
  execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-3.5 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}







|











|



>
>


|

|


|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










|


|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










|


|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is the built-in RTRIM collating
# API.
#
# $Id: collateA.test,v 1.3 2008/04/15 04:02:41 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test collateA-1.1 {
  execsql {
    CREATE TABLE t1(
      a INTEGER PRIMARY KEY,
      b TEXT COLLATE BINARY,
      c TEXT COLLATE RTRIM
    );
    INSERT INTO t1 VALUES(1, 'abcde','abcde');
    INSERT INTO t1 VALUES(2, 'xyzzy ','xyzzy ');
    INSERT INTO t1 VALUES(3, 'xyzzy  ','xyzzy  ');
    INSERT INTO t1 VALUES(4, 'xyzzy   ','xyzzy   ');
    INSERT INTO t1 VALUES(5, '   ', '   ');
    INSERT INTO t1 VALUES(6, '', '');
    SELECT count(*) FROM t1;
  }
} {6}
do_test collateA-1.2 {
  execsql {SELECT a FROM t1 WHERE b='abcde     '}
} {}
do_test collateA-1.3 {
  execsql {SELECT a FROM t1 WHERE c='abcde     '}
} {1}
do_test collateA-1.4 {
  execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-1.5 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}
................................................................................
} {1 0 0}
do_test collateA-1.15 {
  execsql {SELECT '  '='      ' COLLATE RTRIM, '  '='        '}
} {1 0}
do_test collateA-1.16 {
  execsql {SELECT ''<>'  ' COLLATE RTRIM, ''<>'  ' COLLATE BINARY, ''<>'  '}
} {0 1 1}
do_test collateA-1.17 {
  execsql {SELECT a FROM t1 WHERE c='xyzz'}
} {}
do_test collateA-1.18 {
  execsql {SELECT a FROM t1 WHERE c='xyzzyy   '}
} {}
do_test collateA-1.19 {
  execsql {SELECT a FROM t1 WHERE c='xyzz   '}
} {}
do_test collateA-1.20 {
  execsql {SELECT a FROM t1 WHERE c='abcd   '}
} {}
do_test collateA-1.21 {
  execsql {SELECT a FROM t1 WHERE c='abcd'}
} {}
do_test collateA-1.22 {
  execsql {SELECT a FROM t1 WHERE c='abc'}
} {}
do_test collateA-1.23 {
  execsql {SELECT a FROM t1 WHERE c='abcdef    '}
} {}
do_test collateA-1.24 {
  execsql {SELECT a FROM t1 WHERE c=''}
} {5 6}
do_test collateA-1.25 {
  execsql {SELECT a FROM t1 WHERE c=' '}
} {5 6}
do_test collateA-1.26 {
  execsql {SELECT a FROM t1 WHERE c='                    '}
} {5 6}


do_test collateA-2.1 {
  execsql {
    CREATE INDEX i1b ON t1(b);
    CREATE INDEX i1c ON t1(c);
    PRAGMA integrity_check;
  }
} {ok}
do_test collateA-2.2 {
  execsql {SELECT a FROM t1 WHERE b='abcde     '}
} {}
do_test collateA-2.3 {
  execsql {SELECT a FROM t1 WHERE c='abcde     '}
} {1}
do_test collateA-2.4 {
  execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-2.5 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}
................................................................................
} {2 3 4}
do_test collateA-2.9 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy    '}
} {2 3 4}
do_test collateA-2.10 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy                                  '}
} {2 3 4}
do_test collateA-2.17 {
  execsql {SELECT a FROM t1 WHERE c='xyzz'}
} {}
do_test collateA-2.18 {
  execsql {SELECT a FROM t1 WHERE c='xyzzyy   '}
} {}
do_test collateA-2.19 {
  execsql {SELECT a FROM t1 WHERE c='xyzz   '}
} {}
do_test collateA-2.20 {
  execsql {SELECT a FROM t1 WHERE c='abcd   '}
} {}
do_test collateA-2.21 {
  execsql {SELECT a FROM t1 WHERE c='abcd'}
} {}
do_test collateA-2.22 {
  execsql {SELECT a FROM t1 WHERE c='abc'}
} {}
do_test collateA-2.23 {
  execsql {SELECT a FROM t1 WHERE c='abcdef    '}
} {}
do_test collateA-2.24 {
  execsql {SELECT a FROM t1 WHERE c=''}
} {5 6}
do_test collateA-2.25 {
  execsql {SELECT a FROM t1 WHERE c=' '}
} {5 6}
do_test collateA-2.26 {
  execsql {SELECT a FROM t1 WHERE c='                    '}
} {5 6}


do_test collateA-3.1 {
  db close
  sqlite3 db test.db
  execsql {
    REINDEX;
    PRAGMA integrity_check;
  }
} {ok}
do_test collateA-3.2 {
  execsql {SELECT a FROM t1 WHERE b='abcde     '}
} {}
do_test collateA-3.3 {
  execsql {SELECT a FROM t1 WHERE c='abcde     '}
} {1}
do_test collateA-3.4 {
  execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-3.5 {
  execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}

Changes to test/date.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
118
119
120
121
122
123
124











125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
...
171
172
173
174
175
176
177






178
179
180
181
182
183
184
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing date and time functions.
#
# $Id: date.test,v 1.25 2008/02/21 20:40:44 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Skip this whole file if date and time functions are omitted
# at compile-time
#
................................................................................
datetest 2.36 {datetime('2003-10-22 12:24','+1 abcdef')} NULL
datetest 2.37 {datetime('2003-10-22 12:24','+1 abcdefg')} NULL
datetest 2.38 {datetime('2003-10-22 12:24','+1 abcdefgh')} NULL
datetest 2.39 {datetime('2003-10-22 12:24','+1 abcdefghi')} NULL
set sqlite_current_time 1199243045
datetest 2.40 {datetime()} {2008-01-02 03:04:05}
set sqlite_current_time 0













datetest 3.1 {strftime('%d','2003-10-31 12:34:56.432')} 31
datetest 3.2.1 {strftime('%f','2003-10-31 12:34:56.432')} 56.432
datetest 3.2.2 {strftime('%f','2003-10-31 12:34:59.9999999')} 59.999
datetest 3.3 {strftime('%H','2003-10-31 12:34:56.432')} 12
datetest 3.4 {strftime('%j','2003-10-31 12:34:56.432')} 304
datetest 3.5 {strftime('%J','2003-10-31 12:34:56.432')} 2452944.02426426
datetest 3.6 {strftime('%m','2003-10-31 12:34:56.432')} 10
datetest 3.7 {strftime('%M','2003-10-31 12:34:56.432')} 34
datetest 3.8 {strftime('%s','2003-10-31 12:34:56.432')} 1067603696
datetest 3.9 {strftime('%S','2003-10-31 12:34:56.432')} 56
datetest 3.10 {strftime('%w','2003-10-31 12:34:56.432')} 5
datetest 3.11.1 {strftime('%W','2003-10-31 12:34:56.432')} 43
datetest 3.11.2 {strftime('%W','2004-01-01')} 00
datetest 3.11.3 {strftime('%W','2004-01-02')} 00
datetest 3.11.4 {strftime('%W','2004-01-03')} 00
datetest 3.11.5 {strftime('%W','2004-01-04')} 00
datetest 3.11.6 {strftime('%W','2004-01-05')} 01
datetest 3.11.7 {strftime('%W','2004-01-06')} 01
datetest 3.11.8 {strftime('%W','2004-01-07')} 01
datetest 3.11.9 {strftime('%W','2004-01-08')} 01
datetest 3.11.10 {strftime('%W','2004-01-09')} 01
datetest 3.11.11 {strftime('%W','2004-07-18')} 28
datetest 3.11.12 {strftime('%W','2004-12-31')} 52
................................................................................
    incr n -1
  }
  return $x
}
datetest 3.16 "strftime('[repeat 200 %Y]','2003-10-31')" [repeat 200 2003]
datetest 3.17 "strftime('[repeat 200 abc%m123]','2003-10-31')" \
    [repeat 200 abc10123]







# Ticket #2276.  Make sure leading zeros are inserted where appropriate.
#
datetest 3.20 \
   {strftime('%d/%f/%H/%W/%j/%m/%M/%S/%Y','0421-01-02 03:04:05.006')} \
   02/05.006/03/00/002/01/04/05/0421








|







 







>
>
>
>
>
>
>
>
>
>
>

<

|













|







 







>
>
>
>
>
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing date and time functions.
#
# $Id: date.test,v 1.26 2008/04/15 04:02:41 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Skip this whole file if date and time functions are omitted
# at compile-time
#
................................................................................
datetest 2.36 {datetime('2003-10-22 12:24','+1 abcdef')} NULL
datetest 2.37 {datetime('2003-10-22 12:24','+1 abcdefg')} NULL
datetest 2.38 {datetime('2003-10-22 12:24','+1 abcdefgh')} NULL
datetest 2.39 {datetime('2003-10-22 12:24','+1 abcdefghi')} NULL
set sqlite_current_time 1199243045
datetest 2.40 {datetime()} {2008-01-02 03:04:05}
set sqlite_current_time 0
datetest 2.41 {datetime('2003-10-22 12:24','23 seconds')} {2003-10-22 12:24:23}
datetest 2.42 {datetime('2003-10-22 12:24','345 second')} {2003-10-22 12:29:45}
datetest 2.43 {datetime('2003-10-22 12:24','4 second')} {2003-10-22 12:24:04}
datetest 2.44 {datetime('2003-10-22 12:24','56 second')} {2003-10-22 12:24:56}
datetest 2.45 {datetime('2003-10-22 12:24','60 second')} {2003-10-22 12:25:00}
datetest 2.46 {datetime('2003-10-22 12:24','70 second')} {2003-10-22 12:25:10}
datetest 2.47 {datetime('2003-10-22 12:24','8.6 seconds')} {2003-10-22 12:24:08}
datetest 2.48 {datetime('2003-10-22 12:24','9.4 second')} {2003-10-22 12:24:09}
datetest 2.49 {datetime('2003-10-22 12:24','0000 second')} {2003-10-22 12:24:00}
datetest 2.50 {datetime('2003-10-22 12:24','0001 second')} {2003-10-22 12:24:01}
datetest 2.51 {datetime('2003-10-22 12:24','nonsense')} NULL


datetest 3.1 {strftime('%d','2003-10-31 12:34:56.432')} 31
datetest 3.2.1 {strftime('pre%fpost','2003-10-31 12:34:56.432')} pre56.432post
datetest 3.2.2 {strftime('%f','2003-10-31 12:34:59.9999999')} 59.999
datetest 3.3 {strftime('%H','2003-10-31 12:34:56.432')} 12
datetest 3.4 {strftime('%j','2003-10-31 12:34:56.432')} 304
datetest 3.5 {strftime('%J','2003-10-31 12:34:56.432')} 2452944.02426426
datetest 3.6 {strftime('%m','2003-10-31 12:34:56.432')} 10
datetest 3.7 {strftime('%M','2003-10-31 12:34:56.432')} 34
datetest 3.8 {strftime('%s','2003-10-31 12:34:56.432')} 1067603696
datetest 3.9 {strftime('%S','2003-10-31 12:34:56.432')} 56
datetest 3.10 {strftime('%w','2003-10-31 12:34:56.432')} 5
datetest 3.11.1 {strftime('%W','2003-10-31 12:34:56.432')} 43
datetest 3.11.2 {strftime('%W','2004-01-01')} 00
datetest 3.11.3 {strftime('%W','2004-01-02')} 00
datetest 3.11.4 {strftime('%W','2004-01-03')} 00
datetest 3.11.5 {strftime('abc%Wxyz','2004-01-04')} abc00xyz
datetest 3.11.6 {strftime('%W','2004-01-05')} 01
datetest 3.11.7 {strftime('%W','2004-01-06')} 01
datetest 3.11.8 {strftime('%W','2004-01-07')} 01
datetest 3.11.9 {strftime('%W','2004-01-08')} 01
datetest 3.11.10 {strftime('%W','2004-01-09')} 01
datetest 3.11.11 {strftime('%W','2004-07-18')} 28
datetest 3.11.12 {strftime('%W','2004-12-31')} 52
................................................................................
    incr n -1
  }
  return $x
}
datetest 3.16 "strftime('[repeat 200 %Y]','2003-10-31')" [repeat 200 2003]
datetest 3.17 "strftime('[repeat 200 abc%m123]','2003-10-31')" \
    [repeat 200 abc10123]

foreach c {a b c e g h i k l n o p q r t v x y z
           A B C D E F G I K L N O P Q R T U V Z
           0 1 2 3 4 5 6 6 7 9 _} {
  datetest 3.18.$c "strftime('%$c','2003-10-31')" NULL
}

# Ticket #2276.  Make sure leading zeros are inserted where appropriate.
#
datetest 3.20 \
   {strftime('%d/%f/%H/%W/%j/%m/%M/%S/%Y','0421-01-02 03:04:05.006')} \
   02/05.006/03/00/002/01/04/05/0421