blob: c90543ff519bbb4ccd617ece014a62aa5d6a75a1 [file] [log] [blame]
drh7014aff2003-11-01 01:53:53 +00001/*
2** 2003 October 31
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12** This file contains the C functions that implement date and time
13** functions for SQLite.
14**
15** There is only one exported symbol in this file - the function
danielk19774adee202004-05-08 08:23:19 +000016** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
drh7014aff2003-11-01 01:53:53 +000017** All other code has file scope.
18**
shaneb8109ad2008-05-27 19:49:21 +000019** $Id: date.c,v 1.80 2008/05/27 19:49:21 shane Exp $
drh7014aff2003-11-01 01:53:53 +000020**
21** SQLite processes all times and dates as Julian Day numbers. The
22** dates and times are stored as the number of days since noon
23** in Greenwich on November 24, 4714 B.C. according to the Gregorian
drh7f986a62006-09-25 18:05:04 +000024** calendar system.
drh7014aff2003-11-01 01:53:53 +000025**
26** 1970-01-01 00:00:00 is JD 2440587.5
27** 2000-01-01 00:00:00 is JD 2451544.5
28**
29** This implemention requires years to be expressed as a 4-digit number
30** which means that only dates between 0000-01-01 and 9999-12-31 can
31** be represented, even though julian day numbers allow a much wider
32** range of dates.
33**
34** The Gregorian calendar system is used for all dates and times,
35** even those that predate the Gregorian calendar. Historians usually
36** use the Julian calendar for dates prior to 1582-10-15 and for some
37** dates afterwards, depending on locale. Beware of this difference.
38**
39** The conversion algorithms are implemented based on descriptions
40** in the following text:
41**
42** Jean Meeus
43** Astronomical Algorithms, 2nd Edition, 1998
44** ISBM 0-943396-61-1
45** Willmann-Bell, Inc
46** Richmond, Virginia (USA)
47*/
dougcurrieae534182003-12-24 01:41:19 +000048#include "sqliteInt.h"
drh7014aff2003-11-01 01:53:53 +000049#include <ctype.h>
50#include <stdlib.h>
51#include <assert.h>
drh7091cb02003-12-23 16:22:18 +000052#include <time.h>
drh7014aff2003-11-01 01:53:53 +000053
drh4bc05852004-02-10 13:19:35 +000054#ifndef SQLITE_OMIT_DATETIME_FUNCS
55
drh7014aff2003-11-01 01:53:53 +000056/*
shaneb8109ad2008-05-27 19:49:21 +000057** On recent Windows platforms, the localtime_s() function is available
58** as part of the "Secure CRT". It is essentially equivalent to
59** localtime_r() available under most POSIX platforms, except that the
60** order of the parameters is reversed.
61**
62** See http://msdn.microsoft.com/en-us/library/a442x3ye(VS.80).aspx.
63**
64** If the user has not indicated to use localtime_r() or localtime_s()
65** already, check for an MSVC build environment that provides
66** localtime_s().
67*/
68#if !defined(HAVE_LOCALTIME_R) && !defined(HAVE_LOCALTIME_S) && \
69 defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
70#define HAVE_LOCALTIME_S 1
71#endif
72
73/*
drh7014aff2003-11-01 01:53:53 +000074** A structure for holding a single date and time.
75*/
76typedef struct DateTime DateTime;
77struct DateTime {
78 double rJD; /* The julian day number */
79 int Y, M, D; /* Year, month, and day */
80 int h, m; /* Hour and minutes */
81 int tz; /* Timezone offset in minutes */
82 double s; /* Seconds */
83 char validYMD; /* True if Y,M,D are valid */
84 char validHMS; /* True if h,m,s are valid */
85 char validJD; /* True if rJD is valid */
86 char validTZ; /* True if tz is valid */
87};
88
89
90/*
drheb9a9e82004-02-22 17:49:32 +000091** Convert zDate into one or more integers. Additional arguments
92** come in groups of 5 as follows:
93**
94** N number of digits in the integer
95** min minimum allowed value of the integer
96** max maximum allowed value of the integer
97** nextC first character after the integer
98** pVal where to write the integers value.
99**
100** Conversions continue until one with nextC==0 is encountered.
101** The function returns the number of successful conversions.
drh7014aff2003-11-01 01:53:53 +0000102*/
drheb9a9e82004-02-22 17:49:32 +0000103static int getDigits(const char *zDate, ...){
104 va_list ap;
105 int val;
106 int N;
107 int min;
108 int max;
109 int nextC;
110 int *pVal;
111 int cnt = 0;
112 va_start(ap, zDate);
113 do{
114 N = va_arg(ap, int);
115 min = va_arg(ap, int);
116 max = va_arg(ap, int);
117 nextC = va_arg(ap, int);
118 pVal = va_arg(ap, int*);
119 val = 0;
120 while( N-- ){
drh4c755c02004-08-08 20:22:17 +0000121 if( !isdigit(*(u8*)zDate) ){
drh029b44b2006-01-15 00:13:15 +0000122 goto end_getDigits;
drheb9a9e82004-02-22 17:49:32 +0000123 }
124 val = val*10 + *zDate - '0';
125 zDate++;
126 }
127 if( val<min || val>max || (nextC!=0 && nextC!=*zDate) ){
drh029b44b2006-01-15 00:13:15 +0000128 goto end_getDigits;
drheb9a9e82004-02-22 17:49:32 +0000129 }
130 *pVal = val;
drh7014aff2003-11-01 01:53:53 +0000131 zDate++;
drheb9a9e82004-02-22 17:49:32 +0000132 cnt++;
133 }while( nextC );
drh029b44b2006-01-15 00:13:15 +0000134end_getDigits:
drh15b9a152006-01-31 20:49:13 +0000135 va_end(ap);
drheb9a9e82004-02-22 17:49:32 +0000136 return cnt;
drh7014aff2003-11-01 01:53:53 +0000137}
138
139/*
140** Read text from z[] and convert into a floating point number. Return
141** the number of digits converted.
142*/
drh487e2622005-06-25 18:42:14 +0000143#define getValue sqlite3AtoF
drh7014aff2003-11-01 01:53:53 +0000144
145/*
146** Parse a timezone extension on the end of a date-time.
147** The extension is of the form:
148**
149** (+/-)HH:MM
150**
drh1cfdc902008-02-21 20:40:43 +0000151** Or the "zulu" notation:
152**
153** Z
154**
drh7014aff2003-11-01 01:53:53 +0000155** If the parse is successful, write the number of minutes
drh1cfdc902008-02-21 20:40:43 +0000156** of change in p->tz and return 0. If a parser error occurs,
157** return non-zero.
drh7014aff2003-11-01 01:53:53 +0000158**
159** A missing specifier is not considered an error.
160*/
161static int parseTimezone(const char *zDate, DateTime *p){
162 int sgn = 0;
163 int nHr, nMn;
drh1cfdc902008-02-21 20:40:43 +0000164 int c;
drh4c755c02004-08-08 20:22:17 +0000165 while( isspace(*(u8*)zDate) ){ zDate++; }
drh7014aff2003-11-01 01:53:53 +0000166 p->tz = 0;
drh1cfdc902008-02-21 20:40:43 +0000167 c = *zDate;
168 if( c=='-' ){
drh7014aff2003-11-01 01:53:53 +0000169 sgn = -1;
drh1cfdc902008-02-21 20:40:43 +0000170 }else if( c=='+' ){
drh7014aff2003-11-01 01:53:53 +0000171 sgn = +1;
drh1cfdc902008-02-21 20:40:43 +0000172 }else if( c=='Z' || c=='z' ){
173 zDate++;
174 goto zulu_time;
drh7014aff2003-11-01 01:53:53 +0000175 }else{
drh1cfdc902008-02-21 20:40:43 +0000176 return c!=0;
drh7014aff2003-11-01 01:53:53 +0000177 }
178 zDate++;
drheb9a9e82004-02-22 17:49:32 +0000179 if( getDigits(zDate, 2, 0, 14, ':', &nHr, 2, 0, 59, 0, &nMn)!=2 ){
180 return 1;
181 }
182 zDate += 5;
drh7014aff2003-11-01 01:53:53 +0000183 p->tz = sgn*(nMn + nHr*60);
drh1cfdc902008-02-21 20:40:43 +0000184zulu_time:
drh4c755c02004-08-08 20:22:17 +0000185 while( isspace(*(u8*)zDate) ){ zDate++; }
drh7014aff2003-11-01 01:53:53 +0000186 return *zDate!=0;
187}
188
189/*
190** Parse times of the form HH:MM or HH:MM:SS or HH:MM:SS.FFFF.
191** The HH, MM, and SS must each be exactly 2 digits. The
192** fractional seconds FFFF can be one or more digits.
193**
194** Return 1 if there is a parsing error and 0 on success.
195*/
196static int parseHhMmSs(const char *zDate, DateTime *p){
197 int h, m, s;
198 double ms = 0.0;
drheb9a9e82004-02-22 17:49:32 +0000199 if( getDigits(zDate, 2, 0, 24, ':', &h, 2, 0, 59, 0, &m)!=2 ){
200 return 1;
201 }
202 zDate += 5;
drh7014aff2003-11-01 01:53:53 +0000203 if( *zDate==':' ){
drheb9a9e82004-02-22 17:49:32 +0000204 zDate++;
205 if( getDigits(zDate, 2, 0, 59, 0, &s)!=1 ){
206 return 1;
207 }
208 zDate += 2;
drh4c755c02004-08-08 20:22:17 +0000209 if( *zDate=='.' && isdigit((u8)zDate[1]) ){
drh7014aff2003-11-01 01:53:53 +0000210 double rScale = 1.0;
211 zDate++;
drh4c755c02004-08-08 20:22:17 +0000212 while( isdigit(*(u8*)zDate) ){
drh7014aff2003-11-01 01:53:53 +0000213 ms = ms*10.0 + *zDate - '0';
214 rScale *= 10.0;
215 zDate++;
216 }
217 ms /= rScale;
218 }
219 }else{
220 s = 0;
221 }
222 p->validJD = 0;
223 p->validHMS = 1;
224 p->h = h;
225 p->m = m;
226 p->s = s + ms;
227 if( parseTimezone(zDate, p) ) return 1;
228 p->validTZ = p->tz!=0;
229 return 0;
230}
231
232/*
233** Convert from YYYY-MM-DD HH:MM:SS to julian day. We always assume
234** that the YYYY-MM-DD is according to the Gregorian calendar.
235**
236** Reference: Meeus page 61
237*/
238static void computeJD(DateTime *p){
239 int Y, M, D, A, B, X1, X2;
240
241 if( p->validJD ) return;
242 if( p->validYMD ){
243 Y = p->Y;
244 M = p->M;
245 D = p->D;
246 }else{
drhba212562004-01-08 02:17:31 +0000247 Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */
drh7014aff2003-11-01 01:53:53 +0000248 M = 1;
249 D = 1;
250 }
251 if( M<=2 ){
252 Y--;
253 M += 12;
254 }
255 A = Y/100;
256 B = 2 - A + (A/4);
257 X1 = 365.25*(Y+4716);
258 X2 = 30.6001*(M+1);
259 p->rJD = X1 + X2 + D + B - 1524.5;
260 p->validJD = 1;
drh7014aff2003-11-01 01:53:53 +0000261 if( p->validHMS ){
262 p->rJD += (p->h*3600.0 + p->m*60.0 + p->s)/86400.0;
263 if( p->validTZ ){
drh57391032006-01-09 00:18:02 +0000264 p->rJD -= p->tz*60/86400.0;
drhf11c34d2006-09-08 12:27:36 +0000265 p->validYMD = 0;
drh7014aff2003-11-01 01:53:53 +0000266 p->validHMS = 0;
267 p->validTZ = 0;
268 }
269 }
270}
271
272/*
273** Parse dates of the form
274**
275** YYYY-MM-DD HH:MM:SS.FFF
276** YYYY-MM-DD HH:MM:SS
277** YYYY-MM-DD HH:MM
278** YYYY-MM-DD
279**
280** Write the result into the DateTime structure and return 0
281** on success and 1 if the input string is not a well-formed
282** date.
283*/
284static int parseYyyyMmDd(const char *zDate, DateTime *p){
drh8eb2cce2004-02-21 03:28:18 +0000285 int Y, M, D, neg;
drh7014aff2003-11-01 01:53:53 +0000286
drh8eb2cce2004-02-21 03:28:18 +0000287 if( zDate[0]=='-' ){
288 zDate++;
289 neg = 1;
290 }else{
291 neg = 0;
292 }
drheb9a9e82004-02-22 17:49:32 +0000293 if( getDigits(zDate,4,0,9999,'-',&Y,2,1,12,'-',&M,2,1,31,0,&D)!=3 ){
294 return 1;
295 }
296 zDate += 10;
drh4cb29b42005-03-21 00:43:44 +0000297 while( isspace(*(u8*)zDate) || 'T'==*(u8*)zDate ){ zDate++; }
drheb9a9e82004-02-22 17:49:32 +0000298 if( parseHhMmSs(zDate, p)==0 ){
299 /* We got the time */
drh7014aff2003-11-01 01:53:53 +0000300 }else if( *zDate==0 ){
301 p->validHMS = 0;
302 }else{
303 return 1;
304 }
305 p->validJD = 0;
306 p->validYMD = 1;
drh8eb2cce2004-02-21 03:28:18 +0000307 p->Y = neg ? -Y : Y;
drh7014aff2003-11-01 01:53:53 +0000308 p->M = M;
309 p->D = D;
310 if( p->validTZ ){
311 computeJD(p);
312 }
313 return 0;
314}
315
316/*
317** Attempt to parse the given string into a Julian Day Number. Return
318** the number of errors.
319**
320** The following are acceptable forms for the input string:
321**
322** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
323** DDDD.DD
324** now
325**
326** In the first form, the +/-HH:MM is always optional. The fractional
327** seconds extension (the ".FFF") is optional. The seconds portion
328** (":SS.FFF") is option. The year and date can be omitted as long
329** as there is a time string. The time string can be omitted as long
330** as there is a year and date.
331*/
danielk1977fee2d252007-08-18 10:59:19 +0000332static int parseDateOrTime(
333 sqlite3_context *context,
334 const char *zDate,
335 DateTime *p
336){
drh7014aff2003-11-01 01:53:53 +0000337 memset(p, 0, sizeof(*p));
drh8eb2cce2004-02-21 03:28:18 +0000338 if( parseYyyyMmDd(zDate,p)==0 ){
drh7014aff2003-11-01 01:53:53 +0000339 return 0;
drh8eb2cce2004-02-21 03:28:18 +0000340 }else if( parseHhMmSs(zDate, p)==0 ){
341 return 0;
danielk19774adee202004-05-08 08:23:19 +0000342 }else if( sqlite3StrICmp(zDate,"now")==0){
drh7014aff2003-11-01 01:53:53 +0000343 double r;
drhfa4a4b92008-03-19 21:45:51 +0000344 sqlite3 *db = sqlite3_context_db_handle(context);
345 sqlite3OsCurrentTime(db->pVfs, &r);
drh018d1a42005-01-15 01:52:31 +0000346 p->rJD = r;
347 p->validJD = 1;
348 return 0;
danielk1977dc8453f2004-06-12 00:42:34 +0000349 }else if( sqlite3IsNumber(zDate, 0, SQLITE_UTF8) ){
drh487e2622005-06-25 18:42:14 +0000350 getValue(zDate, &p->rJD);
drh7014aff2003-11-01 01:53:53 +0000351 p->validJD = 1;
352 return 0;
353 }
354 return 1;
355}
356
357/*
358** Compute the Year, Month, and Day from the julian day number.
359*/
360static void computeYMD(DateTime *p){
361 int Z, A, B, C, D, E, X1;
362 if( p->validYMD ) return;
drh33a9ad22004-02-29 00:40:32 +0000363 if( !p->validJD ){
364 p->Y = 2000;
365 p->M = 1;
366 p->D = 1;
367 }else{
368 Z = p->rJD + 0.5;
369 A = (Z - 1867216.25)/36524.25;
370 A = Z + 1 + A - (A/4);
371 B = A + 1524;
372 C = (B - 122.1)/365.25;
373 D = 365.25*C;
374 E = (B-D)/30.6001;
375 X1 = 30.6001*E;
376 p->D = B - D - X1;
377 p->M = E<14 ? E-1 : E-13;
378 p->Y = p->M>2 ? C - 4716 : C - 4715;
379 }
drh7014aff2003-11-01 01:53:53 +0000380 p->validYMD = 1;
381}
382
383/*
384** Compute the Hour, Minute, and Seconds from the julian day number.
385*/
386static void computeHMS(DateTime *p){
387 int Z, s;
388 if( p->validHMS ) return;
drhf11c34d2006-09-08 12:27:36 +0000389 computeJD(p);
drh7014aff2003-11-01 01:53:53 +0000390 Z = p->rJD + 0.5;
391 s = (p->rJD + 0.5 - Z)*86400000.0 + 0.5;
392 p->s = 0.001*s;
393 s = p->s;
394 p->s -= s;
395 p->h = s/3600;
396 s -= p->h*3600;
397 p->m = s/60;
398 p->s += s - p->m*60;
399 p->validHMS = 1;
400}
401
402/*
drhba212562004-01-08 02:17:31 +0000403** Compute both YMD and HMS
404*/
405static void computeYMD_HMS(DateTime *p){
406 computeYMD(p);
407 computeHMS(p);
408}
409
410/*
411** Clear the YMD and HMS and the TZ
412*/
413static void clearYMD_HMS_TZ(DateTime *p){
414 p->validYMD = 0;
415 p->validHMS = 0;
416 p->validTZ = 0;
417}
418
419/*
drh7091cb02003-12-23 16:22:18 +0000420** Compute the difference (in days) between localtime and UTC (a.k.a. GMT)
421** for the time value p where p is in UTC.
422*/
423static double localtimeOffset(DateTime *p){
424 DateTime x, y;
425 time_t t;
drh7091cb02003-12-23 16:22:18 +0000426 x = *p;
drhba212562004-01-08 02:17:31 +0000427 computeYMD_HMS(&x);
drh7091cb02003-12-23 16:22:18 +0000428 if( x.Y<1971 || x.Y>=2038 ){
429 x.Y = 2000;
430 x.M = 1;
431 x.D = 1;
432 x.h = 0;
433 x.m = 0;
434 x.s = 0.0;
435 } else {
436 int s = x.s + 0.5;
437 x.s = s;
438 }
439 x.tz = 0;
440 x.validJD = 0;
441 computeJD(&x);
442 t = (x.rJD-2440587.5)*86400.0 + 0.5;
drh87595762006-09-08 12:49:43 +0000443#ifdef HAVE_LOCALTIME_R
444 {
445 struct tm sLocal;
446 localtime_r(&t, &sLocal);
447 y.Y = sLocal.tm_year + 1900;
448 y.M = sLocal.tm_mon + 1;
449 y.D = sLocal.tm_mday;
450 y.h = sLocal.tm_hour;
451 y.m = sLocal.tm_min;
452 y.s = sLocal.tm_sec;
453 }
shaneb8109ad2008-05-27 19:49:21 +0000454#elif defined(HAVE_LOCALTIME_S)
455 {
456 struct tm sLocal;
457 localtime_s(&sLocal, &t);
458 y.Y = sLocal.tm_year + 1900;
459 y.M = sLocal.tm_mon + 1;
460 y.D = sLocal.tm_mday;
461 y.h = sLocal.tm_hour;
462 y.m = sLocal.tm_min;
463 y.s = sLocal.tm_sec;
464 }
drh87595762006-09-08 12:49:43 +0000465#else
466 {
467 struct tm *pTm;
drh153c62c2007-08-24 03:51:33 +0000468 sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
drh87595762006-09-08 12:49:43 +0000469 pTm = localtime(&t);
470 y.Y = pTm->tm_year + 1900;
471 y.M = pTm->tm_mon + 1;
472 y.D = pTm->tm_mday;
473 y.h = pTm->tm_hour;
474 y.m = pTm->tm_min;
475 y.s = pTm->tm_sec;
drh153c62c2007-08-24 03:51:33 +0000476 sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
drh87595762006-09-08 12:49:43 +0000477 }
478#endif
drh7091cb02003-12-23 16:22:18 +0000479 y.validYMD = 1;
480 y.validHMS = 1;
481 y.validJD = 0;
482 y.validTZ = 0;
483 computeJD(&y);
drh7091cb02003-12-23 16:22:18 +0000484 return y.rJD - x.rJD;
485}
486
487/*
drh7014aff2003-11-01 01:53:53 +0000488** Process a modifier to a date-time stamp. The modifiers are
489** as follows:
490**
491** NNN days
492** NNN hours
493** NNN minutes
494** NNN.NNNN seconds
495** NNN months
496** NNN years
497** start of month
498** start of year
499** start of week
500** start of day
501** weekday N
502** unixepoch
drh7091cb02003-12-23 16:22:18 +0000503** localtime
504** utc
drh7014aff2003-11-01 01:53:53 +0000505**
506** Return 0 on success and 1 if there is any kind of error.
507*/
508static int parseModifier(const char *zMod, DateTime *p){
509 int rc = 1;
510 int n;
511 double r;
drh4d5b8362004-01-17 01:16:21 +0000512 char *z, zBuf[30];
513 z = zBuf;
514 for(n=0; n<sizeof(zBuf)-1 && zMod[n]; n++){
drh7014aff2003-11-01 01:53:53 +0000515 z[n] = tolower(zMod[n]);
516 }
517 z[n] = 0;
518 switch( z[0] ){
drh7091cb02003-12-23 16:22:18 +0000519 case 'l': {
520 /* localtime
521 **
522 ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
523 ** show local time.
524 */
525 if( strcmp(z, "localtime")==0 ){
526 computeJD(p);
527 p->rJD += localtimeOffset(p);
drhba212562004-01-08 02:17:31 +0000528 clearYMD_HMS_TZ(p);
drh7091cb02003-12-23 16:22:18 +0000529 rc = 0;
530 }
531 break;
532 }
drh7014aff2003-11-01 01:53:53 +0000533 case 'u': {
534 /*
535 ** unixepoch
536 **
537 ** Treat the current value of p->rJD as the number of
538 ** seconds since 1970. Convert to a real julian day number.
539 */
540 if( strcmp(z, "unixepoch")==0 && p->validJD ){
541 p->rJD = p->rJD/86400.0 + 2440587.5;
drhba212562004-01-08 02:17:31 +0000542 clearYMD_HMS_TZ(p);
drh7014aff2003-11-01 01:53:53 +0000543 rc = 0;
drh7091cb02003-12-23 16:22:18 +0000544 }else if( strcmp(z, "utc")==0 ){
545 double c1;
546 computeJD(p);
547 c1 = localtimeOffset(p);
548 p->rJD -= c1;
drhba212562004-01-08 02:17:31 +0000549 clearYMD_HMS_TZ(p);
drh7091cb02003-12-23 16:22:18 +0000550 p->rJD += c1 - localtimeOffset(p);
drh7091cb02003-12-23 16:22:18 +0000551 rc = 0;
drh7014aff2003-11-01 01:53:53 +0000552 }
553 break;
554 }
555 case 'w': {
556 /*
557 ** weekday N
558 **
drh181fc992004-08-17 10:42:54 +0000559 ** Move the date to the same time on the next occurrence of
drh7014aff2003-11-01 01:53:53 +0000560 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the
drhc5dd9fa2004-01-07 03:29:16 +0000561 ** date is already on the appropriate weekday, this is a no-op.
drh7014aff2003-11-01 01:53:53 +0000562 */
563 if( strncmp(z, "weekday ", 8)==0 && getValue(&z[8],&r)>0
564 && (n=r)==r && n>=0 && r<7 ){
565 int Z;
drhba212562004-01-08 02:17:31 +0000566 computeYMD_HMS(p);
drh7014aff2003-11-01 01:53:53 +0000567 p->validTZ = 0;
568 p->validJD = 0;
569 computeJD(p);
570 Z = p->rJD + 1.5;
571 Z %= 7;
572 if( Z>n ) Z -= 7;
573 p->rJD += n - Z;
drhba212562004-01-08 02:17:31 +0000574 clearYMD_HMS_TZ(p);
drh7014aff2003-11-01 01:53:53 +0000575 rc = 0;
576 }
577 break;
578 }
579 case 's': {
580 /*
581 ** start of TTTTT
582 **
583 ** Move the date backwards to the beginning of the current day,
584 ** or month or year.
585 */
586 if( strncmp(z, "start of ", 9)!=0 ) break;
drh4d5b8362004-01-17 01:16:21 +0000587 z += 9;
drh7014aff2003-11-01 01:53:53 +0000588 computeYMD(p);
589 p->validHMS = 1;
590 p->h = p->m = 0;
591 p->s = 0.0;
592 p->validTZ = 0;
593 p->validJD = 0;
drh4d5b8362004-01-17 01:16:21 +0000594 if( strcmp(z,"month")==0 ){
drh7014aff2003-11-01 01:53:53 +0000595 p->D = 1;
596 rc = 0;
drh4d5b8362004-01-17 01:16:21 +0000597 }else if( strcmp(z,"year")==0 ){
drh7014aff2003-11-01 01:53:53 +0000598 computeYMD(p);
599 p->M = 1;
600 p->D = 1;
601 rc = 0;
drh4d5b8362004-01-17 01:16:21 +0000602 }else if( strcmp(z,"day")==0 ){
drh7014aff2003-11-01 01:53:53 +0000603 rc = 0;
604 }
605 break;
606 }
607 case '+':
608 case '-':
609 case '0':
610 case '1':
611 case '2':
612 case '3':
613 case '4':
614 case '5':
615 case '6':
616 case '7':
617 case '8':
618 case '9': {
619 n = getValue(z, &r);
drh05f7c192007-04-06 02:32:33 +0000620 assert( n>=1 );
drh33a9ad22004-02-29 00:40:32 +0000621 if( z[n]==':' ){
622 /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
623 ** specified number of hours, minutes, seconds, and fractional seconds
624 ** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
625 ** omitted.
626 */
627 const char *z2 = z;
628 DateTime tx;
629 int day;
drh4c755c02004-08-08 20:22:17 +0000630 if( !isdigit(*(u8*)z2) ) z2++;
drh33a9ad22004-02-29 00:40:32 +0000631 memset(&tx, 0, sizeof(tx));
632 if( parseHhMmSs(z2, &tx) ) break;
633 computeJD(&tx);
drh0d131ab2004-02-29 01:08:17 +0000634 tx.rJD -= 0.5;
drh33a9ad22004-02-29 00:40:32 +0000635 day = (int)tx.rJD;
drhb6829e92004-02-29 00:50:33 +0000636 tx.rJD -= day;
drhb6829e92004-02-29 00:50:33 +0000637 if( z[0]=='-' ) tx.rJD = -tx.rJD;
drh0d131ab2004-02-29 01:08:17 +0000638 computeJD(p);
639 clearYMD_HMS_TZ(p);
drhf11c34d2006-09-08 12:27:36 +0000640 p->rJD += tx.rJD;
drh33a9ad22004-02-29 00:40:32 +0000641 rc = 0;
642 break;
643 }
drh4d5b8362004-01-17 01:16:21 +0000644 z += n;
drh4c755c02004-08-08 20:22:17 +0000645 while( isspace(*(u8*)z) ) z++;
drh4d5b8362004-01-17 01:16:21 +0000646 n = strlen(z);
drh7014aff2003-11-01 01:53:53 +0000647 if( n>10 || n<3 ) break;
drh7014aff2003-11-01 01:53:53 +0000648 if( z[n-1]=='s' ){ z[n-1] = 0; n--; }
649 computeJD(p);
650 rc = 0;
651 if( n==3 && strcmp(z,"day")==0 ){
652 p->rJD += r;
653 }else if( n==4 && strcmp(z,"hour")==0 ){
drh7014aff2003-11-01 01:53:53 +0000654 p->rJD += r/24.0;
655 }else if( n==6 && strcmp(z,"minute")==0 ){
drh7014aff2003-11-01 01:53:53 +0000656 p->rJD += r/(24.0*60.0);
657 }else if( n==6 && strcmp(z,"second")==0 ){
drh7014aff2003-11-01 01:53:53 +0000658 p->rJD += r/(24.0*60.0*60.0);
659 }else if( n==5 && strcmp(z,"month")==0 ){
660 int x, y;
drhba212562004-01-08 02:17:31 +0000661 computeYMD_HMS(p);
drh7014aff2003-11-01 01:53:53 +0000662 p->M += r;
663 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
664 p->Y += x;
665 p->M -= x*12;
666 p->validJD = 0;
667 computeJD(p);
668 y = r;
669 if( y!=r ){
670 p->rJD += (r - y)*30.0;
671 }
672 }else if( n==4 && strcmp(z,"year")==0 ){
drhba212562004-01-08 02:17:31 +0000673 computeYMD_HMS(p);
drh7014aff2003-11-01 01:53:53 +0000674 p->Y += r;
675 p->validJD = 0;
676 computeJD(p);
677 }else{
678 rc = 1;
679 }
drhba212562004-01-08 02:17:31 +0000680 clearYMD_HMS_TZ(p);
drh7014aff2003-11-01 01:53:53 +0000681 break;
682 }
683 default: {
684 break;
685 }
686 }
687 return rc;
688}
689
690/*
691** Process time function arguments. argv[0] is a date-time stamp.
692** argv[1] and following are modifiers. Parse them all and write
693** the resulting time into the DateTime structure p. Return 0
694** on success and 1 if there are any errors.
drh008e4762008-01-17 22:27:53 +0000695**
696** If there are zero parameters (if even argv[0] is undefined)
697** then assume a default value of "now" for argv[0].
drh7014aff2003-11-01 01:53:53 +0000698*/
danielk1977fee2d252007-08-18 10:59:19 +0000699static int isDate(
700 sqlite3_context *context,
701 int argc,
702 sqlite3_value **argv,
703 DateTime *p
704){
drh7014aff2003-11-01 01:53:53 +0000705 int i;
drh7a521cf2007-04-25 18:23:52 +0000706 const unsigned char *z;
drh008e4762008-01-17 22:27:53 +0000707 static const unsigned char zDflt[] = "now";
708 if( argc==0 ){
709 z = zDflt;
710 }else{
711 z = sqlite3_value_text(argv[0]);
712 }
danielk1977fee2d252007-08-18 10:59:19 +0000713 if( !z || parseDateOrTime(context, (char*)z, p) ){
drh7a521cf2007-04-25 18:23:52 +0000714 return 1;
715 }
drh7014aff2003-11-01 01:53:53 +0000716 for(i=1; i<argc; i++){
drh7a521cf2007-04-25 18:23:52 +0000717 if( (z = sqlite3_value_text(argv[i]))==0 || parseModifier((char*)z, p) ){
718 return 1;
719 }
drh7014aff2003-11-01 01:53:53 +0000720 }
721 return 0;
722}
723
724
725/*
726** The following routines implement the various date and time functions
727** of SQLite.
728*/
729
730/*
731** julianday( TIMESTRING, MOD, MOD, ...)
732**
733** Return the julian day number of the date specified in the arguments
734*/
drhf9b596e2004-05-26 16:54:42 +0000735static void juliandayFunc(
736 sqlite3_context *context,
737 int argc,
738 sqlite3_value **argv
739){
drh7014aff2003-11-01 01:53:53 +0000740 DateTime x;
danielk1977fee2d252007-08-18 10:59:19 +0000741 if( isDate(context, argc, argv, &x)==0 ){
drh7014aff2003-11-01 01:53:53 +0000742 computeJD(&x);
danielk19777e18c252004-05-25 11:47:24 +0000743 sqlite3_result_double(context, x.rJD);
drh7014aff2003-11-01 01:53:53 +0000744 }
745}
746
747/*
748** datetime( TIMESTRING, MOD, MOD, ...)
749**
750** Return YYYY-MM-DD HH:MM:SS
751*/
drhf9b596e2004-05-26 16:54:42 +0000752static void datetimeFunc(
753 sqlite3_context *context,
754 int argc,
755 sqlite3_value **argv
756){
drh7014aff2003-11-01 01:53:53 +0000757 DateTime x;
danielk1977fee2d252007-08-18 10:59:19 +0000758 if( isDate(context, argc, argv, &x)==0 ){
drh7014aff2003-11-01 01:53:53 +0000759 char zBuf[100];
drhba212562004-01-08 02:17:31 +0000760 computeYMD_HMS(&x);
drh5bb3eb92007-05-04 13:15:55 +0000761 sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d %02d:%02d:%02d",
762 x.Y, x.M, x.D, x.h, x.m, (int)(x.s));
danielk1977d8123362004-06-12 09:25:12 +0000763 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
drh7014aff2003-11-01 01:53:53 +0000764 }
765}
766
767/*
768** time( TIMESTRING, MOD, MOD, ...)
769**
770** Return HH:MM:SS
771*/
drhf9b596e2004-05-26 16:54:42 +0000772static void timeFunc(
773 sqlite3_context *context,
774 int argc,
775 sqlite3_value **argv
776){
drh7014aff2003-11-01 01:53:53 +0000777 DateTime x;
danielk1977fee2d252007-08-18 10:59:19 +0000778 if( isDate(context, argc, argv, &x)==0 ){
drh7014aff2003-11-01 01:53:53 +0000779 char zBuf[100];
780 computeHMS(&x);
drh5bb3eb92007-05-04 13:15:55 +0000781 sqlite3_snprintf(sizeof(zBuf), zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s);
danielk1977d8123362004-06-12 09:25:12 +0000782 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
drh7014aff2003-11-01 01:53:53 +0000783 }
784}
785
786/*
787** date( TIMESTRING, MOD, MOD, ...)
788**
789** Return YYYY-MM-DD
790*/
drhf9b596e2004-05-26 16:54:42 +0000791static void dateFunc(
792 sqlite3_context *context,
793 int argc,
794 sqlite3_value **argv
795){
drh7014aff2003-11-01 01:53:53 +0000796 DateTime x;
danielk1977fee2d252007-08-18 10:59:19 +0000797 if( isDate(context, argc, argv, &x)==0 ){
drh7014aff2003-11-01 01:53:53 +0000798 char zBuf[100];
799 computeYMD(&x);
drh5bb3eb92007-05-04 13:15:55 +0000800 sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D);
danielk1977d8123362004-06-12 09:25:12 +0000801 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
drh7014aff2003-11-01 01:53:53 +0000802 }
803}
804
805/*
806** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
807**
808** Return a string described by FORMAT. Conversions as follows:
809**
810** %d day of month
811** %f ** fractional seconds SS.SSS
812** %H hour 00-24
813** %j day of year 000-366
814** %J ** Julian day number
815** %m month 01-12
816** %M minute 00-59
817** %s seconds since 1970-01-01
818** %S seconds 00-59
819** %w day of week 0-6 sunday==0
820** %W week of year 00-53
821** %Y year 0000-9999
822** %% %
823*/
drhf9b596e2004-05-26 16:54:42 +0000824static void strftimeFunc(
825 sqlite3_context *context,
826 int argc,
827 sqlite3_value **argv
828){
drh7014aff2003-11-01 01:53:53 +0000829 DateTime x;
drha0206bc2007-05-08 15:15:02 +0000830 u64 n;
831 int i, j;
drh7014aff2003-11-01 01:53:53 +0000832 char *z;
drh2646da72005-12-09 20:02:05 +0000833 const char *zFmt = (const char*)sqlite3_value_text(argv[0]);
drh7014aff2003-11-01 01:53:53 +0000834 char zBuf[100];
danielk1977fee2d252007-08-18 10:59:19 +0000835 if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
drh7014aff2003-11-01 01:53:53 +0000836 for(i=0, n=1; zFmt[i]; i++, n++){
837 if( zFmt[i]=='%' ){
838 switch( zFmt[i+1] ){
839 case 'd':
840 case 'H':
841 case 'm':
842 case 'M':
843 case 'S':
844 case 'W':
845 n++;
846 /* fall thru */
847 case 'w':
848 case '%':
849 break;
850 case 'f':
851 n += 8;
852 break;
853 case 'j':
854 n += 3;
855 break;
856 case 'Y':
857 n += 8;
858 break;
859 case 's':
860 case 'J':
861 n += 50;
862 break;
863 default:
864 return; /* ERROR. return a NULL */
865 }
866 i++;
867 }
868 }
869 if( n<sizeof(zBuf) ){
870 z = zBuf;
drhbb4957f2008-03-20 14:03:29 +0000871 }else if( n>sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH] ){
drha0206bc2007-05-08 15:15:02 +0000872 sqlite3_result_error_toobig(context);
873 return;
drh7014aff2003-11-01 01:53:53 +0000874 }else{
drh17435752007-08-16 04:30:38 +0000875 z = sqlite3_malloc( n );
drh3334e942008-01-17 20:26:46 +0000876 if( z==0 ){
877 sqlite3_result_error_nomem(context);
878 return;
879 }
drh7014aff2003-11-01 01:53:53 +0000880 }
881 computeJD(&x);
drhba212562004-01-08 02:17:31 +0000882 computeYMD_HMS(&x);
drh7014aff2003-11-01 01:53:53 +0000883 for(i=j=0; zFmt[i]; i++){
884 if( zFmt[i]!='%' ){
885 z[j++] = zFmt[i];
886 }else{
887 i++;
888 switch( zFmt[i] ){
drh5bb3eb92007-05-04 13:15:55 +0000889 case 'd': sqlite3_snprintf(3, &z[j],"%02d",x.D); j+=2; break;
drh7014aff2003-11-01 01:53:53 +0000890 case 'f': {
drhb1f1e6e2006-09-25 18:01:31 +0000891 double s = x.s;
892 if( s>59.999 ) s = 59.999;
drh2ecad3b2007-03-29 17:57:21 +0000893 sqlite3_snprintf(7, &z[j],"%06.3f", s);
drh7014aff2003-11-01 01:53:53 +0000894 j += strlen(&z[j]);
895 break;
896 }
drh5bb3eb92007-05-04 13:15:55 +0000897 case 'H': sqlite3_snprintf(3, &z[j],"%02d",x.h); j+=2; break;
drh7014aff2003-11-01 01:53:53 +0000898 case 'W': /* Fall thru */
899 case 'j': {
danielk1977f0113002006-01-24 12:09:17 +0000900 int nDay; /* Number of days since 1st day of year */
drh7014aff2003-11-01 01:53:53 +0000901 DateTime y = x;
902 y.validJD = 0;
903 y.M = 1;
904 y.D = 1;
905 computeJD(&y);
drhc2c9eef2007-01-08 13:07:30 +0000906 nDay = x.rJD - y.rJD + 0.5;
drh7014aff2003-11-01 01:53:53 +0000907 if( zFmt[i]=='W' ){
drh1020d492004-07-18 22:22:43 +0000908 int wd; /* 0=Monday, 1=Tuesday, ... 6=Sunday */
909 wd = ((int)(x.rJD+0.5)) % 7;
drh5bb3eb92007-05-04 13:15:55 +0000910 sqlite3_snprintf(3, &z[j],"%02d",(nDay+7-wd)/7);
drh7014aff2003-11-01 01:53:53 +0000911 j += 2;
912 }else{
drh5bb3eb92007-05-04 13:15:55 +0000913 sqlite3_snprintf(4, &z[j],"%03d",nDay+1);
drh7014aff2003-11-01 01:53:53 +0000914 j += 3;
915 }
916 break;
917 }
drh5bb3eb92007-05-04 13:15:55 +0000918 case 'J': {
919 sqlite3_snprintf(20, &z[j],"%.16g",x.rJD);
920 j+=strlen(&z[j]);
921 break;
922 }
923 case 'm': sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break;
924 case 'M': sqlite3_snprintf(3, &z[j],"%02d",x.m); j+=2; break;
drh7014aff2003-11-01 01:53:53 +0000925 case 's': {
drh5bb3eb92007-05-04 13:15:55 +0000926 sqlite3_snprintf(30,&z[j],"%d",
927 (int)((x.rJD-2440587.5)*86400.0 + 0.5));
drh7014aff2003-11-01 01:53:53 +0000928 j += strlen(&z[j]);
929 break;
930 }
drh5bb3eb92007-05-04 13:15:55 +0000931 case 'S': sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break;
drh7014aff2003-11-01 01:53:53 +0000932 case 'w': z[j++] = (((int)(x.rJD+1.5)) % 7) + '0'; break;
drh5bb3eb92007-05-04 13:15:55 +0000933 case 'Y': sqlite3_snprintf(5,&z[j],"%04d",x.Y); j+=strlen(&z[j]);break;
drh008e4762008-01-17 22:27:53 +0000934 default: z[j++] = '%'; break;
drh7014aff2003-11-01 01:53:53 +0000935 }
936 }
937 }
938 z[j] = 0;
drh3334e942008-01-17 20:26:46 +0000939 sqlite3_result_text(context, z, -1,
940 z==zBuf ? SQLITE_TRANSIENT : sqlite3_free);
drh7014aff2003-11-01 01:53:53 +0000941}
942
danielk19777977a172004-11-09 12:44:37 +0000943/*
944** current_time()
945**
946** This function returns the same value as time('now').
947*/
948static void ctimeFunc(
949 sqlite3_context *context,
950 int argc,
951 sqlite3_value **argv
952){
drh008e4762008-01-17 22:27:53 +0000953 timeFunc(context, 0, 0);
danielk19777977a172004-11-09 12:44:37 +0000954}
drh7014aff2003-11-01 01:53:53 +0000955
danielk19777977a172004-11-09 12:44:37 +0000956/*
957** current_date()
958**
959** This function returns the same value as date('now').
960*/
961static void cdateFunc(
962 sqlite3_context *context,
963 int argc,
964 sqlite3_value **argv
965){
drh008e4762008-01-17 22:27:53 +0000966 dateFunc(context, 0, 0);
danielk19777977a172004-11-09 12:44:37 +0000967}
968
969/*
970** current_timestamp()
971**
972** This function returns the same value as datetime('now').
973*/
974static void ctimestampFunc(
975 sqlite3_context *context,
976 int argc,
977 sqlite3_value **argv
978){
drh008e4762008-01-17 22:27:53 +0000979 datetimeFunc(context, 0, 0);
danielk19777977a172004-11-09 12:44:37 +0000980}
drh7014aff2003-11-01 01:53:53 +0000981#endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */
982
danielk1977752e6792004-11-09 16:13:33 +0000983#ifdef SQLITE_OMIT_DATETIME_FUNCS
984/*
985** If the library is compiled to omit the full-scale date and time
986** handling (to get a smaller binary), the following minimal version
987** of the functions current_time(), current_date() and current_timestamp()
988** are included instead. This is to support column declarations that
989** include "DEFAULT CURRENT_TIME" etc.
990**
danielk19772df9fab2004-11-11 01:50:30 +0000991** This function uses the C-library functions time(), gmtime()
danielk1977752e6792004-11-09 16:13:33 +0000992** and strftime(). The format string to pass to strftime() is supplied
993** as the user-data for the function.
994*/
danielk1977752e6792004-11-09 16:13:33 +0000995static void currentTimeFunc(
996 sqlite3_context *context,
997 int argc,
998 sqlite3_value **argv
999){
1000 time_t t;
1001 char *zFormat = (char *)sqlite3_user_data(context);
drhfa4a4b92008-03-19 21:45:51 +00001002 sqlite3 *db;
drh8257f0c2008-03-19 20:18:27 +00001003 double rT;
danielk1977752e6792004-11-09 16:13:33 +00001004 char zBuf[20];
danielk1977752e6792004-11-09 16:13:33 +00001005
drhfa4a4b92008-03-19 21:45:51 +00001006 db = sqlite3_context_db_handle(context);
1007 sqlite3OsCurrentTime(db->pVfs, &rT);
drh8257f0c2008-03-19 20:18:27 +00001008 t = 86400.0*(rT - 2440587.5) + 0.5;
drh87595762006-09-08 12:49:43 +00001009#ifdef HAVE_GMTIME_R
1010 {
1011 struct tm sNow;
1012 gmtime_r(&t, &sNow);
1013 strftime(zBuf, 20, zFormat, &sNow);
1014 }
1015#else
1016 {
1017 struct tm *pTm;
danielk19774152e672007-09-12 17:01:45 +00001018 sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
drh87595762006-09-08 12:49:43 +00001019 pTm = gmtime(&t);
1020 strftime(zBuf, 20, zFormat, pTm);
danielk19774152e672007-09-12 17:01:45 +00001021 sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
drh87595762006-09-08 12:49:43 +00001022 }
1023#endif
danielk1977e6efa742004-11-10 11:55:10 +00001024
danielk1977752e6792004-11-09 16:13:33 +00001025 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
1026}
1027#endif
1028
drh7014aff2003-11-01 01:53:53 +00001029/*
1030** This function registered all of the above C functions as SQL
1031** functions. This should be the only routine in this file with
1032** external linkage.
1033*/
drh9bb575f2004-09-06 17:24:11 +00001034void sqlite3RegisterDateTimeFunctions(sqlite3 *db){
drhfd1f3942004-07-20 00:39:14 +00001035#ifndef SQLITE_OMIT_DATETIME_FUNCS
drh57196282004-10-06 15:41:16 +00001036 static const struct {
drh7014aff2003-11-01 01:53:53 +00001037 char *zName;
1038 int nArg;
danielk19770ae8b832004-05-25 12:05:56 +00001039 void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
drh7014aff2003-11-01 01:53:53 +00001040 } aFuncs[] = {
drhf9b596e2004-05-26 16:54:42 +00001041 { "julianday", -1, juliandayFunc },
1042 { "date", -1, dateFunc },
1043 { "time", -1, timeFunc },
1044 { "datetime", -1, datetimeFunc },
1045 { "strftime", -1, strftimeFunc },
danielk19777977a172004-11-09 12:44:37 +00001046 { "current_time", 0, ctimeFunc },
1047 { "current_timestamp", 0, ctimestampFunc },
1048 { "current_date", 0, cdateFunc },
drh7014aff2003-11-01 01:53:53 +00001049 };
1050 int i;
1051
1052 for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
danielk1977771151b2006-01-17 13:21:40 +00001053 sqlite3CreateFunc(db, aFuncs[i].zName, aFuncs[i].nArg,
drhfa4a4b92008-03-19 21:45:51 +00001054 SQLITE_UTF8, 0, aFuncs[i].xFunc, 0, 0);
drh7014aff2003-11-01 01:53:53 +00001055 }
danielk1977752e6792004-11-09 16:13:33 +00001056#else
1057 static const struct {
1058 char *zName;
1059 char *zFormat;
1060 } aFuncs[] = {
1061 { "current_time", "%H:%M:%S" },
1062 { "current_date", "%Y-%m-%d" },
1063 { "current_timestamp", "%Y-%m-%d %H:%M:%S" }
1064 };
1065 int i;
1066
1067 for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
danielk1977771151b2006-01-17 13:21:40 +00001068 sqlite3CreateFunc(db, aFuncs[i].zName, 0, SQLITE_UTF8,
danielk1977752e6792004-11-09 16:13:33 +00001069 aFuncs[i].zFormat, currentTimeFunc, 0, 0);
1070 }
drhfd1f3942004-07-20 00:39:14 +00001071#endif
drh7014aff2003-11-01 01:53:53 +00001072}