/ Check-in [0e82175f]
Login

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

Overview
Comment:Change the error message returned when localtime_r() fails to "local time unavailable". Ticket [bd484a090c8077]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0e82175fd86f0ca5da90676aaee3118a70264d85
User & Date: dan 2011-06-21 13:46:11
Original Comment: Change the error message returned when localtime_r() fails to "local time unavailable".
Context
2011-06-21
14:35
Simplifications to the localtime() interface. Fix the case where localtime_r() is available so that it works. Ticket [bd484a090c8077]. check-in: 5b68dae3 user: drh tags: trunk
13:46
Change the error message returned when localtime_r() fails to "local time unavailable". Ticket [bd484a090c8077] check-in: 0e82175f user: dan tags: trunk
12:53
Fix an error made in the previous commit. The parameters to localtime_s() were accidentally reversed. Ticket [bd484a090c807]. check-in: 97e86ec6 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/date.c.

   479    479     x.validJD = 0;
   480    480     computeJD(&x);
   481    481     t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
   482    482   #ifdef HAVE_LOCALTIME_R
   483    483     {
   484    484       struct tm sLocal;
   485    485       if( 0==osLocaltime_r(&t, &sLocal) ){
   486         -      sqlite3_result_error(pCtx, "error in localtime_r()", -1);
          486  +      sqlite3_result_error(pCtx, "local time unavailable", -1);
   487    487         *pRc = SQLITE_ERROR;
   488    488         return 0;
   489    489       }
   490    490       y.Y = sLocal.tm_year + 1900;
   491    491       y.M = sLocal.tm_mon + 1;
   492    492       y.D = sLocal.tm_mday;
   493    493       y.h = sLocal.tm_hour;
................................................................................
   494    494       y.m = sLocal.tm_min;
   495    495       y.s = sLocal.tm_sec;
   496    496     }
   497    497   #elif defined(HAVE_LOCALTIME_S) && HAVE_LOCALTIME_S
   498    498     {
   499    499       struct tm sLocal;
   500    500       if( 0!=osLocaltime_s(&sLocal, &t) ){
   501         -      sqlite3_result_error(pCtx, "error in localtime_s()", -1);
          501  +      sqlite3_result_error(pCtx, "local time unavailable", -1);
   502    502         *pRc = SQLITE_ERROR;
   503    503         return 0;
   504    504       }
   505    505       y.Y = sLocal.tm_year + 1900;
   506    506       y.M = sLocal.tm_mon + 1;
   507    507       y.D = sLocal.tm_mday;
   508    508       y.h = sLocal.tm_hour;
................................................................................
   520    520         y.D = pTm->tm_mday;
   521    521         y.h = pTm->tm_hour;
   522    522         y.m = pTm->tm_min;
   523    523         y.s = pTm->tm_sec;
   524    524       }
   525    525       sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
   526    526       if( !pTm ){
   527         -      sqlite3_result_error(pCtx, "error in localtime()", -1);
          527  +      sqlite3_result_error(pCtx, "local time unavailable", -1);
   528    528         *pRc = SQLITE_ERROR;
   529    529         return 0;
   530    530       }
   531    531     }
   532    532   #endif
   533    533     y.validYMD = 1;
   534    534     y.validHMS = 1;

Changes to test/tkt-bd484a090c.test.

    23     23   do_test 1.2 {
    24     24     lindex [catchsql { SELECT datetime('now', 'utc') }] 0
    25     25   } {0}
    26     26   
    27     27   sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 1
    28     28   
    29     29   do_test 2.1 {
    30         -  foreach {rc msg} [catchsql { SELECT datetime('now', 'localtime') }] {}
    31         -  set res [string match {error in localtime*()} $msg]
    32         -  list $rc $res
    33         -} {1 1}
           30  +  catchsql { SELECT datetime('now', 'localtime') }
           31  +} {1 {local time unavailable}}
    34     32   do_test 2.2 {
    35         -  foreach {rc msg} [catchsql { SELECT datetime('now', 'utc') }] {}
    36         -  set res [string match {error in localtime*()} $msg]
    37         -  list $rc $res
    38         -} {1 1}
           33  +  catchsql { SELECT datetime('now', 'utc') }
           34  +} {1 {local time unavailable}}
    39     35   
    40     36   sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 0
    41     37   
    42     38   finish_test