]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Have "DEFAULT CURRENT_TIME" & co. work even if SQLITE_OMIT_DATETIME_FUNCS is defined...
authordanielk1977 <danielk1977@noemail.net>
Tue, 9 Nov 2004 16:13:33 +0000 (16:13 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Tue, 9 Nov 2004 16:13:33 +0000 (16:13 +0000)
FossilOrigin-Name: f81b9c1c022772378aad32ec45d0027beeb36574

manifest
manifest.uuid
src/date.c
src/parse.y
test/table.test

index bc1563c28f4689745fc94862a35d34848aaad4e8..b43603693f4ef7ebee84b5bb9149dec34cdd6f36 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Port\sthe\s"DEFAULT\sCURRENT_TIME"\setc.\sfunctionality\sfrom\san\searlier\sfork\sof\ssqlite.\s(CVS\s2082)
-D 2004-11-09T12:44:38
+C Have\s"DEFAULT\sCURRENT_TIME"\s&\sco.\swork\seven\sif\sSQLITE_OMIT_DATETIME_FUNCS\sis\sdefined.\s(CVS\s2083)
+D 2004-11-09T16:13:33
 F Makefile.in c4d2416860f472a1e3393714d0372074197565df
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@@ -32,7 +32,7 @@ F src/auth.c 3b81f2a42f48a62c2c9c9b0eda31a157c681edea
 F src/btree.c 63a84350a18f6ca68f16e2a12018b5041444a2df
 F src/btree.h 861e40b759a195ba63819740e484390012cf81ab
 F src/build.c d623d84fd7f4e9cc0c5e8d1b96aab7886cf0f84d
-F src/date.c dbf15c130ba2c0231c642b65a361d41dbc02db95
+F src/date.c fcbade133371925ac28fe3f926031d60b07e2474
 F src/delete.c f0af21a1ede15524a5edd59fe10ef486283a1ee9
 F src/expr.c 5f9afecf27e048b8f3627b5a9be3136bc1d9bdf1
 F src/func.c 600e506bccf7648df8ad03efb417560d0f7ad4c1
@@ -54,7 +54,7 @@ F src/os_win.c 9482dfc92f289b68205bb2c9315757c7e3946bfb
 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
 F src/pager.c 2653787b86267c079283b8128541095f0febac4f
 F src/pager.h 9eba8c53dd91eae7f3f90743b2ee242da02a9862
-F src/parse.y 0af8d009cab3a30b967ab75dc260967d87b20496
+F src/parse.y 02e0d88a6d465f6fd5ea79a200a8c23c92a877dc
 F src/pragma.c 44074b93216516b01cafacd85cb10621088693dd
 F src/printf.c 3d20b21cfecadacecac3fb7274e746cb81d3d357
 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
@@ -173,7 +173,7 @@ F test/select6.test 4ce9fa563662d5b2f5a8ff57e4d8b2f5cd186d38
 F test/select7.test c71c822a82c80bbd55558b4b69d35442dfe22ffd
 F test/sort.test c97c1a3289337b1dc349ac8a59e0780d2dcfd90b
 F test/subselect.test 50f98723f00e97b1839d36410ee63597ca82d775
-F test/table.test 54081854744733598af2122451b97b59d64ae894
+F test/table.test 0d7659fa9ffd5946c7d2f006b4c8608d7e9cc518
 F test/tableapi.test b21ab097e87a5484bb61029e69e1a4e5c5e65ede
 F test/tclsqlite.test 5e262df81a638a058536fb6d6666f316843ac7b2
 F test/temptable.test 63a16e3ad19adf073cfbcdf7624c92ac5236522c
@@ -254,7 +254,7 @@ F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25
 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
 F www/whentouse.tcl fdacb0ba2d39831e8a6240d05a490026ad4c4e4c
-P 63f2ee22e20ed7e520fd9230acc5c6db43b69d13
-R c7c1616611e1356d29290318a6cf79f2
+P 0d27c8ff48f327ad82dd5b5b3b47b8d221f119b7
+R 50983ef3488aaf796e19a0b73688d49a
 U danielk1977
-Z ee44e58703e5c1b5ed5b43c2151ec560
+Z a02b42aae687ca01ff2682d8d73ff8dd
index b5f66e1a38ca77b6db6692400d4f51ff413ef32d..a6f27409bcaea41587d94d7e465f5299008b564c 100644 (file)
@@ -1 +1 @@
-0d27c8ff48f327ad82dd5b5b3b47b8d221f119b7
\ No newline at end of file
+f81b9c1c022772378aad32ec45d0027beeb36574
\ No newline at end of file
index f085ed56fbe6177163e63eb813118149b58fffba..3dff942af02abc13767886a608c009f624ac4b6e 100644 (file)
@@ -16,7 +16,7 @@
 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: date.c,v 1.38 2004/11/09 12:44:38 danielk1977 Exp $
+** $Id: date.c,v 1.39 2004/11/09 16:13:33 danielk1977 Exp $
 **
 ** NOTES:
 **
@@ -917,6 +917,45 @@ static void ctimestampFunc(
 }
 #endif /* !defined(SQLITE_OMIT_DATETIME_FUNCS) */
 
+#ifdef SQLITE_OMIT_DATETIME_FUNCS
+/*
+** If the library is compiled to omit the full-scale date and time
+** handling (to get a smaller binary), the following minimal version
+** of the functions current_time(), current_date() and current_timestamp()
+** are included instead. This is to support column declarations that
+** include "DEFAULT CURRENT_TIME" etc.
+**
+** This function uses the C-library functions time(), localtime_r()
+** and strftime(). The format string to pass to strftime() is supplied
+** as the user-data for the function.
+*/
+
+static void currentTimeFunc(
+  sqlite3_context *context,
+  int argc,
+  sqlite3_value **argv
+){
+  time_t t;
+  char *zFormat = (char *)sqlite3_user_data(context);
+  char zBuf[20];
+  struct tm now;
+
+#ifdef SQLITE_TEST
+  /* This test variable is located in os_XXX.c */
+extern int sqlite3_current_time;
+#endif
+  time(&t);
+#ifdef SQLITE_TEST
+  if( sqlite3_current_time ){
+    t = sqlite3_current_time;
+  }
+#endif
+  localtime_r(&t, &now);
+  strftime(zBuf, 20, zFormat, &now);
+  sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
+}
+#endif
+
 /*
 ** This function registered all of the above C functions as SQL
 ** functions.  This should be the only routine in this file with
@@ -944,6 +983,21 @@ void sqlite3RegisterDateTimeFunctions(sqlite3 *db){
     sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
         SQLITE_UTF8, 0, aFuncs[i].xFunc, 0, 0);
   }
+#else
+  static const struct {
+     char *zName;
+     char *zFormat;
+  } aFuncs[] = {
+    { "current_time", "%H:%M:%S" },
+    { "current_date", "%Y-%m-%d" },
+    { "current_timestamp", "%Y-%m-%d %H:%M:%S" }
+  };
+  int i;
+
+  for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
+    sqlite3_create_function(db, aFuncs[i].zName, 0, SQLITE_UTF8, 
+        aFuncs[i].zFormat, currentTimeFunc, 0, 0);
+  }
 #endif
 }
 
index 2729594bdb98c3ff0ed8790f41401930e74e3936..7225257e593235c43ea184c828a20144853c6a78 100644 (file)
@@ -14,7 +14,7 @@
 ** the parser.  Lemon will also generate a header file containing
 ** numeric codes for all of the tokens.
 **
-** @(#) $Id: parse.y,v 1.151 2004/11/09 12:44:38 danielk1977 Exp $
+** @(#) $Id: parse.y,v 1.152 2004/11/09 16:13:33 danielk1977 Exp $
 */
 %token_prefix TK_
 %token_type {Token}
@@ -577,7 +577,7 @@ inscollist(A) ::= nm(Y).                      {A = sqlite3IdListAppend(0,&Y);}
 %destructor term {sqlite3ExprDelete($$);}
 
 expr(A) ::= term(X).             {A = X;}
-term(A) ::= LP(B) expr(X) RP(E). {A = X; sqlite3ExprSpan(A,&B,&E); }
+expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqlite3ExprSpan(A,&B,&E); }
 term(A) ::= NULL(X).             {A = sqlite3Expr(@X, 0, 0, &X);}
 expr(A) ::= ID(X).               {A = sqlite3Expr(TK_ID, 0, 0, &X);}
 expr(A) ::= JOIN_KW(X).          {A = sqlite3Expr(TK_ID, 0, 0, &X);}
index 6da76bb6cfc523bf8ffbb57a8a9c8c6a376b48dc..a30529447f5bd09e68c08c7e2fa7e3c4bd75827c 100644 (file)
@@ -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.31 2004/11/09 12:44:39 danielk1977 Exp $
+# $Id: table.test,v 1.32 2004/11/09 16:13:33 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -546,7 +546,8 @@ foreach {date time} {
   2003-12-31 12:34:56
 } {
   incr i
-  set sqlite_current_time [execsql "SELECT strftime('%s','$date $time')"]
+#  set sqlite_current_time [execsql "SELECT strftime('%s','$date $time')"]
+  set sqlite_current_time [clock scan "$date $time"]
   do_test table-13.2.$i {
     execsql "
       INSERT INTO tablet8(a) VALUES($i);