SQLite

Check-in [0e82175fd8]
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
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0e82175fd86f0ca5da90676aaee3118a70264d85
User & Date: dan 2011-06-21 13:46:11.287
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: 5b68dae320 user: drh tags: trunk)
13:46
Change the error message returned when localtime_r() fails to "local time unavailable". Ticket [bd484a090c8077] (check-in: 0e82175fd8 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: 97e86ec6df user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/date.c.
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
  x.validJD = 0;
  computeJD(&x);
  t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
#ifdef HAVE_LOCALTIME_R
  {
    struct tm sLocal;
    if( 0==osLocaltime_r(&t, &sLocal) ){
      sqlite3_result_error(pCtx, "error in localtime_r()", -1);
      *pRc = SQLITE_ERROR;
      return 0;
    }
    y.Y = sLocal.tm_year + 1900;
    y.M = sLocal.tm_mon + 1;
    y.D = sLocal.tm_mday;
    y.h = sLocal.tm_hour;
    y.m = sLocal.tm_min;
    y.s = sLocal.tm_sec;
  }
#elif defined(HAVE_LOCALTIME_S) && HAVE_LOCALTIME_S
  {
    struct tm sLocal;
    if( 0!=osLocaltime_s(&sLocal, &t) ){
      sqlite3_result_error(pCtx, "error in localtime_s()", -1);
      *pRc = SQLITE_ERROR;
      return 0;
    }
    y.Y = sLocal.tm_year + 1900;
    y.M = sLocal.tm_mon + 1;
    y.D = sLocal.tm_mday;
    y.h = sLocal.tm_hour;







|














|







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







|







520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
      y.D = pTm->tm_mday;
      y.h = pTm->tm_hour;
      y.m = pTm->tm_min;
      y.s = pTm->tm_sec;
    }
    sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
    if( !pTm ){
      sqlite3_result_error(pCtx, "local time unavailable", -1);
      *pRc = SQLITE_ERROR;
      return 0;
    }
  }
#endif
  y.validYMD = 1;
  y.validHMS = 1;
Changes to test/tkt-bd484a090c.test.
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
do_test 1.2 {
  lindex [catchsql { SELECT datetime('now', 'utc') }] 0
} {0}

sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 1

do_test 2.1 {
  foreach {rc msg} [catchsql { SELECT datetime('now', 'localtime') }] {}
  set res [string match {error in localtime*()} $msg]
  list $rc $res
} {1 1}
do_test 2.2 {
  foreach {rc msg} [catchsql { SELECT datetime('now', 'utc') }] {}
  set res [string match {error in localtime*()} $msg]
  list $rc $res
} {1 1}

sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 0

finish_test







|
<
<
|

|
<
<
|




23
24
25
26
27
28
29
30


31
32
33


34
35
36
37
38
do_test 1.2 {
  lindex [catchsql { SELECT datetime('now', 'utc') }] 0
} {0}

sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 1

do_test 2.1 {
  catchsql { SELECT datetime('now', 'localtime') }


} {1 {local time unavailable}}
do_test 2.2 {
  catchsql { SELECT datetime('now', 'utc') }


} {1 {local time unavailable}}

sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 0

finish_test