On Sat, Sep 14, 2013 at 3:19 PM, Yuriy Kaminskiy <yum...@gmail.com> wrote:

> IMO, correct [= least surprise] behavior should be "timestamp used for
> 'now'
> should cached on first row step, and reused in all following calls [until
> SQLITE_OK/SQLITE_DONE returned]", but fixing that won't be easy :-|.
>

That can easily be done with a custom function. Here's one which returns
the current time but could easily be refactored to cache the time in a
static or in app-state (via the sqlite3 context data).

/*
** SQL function to return the number of seconds since 1970.  This is
** the same as strftime('%s','now') but is more compact.
*/
static void fsl_db_now_function(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  sqlite3_result_int64(context, (sqlite3_int64)time(0));
}


Caching like that is only really useful for short-lived apps, though. If
the app runs for several minutes, it may very well later expect 'now' to be
now. One could extend the above function to take an optional boolean
parameter, and reset the cached value if passed a truthy value.

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to