4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
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.
11 *************************************************************************
12 ** This file contains the C functions that implement date and time
13 ** functions for SQLite.
15 ** There is only one exported symbol in this file - the function
16 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
17 ** All other code has file scope.
19 ** SQLite processes all times and dates as Julian Day numbers. The
20 ** dates and times are stored as the number of days since noon
21 ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
24 ** 1970-01-01 00:00:00 is JD 2440587.5
25 ** 2000-01-01 00:00:00 is JD 2451544.5
27 ** This implemention requires years to be expressed as a 4-digit number
28 ** which means that only dates between 0000-01-01 and 9999-12-31 can
29 ** be represented, even though julian day numbers allow a much wider
32 ** The Gregorian calendar system is used for all dates and times,
33 ** even those that predate the Gregorian calendar. Historians usually
34 ** use the Julian calendar for dates prior to 1582-10-15 and for some
35 ** dates afterwards, depending on locale. Beware of this difference.
37 ** The conversion algorithms are implemented based on descriptions
38 ** in the following text:
41 ** Astronomical Algorithms, 2nd Edition, 1998
44 ** Richmond, Virginia (USA)
46 #include "sqliteInt.h"
51 #ifndef SQLITE_OMIT_DATETIME_FUNCS
54 ** On recent Windows platforms, the localtime_s() function is available
55 ** as part of the "Secure CRT". It is essentially equivalent to
56 ** localtime_r() available under most POSIX platforms, except that the
57 ** order of the parameters is reversed.
59 ** See http://msdn.microsoft.com/en-us/library/a442x3ye(VS.80).aspx.
61 ** If the user has not indicated to use localtime_r() or localtime_s()
62 ** already, check for an MSVC build environment that provides
65 #if !defined(HAVE_LOCALTIME_R) && !defined(HAVE_LOCALTIME_S) && \
66 defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
67 #define HAVE_LOCALTIME_S 1
71 ** A structure for holding a single date and time.
73 typedef struct DateTime DateTime
;
75 sqlite3_int64 iJD
; /* The julian day number times 86400000 */
76 int Y
, M
, D
; /* Year, month, and day */
77 int h
, m
; /* Hour and minutes */
78 int tz
; /* Timezone offset in minutes */
79 double s
; /* Seconds */
80 char validYMD
; /* True (1) if Y,M,D are valid */
81 char validHMS
; /* True (1) if h,m,s are valid */
82 char validJD
; /* True (1) if iJD is valid */
83 char validTZ
; /* True (1) if tz is valid */
88 ** Convert zDate into one or more integers. Additional arguments
89 ** come in groups of 5 as follows:
91 ** N number of digits in the integer
92 ** min minimum allowed value of the integer
93 ** max maximum allowed value of the integer
94 ** nextC first character after the integer
95 ** pVal where to write the integers value.
97 ** Conversions continue until one with nextC==0 is encountered.
98 ** The function returns the number of successful conversions.
100 static int getDigits(const char *zDate
, ...){
112 min
= va_arg(ap
, int);
113 max
= va_arg(ap
, int);
114 nextC
= va_arg(ap
, int);
115 pVal
= va_arg(ap
, int*);
118 if( !sqlite3Isdigit(*zDate
) ){
121 val
= val
*10 + *zDate
- '0';
124 if( val
<min
|| val
>max
|| (nextC
!=0 && nextC
!=*zDate
) ){
137 ** Parse a timezone extension on the end of a date-time.
138 ** The extension is of the form:
142 ** Or the "zulu" notation:
146 ** If the parse is successful, write the number of minutes
147 ** of change in p->tz and return 0. If a parser error occurs,
150 ** A missing specifier is not considered an error.
152 static int parseTimezone(const char *zDate
, DateTime
*p
){
156 while( sqlite3Isspace(*zDate
) ){ zDate
++; }
163 }else if( c
=='Z' || c
=='z' ){
170 if( getDigits(zDate
, 2, 0, 14, ':', &nHr
, 2, 0, 59, 0, &nMn
)!=2 ){
174 p
->tz
= sgn
*(nMn
+ nHr
*60);
176 while( sqlite3Isspace(*zDate
) ){ zDate
++; }
181 ** Parse times of the form HH:MM or HH:MM:SS or HH:MM:SS.FFFF.
182 ** The HH, MM, and SS must each be exactly 2 digits. The
183 ** fractional seconds FFFF can be one or more digits.
185 ** Return 1 if there is a parsing error and 0 on success.
187 static int parseHhMmSs(const char *zDate
, DateTime
*p
){
190 if( getDigits(zDate
, 2, 0, 24, ':', &h
, 2, 0, 59, 0, &m
)!=2 ){
196 if( getDigits(zDate
, 2, 0, 59, 0, &s
)!=1 ){
200 if( *zDate
=='.' && sqlite3Isdigit(zDate
[1]) ){
203 while( sqlite3Isdigit(*zDate
) ){
204 ms
= ms
*10.0 + *zDate
- '0';
218 if( parseTimezone(zDate
, p
) ) return 1;
219 p
->validTZ
= (p
->tz
!=0)?1:0;
224 ** Convert from YYYY-MM-DD HH:MM:SS to julian day. We always assume
225 ** that the YYYY-MM-DD is according to the Gregorian calendar.
227 ** Reference: Meeus page 61
229 static void computeJD(DateTime
*p
){
230 int Y
, M
, D
, A
, B
, X1
, X2
;
232 if( p
->validJD
) return;
238 Y
= 2000; /* If no YMD specified, assume 2000-Jan-01 */
248 X1
= 36525*(Y
+4716)/100;
249 X2
= 306001*(M
+1)/10000;
250 p
->iJD
= (sqlite3_int64
)((X1
+ X2
+ D
+ B
- 1524.5 ) * 86400000);
253 p
->iJD
+= p
->h
*3600000 + p
->m
*60000 + (sqlite3_int64
)(p
->s
*1000);
255 p
->iJD
-= p
->tz
*60000;
264 ** Parse dates of the form
266 ** YYYY-MM-DD HH:MM:SS.FFF
267 ** YYYY-MM-DD HH:MM:SS
271 ** Write the result into the DateTime structure and return 0
272 ** on success and 1 if the input string is not a well-formed
275 static int parseYyyyMmDd(const char *zDate
, DateTime
*p
){
284 if( getDigits(zDate
,4,0,9999,'-',&Y
,2,1,12,'-',&M
,2,1,31,0,&D
)!=3 ){
288 while( sqlite3Isspace(*zDate
) || 'T'==*(u8
*)zDate
){ zDate
++; }
289 if( parseHhMmSs(zDate
, p
)==0 ){
290 /* We got the time */
291 }else if( *zDate
==0 ){
308 ** Set the time to the current time reported by the VFS
310 static void setDateTimeToCurrent(sqlite3_context
*context
, DateTime
*p
){
311 sqlite3
*db
= sqlite3_context_db_handle(context
);
312 sqlite3OsCurrentTimeInt64(db
->pVfs
, &p
->iJD
);
317 ** Attempt to parse the given string into a Julian Day Number. Return
318 ** the number of errors.
320 ** The following are acceptable forms for the input string:
322 ** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
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.
332 static int parseDateOrTime(
333 sqlite3_context
*context
,
338 if( parseYyyyMmDd(zDate
,p
)==0 ){
340 }else if( parseHhMmSs(zDate
, p
)==0 ){
342 }else if( sqlite3StrICmp(zDate
,"now")==0){
343 setDateTimeToCurrent(context
, p
);
345 }else if( sqlite3AtoF(zDate
, &r
, sqlite3Strlen30(zDate
), SQLITE_UTF8
) ){
346 p
->iJD
= (sqlite3_int64
)(r
*86400000.0 + 0.5);
354 ** Compute the Year, Month, and Day from the julian day number.
356 static void computeYMD(DateTime
*p
){
357 int Z
, A
, B
, C
, D
, E
, X1
;
358 if( p
->validYMD
) return;
364 Z
= (int)((p
->iJD
+ 43200000)/86400000);
365 A
= (int)((Z
- 1867216.25)/36524.25);
366 A
= Z
+ 1 + A
- (A
/4);
368 C
= (int)((B
- 122.1)/365.25);
370 E
= (int)((B
-D
)/30.6001);
371 X1
= (int)(30.6001*E
);
373 p
->M
= E
<14 ? E
-1 : E
-13;
374 p
->Y
= p
->M
>2 ? C
- 4716 : C
- 4715;
380 ** Compute the Hour, Minute, and Seconds from the julian day number.
382 static void computeHMS(DateTime
*p
){
384 if( p
->validHMS
) return;
386 s
= (int)((p
->iJD
+ 43200000) % 86400000);
398 ** Compute both YMD and HMS
400 static void computeYMD_HMS(DateTime
*p
){
406 ** Clear the YMD and HMS and the TZ
408 static void clearYMD_HMS_TZ(DateTime
*p
){
414 #ifndef SQLITE_OMIT_LOCALTIME
416 ** Compute the difference (in milliseconds)
417 ** between localtime and UTC (a.k.a. GMT)
418 ** for the time value p where p is in UTC.
420 static sqlite3_int64
localtimeOffset(DateTime
*p
){
425 if( x
.Y
<1971 || x
.Y
>=2038 ){
433 int s
= (int)(x
.s
+ 0.5);
439 t
= (time_t)(x
.iJD
/1000 - 21086676*(i64
)10000);
440 #ifdef HAVE_LOCALTIME_R
443 localtime_r(&t
, &sLocal
);
444 y
.Y
= sLocal
.tm_year
+ 1900;
445 y
.M
= sLocal
.tm_mon
+ 1;
446 y
.D
= sLocal
.tm_mday
;
447 y
.h
= sLocal
.tm_hour
;
451 #elif defined(HAVE_LOCALTIME_S) && HAVE_LOCALTIME_S
454 localtime_s(&sLocal
, &t
);
455 y
.Y
= sLocal
.tm_year
+ 1900;
456 y
.M
= sLocal
.tm_mon
+ 1;
457 y
.D
= sLocal
.tm_mday
;
458 y
.h
= sLocal
.tm_hour
;
465 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER
));
467 y
.Y
= pTm
->tm_year
+ 1900;
468 y
.M
= pTm
->tm_mon
+ 1;
473 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER
));
481 return y
.iJD
- x
.iJD
;
483 #endif /* SQLITE_OMIT_LOCALTIME */
486 ** Process a modifier to a date-time stamp. The modifiers are
504 ** Return 0 on success and 1 if there is any kind of error.
506 static int parseModifier(const char *zMod
, DateTime
*p
){
512 for(n
=0; n
<ArraySize(zBuf
)-1 && zMod
[n
]; n
++){
513 z
[n
] = (char)sqlite3UpperToLower
[(u8
)zMod
[n
]];
517 #ifndef SQLITE_OMIT_LOCALTIME
521 ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
524 if( strcmp(z
, "localtime")==0 ){
526 p
->iJD
+= localtimeOffset(p
);
537 ** Treat the current value of p->iJD as the number of
538 ** seconds since 1970. Convert to a real julian day number.
540 if( strcmp(z
, "unixepoch")==0 && p
->validJD
){
541 p
->iJD
= (p
->iJD
+ 43200)/86400 + 21086676*(i64
)10000000;
545 #ifndef SQLITE_OMIT_LOCALTIME
546 else if( strcmp(z
, "utc")==0 ){
549 c1
= localtimeOffset(p
);
552 p
->iJD
+= c1
- localtimeOffset(p
);
562 ** Move the date to the same time on the next occurrence of
563 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the
564 ** date is already on the appropriate weekday, this is a no-op.
566 if( strncmp(z
, "weekday ", 8)==0
567 && sqlite3AtoF(&z
[8], &r
, sqlite3Strlen30(&z
[8]), SQLITE_UTF8
)
568 && (n
=(int)r
)==r
&& n
>=0 && r
<7 ){
574 Z
= ((p
->iJD
+ 129600000)/86400000) % 7;
576 p
->iJD
+= (n
- Z
)*86400000;
586 ** Move the date backwards to the beginning of the current day,
589 if( strncmp(z
, "start of ", 9)!=0 ) break;
597 if( strcmp(z
,"month")==0 ){
600 }else if( strcmp(z
,"year")==0 ){
605 }else if( strcmp(z
,"day")==0 ){
623 for(n
=1; z
[n
] && z
[n
]!=':' && !sqlite3Isspace(z
[n
]); n
++){}
624 if( !sqlite3AtoF(z
, &r
, n
, SQLITE_UTF8
) ){
629 /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
630 ** specified number of hours, minutes, seconds, and fractional seconds
631 ** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
637 if( !sqlite3Isdigit(*z2
) ) z2
++;
638 memset(&tx
, 0, sizeof(tx
));
639 if( parseHhMmSs(z2
, &tx
) ) break;
642 day
= tx
.iJD
/86400000;
643 tx
.iJD
-= day
*86400000;
644 if( z
[0]=='-' ) tx
.iJD
= -tx
.iJD
;
652 while( sqlite3Isspace(*z
) ) z
++;
653 n
= sqlite3Strlen30(z
);
654 if( n
>10 || n
<3 ) break;
655 if( z
[n
-1]=='s' ){ z
[n
-1] = 0; n
--; }
658 rRounder
= r
<0 ? -0.5 : +0.5;
659 if( n
==3 && strcmp(z
,"day")==0 ){
660 p
->iJD
+= (sqlite3_int64
)(r
*86400000.0 + rRounder
);
661 }else if( n
==4 && strcmp(z
,"hour")==0 ){
662 p
->iJD
+= (sqlite3_int64
)(r
*(86400000.0/24.0) + rRounder
);
663 }else if( n
==6 && strcmp(z
,"minute")==0 ){
664 p
->iJD
+= (sqlite3_int64
)(r
*(86400000.0/(24.0*60.0)) + rRounder
);
665 }else if( n
==6 && strcmp(z
,"second")==0 ){
666 p
->iJD
+= (sqlite3_int64
)(r
*(86400000.0/(24.0*60.0*60.0)) + rRounder
);
667 }else if( n
==5 && strcmp(z
,"month")==0 ){
671 x
= p
->M
>0 ? (p
->M
-1)/12 : (p
->M
-12)/12;
678 p
->iJD
+= (sqlite3_int64
)((r
- y
)*30.0*86400000.0 + rRounder
);
680 }else if( n
==4 && strcmp(z
,"year")==0 ){
687 p
->iJD
+= (sqlite3_int64
)((r
- y
)*365.0*86400000.0 + rRounder
);
703 ** Process time function arguments. argv[0] is a date-time stamp.
704 ** argv[1] and following are modifiers. Parse them all and write
705 ** the resulting time into the DateTime structure p. Return 0
706 ** on success and 1 if there are any errors.
708 ** If there are zero parameters (if even argv[0] is undefined)
709 ** then assume a default value of "now" for argv[0].
712 sqlite3_context
*context
,
714 sqlite3_value
**argv
,
718 const unsigned char *z
;
720 memset(p
, 0, sizeof(*p
));
722 setDateTimeToCurrent(context
, p
);
723 }else if( (eType
= sqlite3_value_type(argv
[0]))==SQLITE_FLOAT
724 || eType
==SQLITE_INTEGER
){
725 p
->iJD
= (sqlite3_int64
)(sqlite3_value_double(argv
[0])*86400000.0 + 0.5);
728 z
= sqlite3_value_text(argv
[0]);
729 if( !z
|| parseDateOrTime(context
, (char*)z
, p
) ){
733 for(i
=1; i
<argc
; i
++){
734 if( (z
= sqlite3_value_text(argv
[i
]))==0 || parseModifier((char*)z
, p
) ){
743 ** The following routines implement the various date and time functions
748 ** julianday( TIMESTRING, MOD, MOD, ...)
750 ** Return the julian day number of the date specified in the arguments
752 static void juliandayFunc(
753 sqlite3_context
*context
,
758 if( isDate(context
, argc
, argv
, &x
)==0 ){
760 sqlite3_result_double(context
, x
.iJD
/86400000.0);
765 ** datetime( TIMESTRING, MOD, MOD, ...)
767 ** Return YYYY-MM-DD HH:MM:SS
769 static void datetimeFunc(
770 sqlite3_context
*context
,
775 if( isDate(context
, argc
, argv
, &x
)==0 ){
778 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%04d-%02d-%02d %02d:%02d:%02d",
779 x
.Y
, x
.M
, x
.D
, x
.h
, x
.m
, (int)(x
.s
));
780 sqlite3_result_text(context
, zBuf
, -1, SQLITE_TRANSIENT
);
785 ** time( TIMESTRING, MOD, MOD, ...)
789 static void timeFunc(
790 sqlite3_context
*context
,
795 if( isDate(context
, argc
, argv
, &x
)==0 ){
798 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%02d:%02d:%02d", x
.h
, x
.m
, (int)x
.s
);
799 sqlite3_result_text(context
, zBuf
, -1, SQLITE_TRANSIENT
);
804 ** date( TIMESTRING, MOD, MOD, ...)
808 static void dateFunc(
809 sqlite3_context
*context
,
814 if( isDate(context
, argc
, argv
, &x
)==0 ){
817 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%04d-%02d-%02d", x
.Y
, x
.M
, x
.D
);
818 sqlite3_result_text(context
, zBuf
, -1, SQLITE_TRANSIENT
);
823 ** strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
825 ** Return a string described by FORMAT. Conversions as follows:
828 ** %f ** fractional seconds SS.SSS
830 ** %j day of year 000-366
831 ** %J ** Julian day number
834 ** %s seconds since 1970-01-01
836 ** %w day of week 0-6 sunday==0
837 ** %W week of year 00-53
841 static void strftimeFunc(
842 sqlite3_context
*context
,
851 const char *zFmt
= (const char*)sqlite3_value_text(argv
[0]);
853 if( zFmt
==0 || isDate(context
, argc
-1, argv
+1, &x
) ) return;
854 db
= sqlite3_context_db_handle(context
);
855 for(i
=0, n
=1; zFmt
[i
]; i
++, n
++){
883 return; /* ERROR. return a NULL */
888 testcase( n
==sizeof(zBuf
)-1 );
889 testcase( n
==sizeof(zBuf
) );
890 testcase( n
==(u64
)db
->aLimit
[SQLITE_LIMIT_LENGTH
]+1 );
891 testcase( n
==(u64
)db
->aLimit
[SQLITE_LIMIT_LENGTH
] );
892 if( n
<sizeof(zBuf
) ){
894 }else if( n
>(u64
)db
->aLimit
[SQLITE_LIMIT_LENGTH
] ){
895 sqlite3_result_error_toobig(context
);
898 z
= sqlite3DbMallocRaw(db
, (int)n
);
900 sqlite3_result_error_nomem(context
);
906 for(i
=j
=0; zFmt
[i
]; i
++){
912 case 'd': sqlite3_snprintf(3, &z
[j
],"%02d",x
.D
); j
+=2; break;
915 if( s
>59.999 ) s
= 59.999;
916 sqlite3_snprintf(7, &z
[j
],"%06.3f", s
);
917 j
+= sqlite3Strlen30(&z
[j
]);
920 case 'H': sqlite3_snprintf(3, &z
[j
],"%02d",x
.h
); j
+=2; break;
921 case 'W': /* Fall thru */
923 int nDay
; /* Number of days since 1st day of year */
929 nDay
= (int)((x
.iJD
-y
.iJD
+43200000)/86400000);
931 int wd
; /* 0=Monday, 1=Tuesday, ... 6=Sunday */
932 wd
= (int)(((x
.iJD
+43200000)/86400000)%7);
933 sqlite3_snprintf(3, &z
[j
],"%02d",(nDay
+7-wd
)/7);
936 sqlite3_snprintf(4, &z
[j
],"%03d",nDay
+1);
942 sqlite3_snprintf(20, &z
[j
],"%.16g",x
.iJD
/86400000.0);
943 j
+=sqlite3Strlen30(&z
[j
]);
946 case 'm': sqlite3_snprintf(3, &z
[j
],"%02d",x
.M
); j
+=2; break;
947 case 'M': sqlite3_snprintf(3, &z
[j
],"%02d",x
.m
); j
+=2; break;
949 sqlite3_snprintf(30,&z
[j
],"%lld",
950 (i64
)(x
.iJD
/1000 - 21086676*(i64
)10000));
951 j
+= sqlite3Strlen30(&z
[j
]);
954 case 'S': sqlite3_snprintf(3,&z
[j
],"%02d",(int)x
.s
); j
+=2; break;
956 z
[j
++] = (char)(((x
.iJD
+129600000)/86400000) % 7) + '0';
960 sqlite3_snprintf(5,&z
[j
],"%04d",x
.Y
); j
+=sqlite3Strlen30(&z
[j
]);
963 default: z
[j
++] = '%'; break;
968 sqlite3_result_text(context
, z
, -1,
969 z
==zBuf
? SQLITE_TRANSIENT
: SQLITE_DYNAMIC
);
975 ** This function returns the same value as time('now').
977 static void ctimeFunc(
978 sqlite3_context
*context
,
980 sqlite3_value
**NotUsed2
982 UNUSED_PARAMETER2(NotUsed
, NotUsed2
);
983 timeFunc(context
, 0, 0);
989 ** This function returns the same value as date('now').
991 static void cdateFunc(
992 sqlite3_context
*context
,
994 sqlite3_value
**NotUsed2
996 UNUSED_PARAMETER2(NotUsed
, NotUsed2
);
997 dateFunc(context
, 0, 0);
1001 ** current_timestamp()
1003 ** This function returns the same value as datetime('now').
1005 static void ctimestampFunc(
1006 sqlite3_context
*context
,
1008 sqlite3_value
**NotUsed2
1010 UNUSED_PARAMETER2(NotUsed
, NotUsed2
);
1011 datetimeFunc(context
, 0, 0);
1013 #endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */
1015 #ifdef SQLITE_OMIT_DATETIME_FUNCS
1017 ** If the library is compiled to omit the full-scale date and time
1018 ** handling (to get a smaller binary), the following minimal version
1019 ** of the functions current_time(), current_date() and current_timestamp()
1020 ** are included instead. This is to support column declarations that
1021 ** include "DEFAULT CURRENT_TIME" etc.
1023 ** This function uses the C-library functions time(), gmtime()
1024 ** and strftime(). The format string to pass to strftime() is supplied
1025 ** as the user-data for the function.
1027 static void currentTimeFunc(
1028 sqlite3_context
*context
,
1030 sqlite3_value
**argv
1033 char *zFormat
= (char *)sqlite3_user_data(context
);
1038 UNUSED_PARAMETER(argc
);
1039 UNUSED_PARAMETER(argv
);
1041 db
= sqlite3_context_db_handle(context
);
1042 sqlite3OsCurrentTimeInt64(db
->pVfs
, &iT
);
1043 t
= iT
/1000 - 10000*(sqlite3_int64
)21086676;
1044 #ifdef HAVE_GMTIME_R
1047 gmtime_r(&t
, &sNow
);
1048 strftime(zBuf
, 20, zFormat
, &sNow
);
1053 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER
));
1055 strftime(zBuf
, 20, zFormat
, pTm
);
1056 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER
));
1060 sqlite3_result_text(context
, zBuf
, -1, SQLITE_TRANSIENT
);
1065 ** This function registered all of the above C functions as SQL
1066 ** functions. This should be the only routine in this file with
1067 ** external linkage.
1069 void sqlite3RegisterDateTimeFunctions(void){
1070 static SQLITE_WSD FuncDef aDateTimeFuncs
[] = {
1071 #ifndef SQLITE_OMIT_DATETIME_FUNCS
1072 FUNCTION(julianday
, -1, 0, 0, juliandayFunc
),
1073 FUNCTION(date
, -1, 0, 0, dateFunc
),
1074 FUNCTION(time
, -1, 0, 0, timeFunc
),
1075 FUNCTION(datetime
, -1, 0, 0, datetimeFunc
),
1076 FUNCTION(strftime
, -1, 0, 0, strftimeFunc
),
1077 FUNCTION(current_time
, 0, 0, 0, ctimeFunc
),
1078 FUNCTION(current_timestamp
, 0, 0, 0, ctimestampFunc
),
1079 FUNCTION(current_date
, 0, 0, 0, cdateFunc
),
1081 STR_FUNCTION(current_time
, 0, "%H:%M:%S", 0, currentTimeFunc
),
1082 STR_FUNCTION(current_date
, 0, "%Y-%m-%d", 0, currentTimeFunc
),
1083 STR_FUNCTION(current_timestamp
, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc
),
1087 FuncDefHash
*pHash
= &GLOBAL(FuncDefHash
, sqlite3GlobalFunctions
);
1088 FuncDef
*aFunc
= (FuncDef
*)&GLOBAL(FuncDef
, aDateTimeFuncs
);
1090 for(i
=0; i
<ArraySize(aDateTimeFuncs
); i
++){
1091 sqlite3FuncDefInsert(pHash
, &aFunc
[i
]);