| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/sqlite/src/src/date.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | typedef struct DateTime DateTime; | - | ||||||||||||||||||||||||
| 4 | struct DateTime { | - | ||||||||||||||||||||||||
| 5 | sqlite3_int64 iJD; | - | ||||||||||||||||||||||||
| 6 | int Y, M, D; | - | ||||||||||||||||||||||||
| 7 | int h, m; | - | ||||||||||||||||||||||||
| 8 | int tz; | - | ||||||||||||||||||||||||
| 9 | double s; | - | ||||||||||||||||||||||||
| 10 | char validJD; | - | ||||||||||||||||||||||||
| 11 | char rawS; | - | ||||||||||||||||||||||||
| 12 | char validYMD; | - | ||||||||||||||||||||||||
| 13 | char validHMS; | - | ||||||||||||||||||||||||
| 14 | char validTZ; | - | ||||||||||||||||||||||||
| 15 | char tzSet; | - | ||||||||||||||||||||||||
| 16 | char isError; | - | ||||||||||||||||||||||||
| 17 | }; | - | ||||||||||||||||||||||||
| 18 | static int getDigits(const char *zDate, const char *zFormat, ...){ | - | ||||||||||||||||||||||||
| 19 | - | |||||||||||||||||||||||||
| 20 | - | |||||||||||||||||||||||||
| 21 | static const u16 aMx[] = { 12, 14, 24, 31, 59, 9999 }; | - | ||||||||||||||||||||||||
| 22 | va_list ap; | - | ||||||||||||||||||||||||
| 23 | int cnt = 0; | - | ||||||||||||||||||||||||
| 24 | char nextC; | - | ||||||||||||||||||||||||
| 25 | - | |||||||||||||||||||||||||
| 26 | __builtin_va_start( | - | ||||||||||||||||||||||||
| 27 | ap | - | ||||||||||||||||||||||||
| 28 | , | - | ||||||||||||||||||||||||
| 29 | zFormat | - | ||||||||||||||||||||||||
| 30 | ) | - | ||||||||||||||||||||||||
| 31 | ; | - | ||||||||||||||||||||||||
| 32 | do{ | - | ||||||||||||||||||||||||
| 33 | char N = zFormat[0] - '0'; | - | ||||||||||||||||||||||||
| 34 | char min = zFormat[1] - '0'; | - | ||||||||||||||||||||||||
| 35 | int val = 0; | - | ||||||||||||||||||||||||
| 36 | u16 max; | - | ||||||||||||||||||||||||
| 37 | - | |||||||||||||||||||||||||
| 38 | - | |||||||||||||||||||||||||
| 39 | ((void) (0)) | - | ||||||||||||||||||||||||
| 40 | ; | - | ||||||||||||||||||||||||
| 41 | max = aMx[zFormat[2] - 'a']; | - | ||||||||||||||||||||||||
| 42 | nextC = zFormat[3]; | - | ||||||||||||||||||||||||
| 43 | val = 0; | - | ||||||||||||||||||||||||
| 44 | while( N--
| 1098-2898 | ||||||||||||||||||||||||
| 45 | if( !(sqlite3CtypeMap[(unsigned char)(*zDate)]&0x04)
| 213-2685 | ||||||||||||||||||||||||
| 46 | goto executed 213 times by 1 test: end_getDigits;goto end_getDigits;Executed by:
executed 213 times by 1 test: goto end_getDigits;Executed by:
| 213 | ||||||||||||||||||||||||
| 47 | } | - | ||||||||||||||||||||||||
| 48 | val = val*10 + *zDate - '0'; | - | ||||||||||||||||||||||||
| 49 | zDate++; | - | ||||||||||||||||||||||||
| 50 | } executed 2685 times by 1 test: end of blockExecuted by:
| 2685 | ||||||||||||||||||||||||
| 51 | if( val<(int)min
| 2-1096 | ||||||||||||||||||||||||
| 52 | goto executed 29 times by 1 test: end_getDigits;goto end_getDigits;Executed by:
executed 29 times by 1 test: goto end_getDigits;Executed by:
| 29 | ||||||||||||||||||||||||
| 53 | } | - | ||||||||||||||||||||||||
| 54 | * | - | ||||||||||||||||||||||||
| 55 | __builtin_va_arg( | - | ||||||||||||||||||||||||
| 56 | ap | - | ||||||||||||||||||||||||
| 57 | , | - | ||||||||||||||||||||||||
| 58 | int* | - | ||||||||||||||||||||||||
| 59 | ) | - | ||||||||||||||||||||||||
| 60 | = val; | - | ||||||||||||||||||||||||
| 61 | zDate++; | - | ||||||||||||||||||||||||
| 62 | cnt++; | - | ||||||||||||||||||||||||
| 63 | zFormat += 4; | - | ||||||||||||||||||||||||
| 64 | } executed 1069 times by 1 test: while( nextCend of blockExecuted by:
| 457-1069 | ||||||||||||||||||||||||
| 65 | end_getDigits: code before this statement executed 457 times by 1 test: end_getDigits:Executed by:
| 457 | ||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||
| 67 | __builtin_va_end( | - | ||||||||||||||||||||||||
| 68 | ap | - | ||||||||||||||||||||||||
| 69 | ) | - | ||||||||||||||||||||||||
| 70 | ; | - | ||||||||||||||||||||||||
| 71 | return executed 699 times by 1 test: cnt;return cnt;Executed by:
executed 699 times by 1 test: return cnt;Executed by:
| 699 | ||||||||||||||||||||||||
| 72 | } | - | ||||||||||||||||||||||||
| 73 | static int parseTimezone(const char *zDate, DateTime *p){ | - | ||||||||||||||||||||||||
| 74 | int sgn = 0; | - | ||||||||||||||||||||||||
| 75 | int nHr, nMn; | - | ||||||||||||||||||||||||
| 76 | int c; | - | ||||||||||||||||||||||||
| 77 | while( (
executed 15 times by 1 test: end of blockExecuted by:
| 15-134 | ||||||||||||||||||||||||
| 78 | p->tz = 0; | - | ||||||||||||||||||||||||
| 79 | c = *zDate; | - | ||||||||||||||||||||||||
| 80 | if( c=='-'
| 5-129 | ||||||||||||||||||||||||
| 81 | sgn = -1; | - | ||||||||||||||||||||||||
| 82 | } executed 5 times by 1 test: else if( c=='+'end of blockExecuted by:
| 3-126 | ||||||||||||||||||||||||
| 83 | sgn = +1; | - | ||||||||||||||||||||||||
| 84 | } executed 3 times by 1 test: else if( c=='Z'end of blockExecuted by:
| 3-122 | ||||||||||||||||||||||||
| 85 | zDate++; | - | ||||||||||||||||||||||||
| 86 | goto executed 7 times by 1 test: zulu_time;goto zulu_time;Executed by:
executed 7 times by 1 test: goto zulu_time;Executed by:
| 7 | ||||||||||||||||||||||||
| 87 | }else{ | - | ||||||||||||||||||||||||
| 88 | return executed 119 times by 1 test: c!=0;return c!=0;Executed by:
executed 119 times by 1 test: return c!=0;Executed by:
| 119 | ||||||||||||||||||||||||
| 89 | } | - | ||||||||||||||||||||||||
| 90 | zDate++; | - | ||||||||||||||||||||||||
| 91 | if( getDigits(zDate, "20b:20e", &nHr, &nMn)!=2
| 1-7 | ||||||||||||||||||||||||
| 92 | return executed 1 time by 1 test: 1;return 1;Executed by:
executed 1 time by 1 test: return 1;Executed by:
| 1 | ||||||||||||||||||||||||
| 93 | } | - | ||||||||||||||||||||||||
| 94 | zDate += 5; | - | ||||||||||||||||||||||||
| 95 | p->tz = sgn*(nMn + nHr*60); | - | ||||||||||||||||||||||||
| 96 | zulu_time: code before this statement executed 7 times by 1 test: zulu_time:Executed by:
| 7 | ||||||||||||||||||||||||
| 97 | while( (
executed 13 times by 1 test: end of blockExecuted by:
| 13-14 | ||||||||||||||||||||||||
| 98 | p->tzSet = 1; | - | ||||||||||||||||||||||||
| 99 | return executed 14 times by 1 test: *zDate!=0;return *zDate!=0;Executed by:
executed 14 times by 1 test: return *zDate!=0;Executed by:
| 14 | ||||||||||||||||||||||||
| 100 | } | - | ||||||||||||||||||||||||
| 101 | static int parseHhMmSs(const char *zDate, DateTime *p){ | - | ||||||||||||||||||||||||
| 102 | int h, m, s; | - | ||||||||||||||||||||||||
| 103 | double ms = 0.0; | - | ||||||||||||||||||||||||
| 104 | if( getDigits(zDate, "20c:20e", &h, &m)!=2
| 135-177 | ||||||||||||||||||||||||
| 105 | return executed 177 times by 1 test: 1;return 1;Executed by:
executed 177 times by 1 test: return 1;Executed by:
| 177 | ||||||||||||||||||||||||
| 106 | } | - | ||||||||||||||||||||||||
| 107 | zDate += 5; | - | ||||||||||||||||||||||||
| 108 | if( *
| 48-87 | ||||||||||||||||||||||||
| 109 | zDate++; | - | ||||||||||||||||||||||||
| 110 | if( getDigits(zDate, "20e", &s)!=1
| 1-86 | ||||||||||||||||||||||||
| 111 | return executed 1 time by 1 test: 1;return 1;Executed by:
executed 1 time by 1 test: return 1;Executed by:
| 1 | ||||||||||||||||||||||||
| 112 | } | - | ||||||||||||||||||||||||
| 113 | zDate += 2; | - | ||||||||||||||||||||||||
| 114 | if( *
| 1-57 | ||||||||||||||||||||||||
| 115 | double rScale = 1.0; | - | ||||||||||||||||||||||||
| 116 | zDate++; | - | ||||||||||||||||||||||||
| 117 | while( (
| 28-72 | ||||||||||||||||||||||||
| 118 | ms = ms*10.0 + *zDate - '0'; | - | ||||||||||||||||||||||||
| 119 | rScale *= 10.0; | - | ||||||||||||||||||||||||
| 120 | zDate++; | - | ||||||||||||||||||||||||
| 121 | } executed 72 times by 1 test: end of blockExecuted by:
| 72 | ||||||||||||||||||||||||
| 122 | ms /= rScale; | - | ||||||||||||||||||||||||
| 123 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 124 | } executed 86 times by 1 test: else{end of blockExecuted by:
| 86 | ||||||||||||||||||||||||
| 125 | s = 0; | - | ||||||||||||||||||||||||
| 126 | } executed 48 times by 1 test: end of blockExecuted by:
| 48 | ||||||||||||||||||||||||
| 127 | p->validJD = 0; | - | ||||||||||||||||||||||||
| 128 | p->rawS = 0; | - | ||||||||||||||||||||||||
| 129 | p->validHMS = 1; | - | ||||||||||||||||||||||||
| 130 | p->h = h; | - | ||||||||||||||||||||||||
| 131 | p->m = m; | - | ||||||||||||||||||||||||
| 132 | p->s = s + ms; | - | ||||||||||||||||||||||||
| 133 | if( parseTimezone(zDate, p)
executed 7 times by 1 test: 1;return 1;Executed by:
executed 7 times by 1 test: return 1;Executed by:
| 7-127 | ||||||||||||||||||||||||
| 134 | p->validTZ = (
| 5-122 | ||||||||||||||||||||||||
| 135 | return executed 127 times by 1 test: 0;return 0;Executed by:
executed 127 times by 1 test: return 0;Executed by:
| 127 | ||||||||||||||||||||||||
| 136 | } | - | ||||||||||||||||||||||||
| 137 | - | |||||||||||||||||||||||||
| 138 | - | |||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||
| 140 | - | |||||||||||||||||||||||||
| 141 | static void datetimeError(DateTime *p){ | - | ||||||||||||||||||||||||
| 142 | memset(p, 0, sizeof(*p)); | - | ||||||||||||||||||||||||
| 143 | p->isError = 1; | - | ||||||||||||||||||||||||
| 144 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 145 | - | |||||||||||||||||||||||||
| 146 | - | |||||||||||||||||||||||||
| 147 | - | |||||||||||||||||||||||||
| 148 | - | |||||||||||||||||||||||||
| 149 | - | |||||||||||||||||||||||||
| 150 | - | |||||||||||||||||||||||||
| 151 | - | |||||||||||||||||||||||||
| 152 | static void computeJD(DateTime *p){ | - | ||||||||||||||||||||||||
| 153 | int Y, M, D, A, B, X1, X2; | - | ||||||||||||||||||||||||
| 154 | - | |||||||||||||||||||||||||
| 155 | if( p->validJD
executed 8804 times by 1 test: return;Executed by:
| 377-8804 | ||||||||||||||||||||||||
| 156 | if( p->validYMD
| 15-362 | ||||||||||||||||||||||||
| 157 | Y = p->Y; | - | ||||||||||||||||||||||||
| 158 | M = p->M; | - | ||||||||||||||||||||||||
| 159 | D = p->D; | - | ||||||||||||||||||||||||
| 160 | } executed 362 times by 1 test: else{end of blockExecuted by:
| 362 | ||||||||||||||||||||||||
| 161 | Y = 2000; | - | ||||||||||||||||||||||||
| 162 | M = 1; | - | ||||||||||||||||||||||||
| 163 | D = 1; | - | ||||||||||||||||||||||||
| 164 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||||||||
| 165 | if( Y<-4713
| 0-377 | ||||||||||||||||||||||||
| 166 | datetimeError(p); | - | ||||||||||||||||||||||||
| 167 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||||||||
| 168 | } | - | ||||||||||||||||||||||||
| 169 | if( M<=2
| 145-231 | ||||||||||||||||||||||||
| 170 | Y--; | - | ||||||||||||||||||||||||
| 171 | M += 12; | - | ||||||||||||||||||||||||
| 172 | } executed 145 times by 1 test: end of blockExecuted by:
| 145 | ||||||||||||||||||||||||
| 173 | A = Y/100; | - | ||||||||||||||||||||||||
| 174 | B = 2 - A + (A/4); | - | ||||||||||||||||||||||||
| 175 | X1 = 36525*(Y+4716)/100; | - | ||||||||||||||||||||||||
| 176 | X2 = 306001*(M+1)/10000; | - | ||||||||||||||||||||||||
| 177 | p->iJD = (sqlite3_int64)((X1 + X2 + D + B - 1524.5 ) * 86400000); | - | ||||||||||||||||||||||||
| 178 | p->validJD = 1; | - | ||||||||||||||||||||||||
| 179 | if( p->validHMS
| 97-279 | ||||||||||||||||||||||||
| 180 | p->iJD += p->h*3600000 + p->m*60000 + (sqlite3_int64)(p->s*1000); | - | ||||||||||||||||||||||||
| 181 | if( p->validTZ
| 5-274 | ||||||||||||||||||||||||
| 182 | p->iJD -= p->tz*60000; | - | ||||||||||||||||||||||||
| 183 | p->validYMD = 0; | - | ||||||||||||||||||||||||
| 184 | p->validHMS = 0; | - | ||||||||||||||||||||||||
| 185 | p->validTZ = 0; | - | ||||||||||||||||||||||||
| 186 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 187 | } executed 279 times by 1 test: end of blockExecuted by:
| 279 | ||||||||||||||||||||||||
| 188 | } executed 376 times by 1 test: end of blockExecuted by:
| 376 | ||||||||||||||||||||||||
| 189 | static int parseYyyyMmDd(const char *zDate, DateTime *p){ | - | ||||||||||||||||||||||||
| 190 | int Y, M, D, neg; | - | ||||||||||||||||||||||||
| 191 | - | |||||||||||||||||||||||||
| 192 | if( zDate[0]=='-'
| 8-284 | ||||||||||||||||||||||||
| 193 | zDate++; | - | ||||||||||||||||||||||||
| 194 | neg = 1; | - | ||||||||||||||||||||||||
| 195 | } executed 8 times by 1 test: else{end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 196 | neg = 0; | - | ||||||||||||||||||||||||
| 197 | } executed 284 times by 1 test: end of blockExecuted by:
| 284 | ||||||||||||||||||||||||
| 198 | if( getDigits(zDate, "40f-21a-21d", &Y, &M, &D)!=3
| 63-229 | ||||||||||||||||||||||||
| 199 | return executed 63 times by 1 test: 1;return 1;Executed by:
executed 63 times by 1 test: return 1;Executed by:
| 63 | ||||||||||||||||||||||||
| 200 | } | - | ||||||||||||||||||||||||
| 201 | zDate += 10; | - | ||||||||||||||||||||||||
| 202 | while( (
executed 131 times by 1 test: end of blockExecuted by:
| 6-235 | ||||||||||||||||||||||||
| 203 | if( parseHhMmSs(zDate, p)==0
| 113-116 | ||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||
| 205 | } executed 113 times by 1 test: else if( *end of blockExecuted by:
| 10-113 | ||||||||||||||||||||||||
| 206 | p->validHMS = 0; | - | ||||||||||||||||||||||||
| 207 | } executed 106 times by 1 test: else{end of blockExecuted by:
| 106 | ||||||||||||||||||||||||
| 208 | return executed 10 times by 1 test: 1;return 1;Executed by:
executed 10 times by 1 test: return 1;Executed by:
| 10 | ||||||||||||||||||||||||
| 209 | } | - | ||||||||||||||||||||||||
| 210 | p->validJD = 0; | - | ||||||||||||||||||||||||
| 211 | p->validYMD = 1; | - | ||||||||||||||||||||||||
| 212 | p->Y = neg
| 8-211 | ||||||||||||||||||||||||
| 213 | p->M = M; | - | ||||||||||||||||||||||||
| 214 | p->D = D; | - | ||||||||||||||||||||||||
| 215 | if( p->validTZ
| 5-214 | ||||||||||||||||||||||||
| 216 | computeJD(p); | - | ||||||||||||||||||||||||
| 217 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 218 | return executed 219 times by 1 test: 0;return 0;Executed by:
executed 219 times by 1 test: return 0;Executed by:
| 219 | ||||||||||||||||||||||||
| 219 | } | - | ||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||
| 222 | - | |||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||
| 224 | - | |||||||||||||||||||||||||
| 225 | - | |||||||||||||||||||||||||
| 226 | static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){ | - | ||||||||||||||||||||||||
| 227 | p->iJD = sqlite3StmtCurrentTime(context); | - | ||||||||||||||||||||||||
| 228 | if( p->iJD>0
| 0-78 | ||||||||||||||||||||||||
| 229 | p->validJD = 1; | - | ||||||||||||||||||||||||
| 230 | return executed 78 times by 1 test: 0;return 0;Executed by:
executed 78 times by 1 test: return 0;Executed by:
| 78 | ||||||||||||||||||||||||
| 231 | }else{ | - | ||||||||||||||||||||||||
| 232 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||||||||||||||||||||
| 233 | } | - | ||||||||||||||||||||||||
| 234 | } | - | ||||||||||||||||||||||||
| 235 | - | |||||||||||||||||||||||||
| 236 | - | |||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||
| 238 | - | |||||||||||||||||||||||||
| 239 | - | |||||||||||||||||||||||||
| 240 | - | |||||||||||||||||||||||||
| 241 | - | |||||||||||||||||||||||||
| 242 | static void setRawDateNumber(DateTime *p, double r){ | - | ||||||||||||||||||||||||
| 243 | p->s = r; | - | ||||||||||||||||||||||||
| 244 | p->rawS = 1; | - | ||||||||||||||||||||||||
| 245 | if( r>=0.0
| 0-4414 | ||||||||||||||||||||||||
| 246 | p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5); | - | ||||||||||||||||||||||||
| 247 | p->validJD = 1; | - | ||||||||||||||||||||||||
| 248 | } executed 3408 times by 1 test: end of blockExecuted by:
| 3408 | ||||||||||||||||||||||||
| 249 | } executed 4414 times by 1 test: end of blockExecuted by:
| 4414 | ||||||||||||||||||||||||
| 250 | static int parseDateOrTime( | - | ||||||||||||||||||||||||
| 251 | sqlite3_context *context, | - | ||||||||||||||||||||||||
| 252 | const char *zDate, | - | ||||||||||||||||||||||||
| 253 | DateTime *p | - | ||||||||||||||||||||||||
| 254 | ){ | - | ||||||||||||||||||||||||
| 255 | double r; | - | ||||||||||||||||||||||||
| 256 | if( parseYyyyMmDd(zDate,p)==0
| 73-219 | ||||||||||||||||||||||||
| 257 | return executed 219 times by 1 test: 0;return 0;Executed by:
executed 219 times by 1 test: return 0;Executed by:
| 219 | ||||||||||||||||||||||||
| 258 | }else if( parseHhMmSs(zDate, p)==0
| 5-68 | ||||||||||||||||||||||||
| 259 | return executed 5 times by 1 test: 0;return 0;Executed by:
executed 5 times by 1 test: return 0;Executed by:
| 5 | ||||||||||||||||||||||||
| 260 | }else if( sqlite3StrICmp(zDate,"now")==0
| 6-46 | ||||||||||||||||||||||||
| 261 | return executed 40 times by 1 test: setDateTimeToCurrent(context, p);return setDateTimeToCurrent(context, p);Executed by:
executed 40 times by 1 test: return setDateTimeToCurrent(context, p);Executed by:
| 40 | ||||||||||||||||||||||||
| 262 | }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), 1)
| 2-26 | ||||||||||||||||||||||||
| 263 | setRawDateNumber(p, r); | - | ||||||||||||||||||||||||
| 264 | return executed 2 times by 1 test: 0;return 0;Executed by:
executed 2 times by 1 test: return 0;Executed by:
| 2 | ||||||||||||||||||||||||
| 265 | } | - | ||||||||||||||||||||||||
| 266 | return executed 26 times by 1 test: 1;return 1;Executed by:
executed 26 times by 1 test: return 1;Executed by:
| 26 | ||||||||||||||||||||||||
| 267 | } | - | ||||||||||||||||||||||||
| 268 | static int validJulianDay(sqlite3_int64 iJD){ | - | ||||||||||||||||||||||||
| 269 | return executed 9168 times by 1 test: iJD>=0return iJD>=0 && iJD<=((((i64)0x1a640)<<32)|0x1072fdff);Executed by:
executed 9168 times by 1 test: return iJD>=0 && iJD<=((((i64)0x1a640)<<32)|0x1072fdff);Executed by:
| 0-9168 | ||||||||||||||||||||||||
| 270 | } | - | ||||||||||||||||||||||||
| 271 | - | |||||||||||||||||||||||||
| 272 | - | |||||||||||||||||||||||||
| 273 | - | |||||||||||||||||||||||||
| 274 | - | |||||||||||||||||||||||||
| 275 | static void computeYMD(DateTime *p){ | - | ||||||||||||||||||||||||
| 276 | int Z, A, B, C, D, E, X1; | - | ||||||||||||||||||||||||
| 277 | if( p->validYMD
executed 108 times by 1 test: return;Executed by:
| 108-4544 | ||||||||||||||||||||||||
| 278 | if( !p->validJD
| 0-4544 | ||||||||||||||||||||||||
| 279 | p->Y = 2000; | - | ||||||||||||||||||||||||
| 280 | p->M = 1; | - | ||||||||||||||||||||||||
| 281 | p->D = 1; | - | ||||||||||||||||||||||||
| 282 | } never executed: else if( !validJulianDay(p->iJD)end of block
| 0-4544 | ||||||||||||||||||||||||
| 283 | datetimeError(p); | - | ||||||||||||||||||||||||
| 284 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 285 | }else{ | - | ||||||||||||||||||||||||
| 286 | Z = (int)((p->iJD + 43200000)/86400000); | - | ||||||||||||||||||||||||
| 287 | A = (int)((Z - 1867216.25)/36524.25); | - | ||||||||||||||||||||||||
| 288 | A = Z + 1 + A - (A/4); | - | ||||||||||||||||||||||||
| 289 | B = A + 1524; | - | ||||||||||||||||||||||||
| 290 | C = (int)((B - 122.1)/365.25); | - | ||||||||||||||||||||||||
| 291 | D = (36525*(C&32767))/100; | - | ||||||||||||||||||||||||
| 292 | E = (int)((B-D)/30.6001); | - | ||||||||||||||||||||||||
| 293 | X1 = (int)(30.6001*E); | - | ||||||||||||||||||||||||
| 294 | p->D = B - D - X1; | - | ||||||||||||||||||||||||
| 295 | p->M = E<14
| 533-4011 | ||||||||||||||||||||||||
| 296 | p->Y = p->M>2
| 533-4011 | ||||||||||||||||||||||||
| 297 | } executed 4544 times by 1 test: end of blockExecuted by:
| 4544 | ||||||||||||||||||||||||
| 298 | p->validYMD = 1; | - | ||||||||||||||||||||||||
| 299 | } executed 4544 times by 1 test: end of blockExecuted by:
| 4544 | ||||||||||||||||||||||||
| 300 | - | |||||||||||||||||||||||||
| 301 | - | |||||||||||||||||||||||||
| 302 | - | |||||||||||||||||||||||||
| 303 | - | |||||||||||||||||||||||||
| 304 | static void computeHMS(DateTime *p){ | - | ||||||||||||||||||||||||
| 305 | int s; | - | ||||||||||||||||||||||||
| 306 | if( p->validHMS
executed 72 times by 1 test: return;Executed by:
| 72-3037 | ||||||||||||||||||||||||
| 307 | computeJD(p); | - | ||||||||||||||||||||||||
| 308 | s = (int)((p->iJD + 43200000) % 86400000); | - | ||||||||||||||||||||||||
| 309 | p->s = s/1000.0; | - | ||||||||||||||||||||||||
| 310 | s = (int)p->s; | - | ||||||||||||||||||||||||
| 311 | p->s -= s; | - | ||||||||||||||||||||||||
| 312 | p->h = s/3600; | - | ||||||||||||||||||||||||
| 313 | s -= p->h*3600; | - | ||||||||||||||||||||||||
| 314 | p->m = s/60; | - | ||||||||||||||||||||||||
| 315 | p->s += s - p->m*60; | - | ||||||||||||||||||||||||
| 316 | p->rawS = 0; | - | ||||||||||||||||||||||||
| 317 | p->validHMS = 1; | - | ||||||||||||||||||||||||
| 318 | } executed 3037 times by 1 test: end of blockExecuted by:
| 3037 | ||||||||||||||||||||||||
| 319 | - | |||||||||||||||||||||||||
| 320 | - | |||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | - | |||||||||||||||||||||||||
| 323 | static void computeYMD_HMS(DateTime *p){ | - | ||||||||||||||||||||||||
| 324 | computeYMD(p); | - | ||||||||||||||||||||||||
| 325 | computeHMS(p); | - | ||||||||||||||||||||||||
| 326 | } executed 3095 times by 1 test: end of blockExecuted by:
| 3095 | ||||||||||||||||||||||||
| 327 | - | |||||||||||||||||||||||||
| 328 | - | |||||||||||||||||||||||||
| 329 | - | |||||||||||||||||||||||||
| 330 | - | |||||||||||||||||||||||||
| 331 | static void clearYMD_HMS_TZ(DateTime *p){ | - | ||||||||||||||||||||||||
| 332 | p->validYMD = 0; | - | ||||||||||||||||||||||||
| 333 | p->validHMS = 0; | - | ||||||||||||||||||||||||
| 334 | p->validTZ = 0; | - | ||||||||||||||||||||||||
| 335 | } executed 1199 times by 1 test: end of blockExecuted by:
| 1199 | ||||||||||||||||||||||||
| 336 | static int osLocaltime(time_t *t, struct tm *pTm){ | - | ||||||||||||||||||||||||
| 337 | int rc; | - | ||||||||||||||||||||||||
| 338 | if( sqlite3Config.bLocaltimeFault
executed 2 times by 1 test: 1;return 1;Executed by:
executed 2 times by 1 test: return 1;Executed by:
| 2-16 | ||||||||||||||||||||||||
| 339 | - | |||||||||||||||||||||||||
| 340 | - | |||||||||||||||||||||||||
| 341 | rc = localtime_r(t, pTm)==0; | - | ||||||||||||||||||||||||
| 342 | - | |||||||||||||||||||||||||
| 343 | - | |||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | - | |||||||||||||||||||||||||
| 346 | return executed 16 times by 1 test: rc;return rc;Executed by:
executed 16 times by 1 test: return rc;Executed by:
| 16 | ||||||||||||||||||||||||
| 347 | } | - | ||||||||||||||||||||||||
| 348 | static sqlite3_int64 localtimeOffset( | - | ||||||||||||||||||||||||
| 349 | DateTime *p, | - | ||||||||||||||||||||||||
| 350 | sqlite3_context *pCtx, | - | ||||||||||||||||||||||||
| 351 | int *pRc | - | ||||||||||||||||||||||||
| 352 | ){ | - | ||||||||||||||||||||||||
| 353 | DateTime x, y; | - | ||||||||||||||||||||||||
| 354 | time_t t; | - | ||||||||||||||||||||||||
| 355 | struct tm sLocal; | - | ||||||||||||||||||||||||
| 356 | - | |||||||||||||||||||||||||
| 357 | - | |||||||||||||||||||||||||
| 358 | memset(&sLocal, 0, sizeof(sLocal)); | - | ||||||||||||||||||||||||
| 359 | - | |||||||||||||||||||||||||
| 360 | x = *p; | - | ||||||||||||||||||||||||
| 361 | computeYMD_HMS(&x); | - | ||||||||||||||||||||||||
| 362 | if( x.Y<1971
| 0-18 | ||||||||||||||||||||||||
| 363 | - | |||||||||||||||||||||||||
| 364 | - | |||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||
| 367 | - | |||||||||||||||||||||||||
| 368 | x.Y = 2000; | - | ||||||||||||||||||||||||
| 369 | x.M = 1; | - | ||||||||||||||||||||||||
| 370 | x.D = 1; | - | ||||||||||||||||||||||||
| 371 | x.h = 0; | - | ||||||||||||||||||||||||
| 372 | x.m = 0; | - | ||||||||||||||||||||||||
| 373 | x.s = 0.0; | - | ||||||||||||||||||||||||
| 374 | } executed 3 times by 1 test: else {end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 375 | int s = (int)(x.s + 0.5); | - | ||||||||||||||||||||||||
| 376 | x.s = s; | - | ||||||||||||||||||||||||
| 377 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||||||||
| 378 | x.tz = 0; | - | ||||||||||||||||||||||||
| 379 | x.validJD = 0; | - | ||||||||||||||||||||||||
| 380 | computeJD(&x); | - | ||||||||||||||||||||||||
| 381 | t = (time_t)(x.iJD/1000 - 21086676*(i64)10000); | - | ||||||||||||||||||||||||
| 382 | if( osLocaltime(&t, &sLocal)
| 2-16 | ||||||||||||||||||||||||
| 383 | sqlite3_result_error(pCtx, "local time unavailable", -1); | - | ||||||||||||||||||||||||
| 384 | *pRc = 1; | - | ||||||||||||||||||||||||
| 385 | return executed 2 times by 1 test: 0;return 0;Executed by:
executed 2 times by 1 test: return 0;Executed by:
| 2 | ||||||||||||||||||||||||
| 386 | } | - | ||||||||||||||||||||||||
| 387 | y.Y = sLocal.tm_year + 1900; | - | ||||||||||||||||||||||||
| 388 | y.M = sLocal.tm_mon + 1; | - | ||||||||||||||||||||||||
| 389 | y.D = sLocal.tm_mday; | - | ||||||||||||||||||||||||
| 390 | y.h = sLocal.tm_hour; | - | ||||||||||||||||||||||||
| 391 | y.m = sLocal.tm_min; | - | ||||||||||||||||||||||||
| 392 | y.s = sLocal.tm_sec; | - | ||||||||||||||||||||||||
| 393 | y.validYMD = 1; | - | ||||||||||||||||||||||||
| 394 | y.validHMS = 1; | - | ||||||||||||||||||||||||
| 395 | y.validJD = 0; | - | ||||||||||||||||||||||||
| 396 | y.rawS = 0; | - | ||||||||||||||||||||||||
| 397 | y.validTZ = 0; | - | ||||||||||||||||||||||||
| 398 | y.isError = 0; | - | ||||||||||||||||||||||||
| 399 | computeJD(&y); | - | ||||||||||||||||||||||||
| 400 | *pRc = 0; | - | ||||||||||||||||||||||||
| 401 | return executed 16 times by 1 test: y.iJD - x.iJD;return y.iJD - x.iJD;Executed by:
executed 16 times by 1 test: return y.iJD - x.iJD;Executed by:
| 16 | ||||||||||||||||||||||||
| 402 | } | - | ||||||||||||||||||||||||
| 403 | static const struct { | - | ||||||||||||||||||||||||
| 404 | u8 eType; | - | ||||||||||||||||||||||||
| 405 | u8 nName; | - | ||||||||||||||||||||||||
| 406 | char *zName; | - | ||||||||||||||||||||||||
| 407 | double rLimit; | - | ||||||||||||||||||||||||
| 408 | double rXform; | - | ||||||||||||||||||||||||
| 409 | } aXformType[] = { | - | ||||||||||||||||||||||||
| 410 | { 0, 6, "second", 464269060800.0, 86400000.0/(24.0*60.0*60.0) }, | - | ||||||||||||||||||||||||
| 411 | { 0, 6, "minute", 7737817680.0, 86400000.0/(24.0*60.0) }, | - | ||||||||||||||||||||||||
| 412 | { 0, 4, "hour", 128963628.0, 86400000.0/24.0 }, | - | ||||||||||||||||||||||||
| 413 | { 0, 3, "day", 5373485.0, 86400000.0 }, | - | ||||||||||||||||||||||||
| 414 | { 1, 5, "month", 176546.0, 30.0*86400000.0 }, | - | ||||||||||||||||||||||||
| 415 | { 2, 4, "year", 14713.0, 365.0*86400000.0 }, | - | ||||||||||||||||||||||||
| 416 | }; | - | ||||||||||||||||||||||||
| 417 | static int parseModifier( | - | ||||||||||||||||||||||||
| 418 | sqlite3_context *pCtx, | - | ||||||||||||||||||||||||
| 419 | const char *z, | - | ||||||||||||||||||||||||
| 420 | int n, | - | ||||||||||||||||||||||||
| 421 | DateTime *p | - | ||||||||||||||||||||||||
| 422 | ){ | - | ||||||||||||||||||||||||
| 423 | int rc = 1; | - | ||||||||||||||||||||||||
| 424 | double r; | - | ||||||||||||||||||||||||
| 425 | switch(sqlite3UpperToLower[(u8)z[0]] ){ | - | ||||||||||||||||||||||||
| 426 | - | |||||||||||||||||||||||||
| 427 | case executed 14 times by 1 test: 'l':case 'l':Executed by:
executed 14 times by 1 test: {case 'l':Executed by:
| 14 | ||||||||||||||||||||||||
| 428 | - | |||||||||||||||||||||||||
| 429 | - | |||||||||||||||||||||||||
| 430 | - | |||||||||||||||||||||||||
| 431 | - | |||||||||||||||||||||||||
| 432 | - | |||||||||||||||||||||||||
| 433 | if( sqlite3_stricmp(z, "localtime")==0
| 0-14 | ||||||||||||||||||||||||
| 434 | computeJD(p); | - | ||||||||||||||||||||||||
| 435 | p->iJD += localtimeOffset(p, pCtx, &rc); | - | ||||||||||||||||||||||||
| 436 | clearYMD_HMS_TZ(p); | - | ||||||||||||||||||||||||
| 437 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 438 | break; executed 14 times by 1 test: break;Executed by:
| 14 | ||||||||||||||||||||||||
| 439 | } | - | ||||||||||||||||||||||||
| 440 | - | |||||||||||||||||||||||||
| 441 | case executed 1018 times by 1 test: 'u':case 'u':Executed by:
executed 1018 times by 1 test: {case 'u':Executed by:
| 1018 | ||||||||||||||||||||||||
| 442 | - | |||||||||||||||||||||||||
| 443 | - | |||||||||||||||||||||||||
| 444 | - | |||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||
| 446 | - | |||||||||||||||||||||||||
| 447 | - | |||||||||||||||||||||||||
| 448 | if( sqlite3_stricmp(z, "unixepoch")==0
| 1-1012 | ||||||||||||||||||||||||
| 449 | r = p->s*1000.0 + 210866760000000.0; | - | ||||||||||||||||||||||||
| 450 | if( r>=0.0
| 0-1011 | ||||||||||||||||||||||||
| 451 | clearYMD_HMS_TZ(p); | - | ||||||||||||||||||||||||
| 452 | p->iJD = (sqlite3_int64)r; | - | ||||||||||||||||||||||||
| 453 | p->validJD = 1; | - | ||||||||||||||||||||||||
| 454 | p->rawS = 0; | - | ||||||||||||||||||||||||
| 455 | rc = 0; | - | ||||||||||||||||||||||||
| 456 | } executed 1011 times by 1 test: end of blockExecuted by:
| 1011 | ||||||||||||||||||||||||
| 457 | } executed 1011 times by 1 test: end of blockExecuted by:
| 1011 | ||||||||||||||||||||||||
| 458 | - | |||||||||||||||||||||||||
| 459 | else if( sqlite3_stricmp(z, "utc")==0
| 1-4 | ||||||||||||||||||||||||
| 460 | if( p->tzSet==0
| 0-3 | ||||||||||||||||||||||||
| 461 | sqlite3_int64 c1; | - | ||||||||||||||||||||||||
| 462 | computeJD(p); | - | ||||||||||||||||||||||||
| 463 | c1 = localtimeOffset(p, pCtx, &rc); | - | ||||||||||||||||||||||||
| 464 | if( rc==0
| 1-2 | ||||||||||||||||||||||||
| 465 | p->iJD -= c1; | - | ||||||||||||||||||||||||
| 466 | clearYMD_HMS_TZ(p); | - | ||||||||||||||||||||||||
| 467 | p->iJD += c1 - localtimeOffset(p, pCtx, &rc); | - | ||||||||||||||||||||||||
| 468 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 469 | p->tzSet = 1; | - | ||||||||||||||||||||||||
| 470 | } executed 3 times by 1 test: else{end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 471 | rc = 0; | - | ||||||||||||||||||||||||
| 472 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 473 | } | - | ||||||||||||||||||||||||
| 474 | - | |||||||||||||||||||||||||
| 475 | break; executed 1018 times by 1 test: break;Executed by:
| 1018 | ||||||||||||||||||||||||
| 476 | } | - | ||||||||||||||||||||||||
| 477 | case executed 24 times by 1 test: 'w':case 'w':Executed by:
executed 24 times by 1 test: {case 'w':Executed by:
| 24 | ||||||||||||||||||||||||
| 478 | - | |||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||
| 480 | - | |||||||||||||||||||||||||
| 481 | - | |||||||||||||||||||||||||
| 482 | - | |||||||||||||||||||||||||
| 483 | - | |||||||||||||||||||||||||
| 484 | - | |||||||||||||||||||||||||
| 485 | if( sqlite3_strnicmp(z, "weekday ", 8)==0
| 1-23 | ||||||||||||||||||||||||
| 486 | && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), 1)
| 2-21 | ||||||||||||||||||||||||
| 487 | && (
| 1-20 | ||||||||||||||||||||||||
| 488 | sqlite3_int64 Z; | - | ||||||||||||||||||||||||
| 489 | computeYMD_HMS(p); | - | ||||||||||||||||||||||||
| 490 | p->validTZ = 0; | - | ||||||||||||||||||||||||
| 491 | p->validJD = 0; | - | ||||||||||||||||||||||||
| 492 | computeJD(p); | - | ||||||||||||||||||||||||
| 493 | Z = ((p->iJD + 129600000)/86400000) % 7; | - | ||||||||||||||||||||||||
| 494 | if( Z>n
executed 11 times by 1 test: Z -= 7;Executed by:
| 7-11 | ||||||||||||||||||||||||
| 495 | p->iJD += (n - Z)*86400000; | - | ||||||||||||||||||||||||
| 496 | clearYMD_HMS_TZ(p); | - | ||||||||||||||||||||||||
| 497 | rc = 0; | - | ||||||||||||||||||||||||
| 498 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||||||||
| 499 | break; executed 24 times by 1 test: break;Executed by:
| 24 | ||||||||||||||||||||||||
| 500 | } | - | ||||||||||||||||||||||||
| 501 | case executed 29 times by 1 test: 's':case 's':Executed by:
executed 29 times by 1 test: {case 's':Executed by:
| 29 | ||||||||||||||||||||||||
| 502 | - | |||||||||||||||||||||||||
| 503 | - | |||||||||||||||||||||||||
| 504 | - | |||||||||||||||||||||||||
| 505 | - | |||||||||||||||||||||||||
| 506 | - | |||||||||||||||||||||||||
| 507 | - | |||||||||||||||||||||||||
| 508 | if( sqlite3_strnicmp(z, "start of ", 9)!=0
executed 1 time by 1 test: break;Executed by:
| 1-28 | ||||||||||||||||||||||||
| 509 | if( !p->validJD
never executed: break; | 0-24 | ||||||||||||||||||||||||
| 510 | z += 9; | - | ||||||||||||||||||||||||
| 511 | computeYMD(p); | - | ||||||||||||||||||||||||
| 512 | p->validHMS = 1; | - | ||||||||||||||||||||||||
| 513 | p->h = p->m = 0; | - | ||||||||||||||||||||||||
| 514 | p->s = 0.0; | - | ||||||||||||||||||||||||
| 515 | p->rawS = 0; | - | ||||||||||||||||||||||||
| 516 | p->validTZ = 0; | - | ||||||||||||||||||||||||
| 517 | p->validJD = 0; | - | ||||||||||||||||||||||||
| 518 | if( sqlite3_stricmp(z,"month")==0
| 8-20 | ||||||||||||||||||||||||
| 519 | p->D = 1; | - | ||||||||||||||||||||||||
| 520 | rc = 0; | - | ||||||||||||||||||||||||
| 521 | } executed 8 times by 1 test: else if( sqlite3_stricmp(z,"year")==0end of blockExecuted by:
| 8-10 | ||||||||||||||||||||||||
| 522 | p->M = 1; | - | ||||||||||||||||||||||||
| 523 | p->D = 1; | - | ||||||||||||||||||||||||
| 524 | rc = 0; | - | ||||||||||||||||||||||||
| 525 | } executed 10 times by 1 test: else if( sqlite3_stricmp(z,"day")==0end of blockExecuted by:
| 1-10 | ||||||||||||||||||||||||
| 526 | rc = 0; | - | ||||||||||||||||||||||||
| 527 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||
| 528 | break; executed 28 times by 1 test: break;Executed by:
| 28 | ||||||||||||||||||||||||
| 529 | } | - | ||||||||||||||||||||||||
| 530 | case executed 72 times by 1 test: '+':case '+':Executed by:
executed 72 times by 1 test: case '+':Executed by:
| 72 | ||||||||||||||||||||||||
| 531 | case executed 63 times by 1 test: '-':case '-':Executed by:
executed 63 times by 1 test: case '-':Executed by:
| 63 | ||||||||||||||||||||||||
| 532 | case executed 2 times by 1 test: '0':case '0':Executed by:
executed 2 times by 1 test: case '0':Executed by:
| 2 | ||||||||||||||||||||||||
| 533 | case executed 14 times by 1 test: '1':case '1':Executed by:
executed 14 times by 1 test: case '1':Executed by:
| 14 | ||||||||||||||||||||||||
| 534 | case executed 1 time by 1 test: '2':case '2':Executed by:
executed 1 time by 1 test: case '2':Executed by:
| 1 | ||||||||||||||||||||||||
| 535 | case executed 1 time by 1 test: '3':case '3':Executed by:
executed 1 time by 1 test: case '3':Executed by:
| 1 | ||||||||||||||||||||||||
| 536 | case executed 1 time by 1 test: '4':case '4':Executed by:
executed 1 time by 1 test: case '4':Executed by:
| 1 | ||||||||||||||||||||||||
| 537 | case executed 1 time by 1 test: '5':case '5':Executed by:
executed 1 time by 1 test: case '5':Executed by:
| 1 | ||||||||||||||||||||||||
| 538 | case executed 1 time by 1 test: '6':case '6':Executed by:
executed 1 time by 1 test: case '6':Executed by:
| 1 | ||||||||||||||||||||||||
| 539 | case executed 1 time by 1 test: '7':case '7':Executed by:
executed 1 time by 1 test: case '7':Executed by:
| 1 | ||||||||||||||||||||||||
| 540 | case executed 1 time by 1 test: '8':case '8':Executed by:
executed 1 time by 1 test: case '8':Executed by:
| 1 | ||||||||||||||||||||||||
| 541 | case executed 1 time by 1 test: '9':case '9':Executed by:
executed 1 time by 1 test: {case '9':Executed by:
| 1 | ||||||||||||||||||||||||
| 542 | double rRounder; | - | ||||||||||||||||||||||||
| 543 | int i; | - | ||||||||||||||||||||||||
| 544 | for(n=1; z[n]
executed 470 times by 1 test: end of blockExecuted by:
| 1-628 | ||||||||||||||||||||||||
| 545 | if( !sqlite3AtoF(z, &r, n, 1)
| 1-158 | ||||||||||||||||||||||||
| 546 | rc = 1; | - | ||||||||||||||||||||||||
| 547 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||||||||
| 548 | } | - | ||||||||||||||||||||||||
| 549 | if( z[n]==':'
| 10-148 | ||||||||||||||||||||||||
| 550 | - | |||||||||||||||||||||||||
| 551 | - | |||||||||||||||||||||||||
| 552 | - | |||||||||||||||||||||||||
| 553 | - | |||||||||||||||||||||||||
| 554 | - | |||||||||||||||||||||||||
| 555 | const char *z2 = z; | - | ||||||||||||||||||||||||
| 556 | DateTime tx; | - | ||||||||||||||||||||||||
| 557 | sqlite3_int64 day; | - | ||||||||||||||||||||||||
| 558 | if( !(sqlite3CtypeMap[(unsigned char)(*z2)]&0x04)
executed 6 times by 1 test: z2++;Executed by:
| 4-6 | ||||||||||||||||||||||||
| 559 | memset(&tx, 0, sizeof(tx)); | - | ||||||||||||||||||||||||
| 560 | if( parseHhMmSs(z2, &tx)
executed 1 time by 1 test: break;Executed by:
| 1-9 | ||||||||||||||||||||||||
| 561 | computeJD(&tx); | - | ||||||||||||||||||||||||
| 562 | tx.iJD -= 43200000; | - | ||||||||||||||||||||||||
| 563 | day = tx.iJD/86400000; | - | ||||||||||||||||||||||||
| 564 | tx.iJD -= day*86400000; | - | ||||||||||||||||||||||||
| 565 | if( z[0]=='-'
executed 4 times by 1 test: tx.iJD = -tx.iJD;Executed by:
| 4-5 | ||||||||||||||||||||||||
| 566 | computeJD(p); | - | ||||||||||||||||||||||||
| 567 | clearYMD_HMS_TZ(p); | - | ||||||||||||||||||||||||
| 568 | p->iJD += tx.iJD; | - | ||||||||||||||||||||||||
| 569 | rc = 0; | - | ||||||||||||||||||||||||
| 570 | break; executed 9 times by 1 test: break;Executed by:
| 9 | ||||||||||||||||||||||||
| 571 | } | - | ||||||||||||||||||||||||
| 572 | - | |||||||||||||||||||||||||
| 573 | - | |||||||||||||||||||||||||
| 574 | - | |||||||||||||||||||||||||
| 575 | z += n; | - | ||||||||||||||||||||||||
| 576 | while( (
executed 148 times by 1 test: z++;Executed by:
| 148 | ||||||||||||||||||||||||
| 577 | n = sqlite3Strlen30(z); | - | ||||||||||||||||||||||||
| 578 | if( n>10
executed 2 times by 1 test: break;Executed by:
| 1-147 | ||||||||||||||||||||||||
| 579 | if( sqlite3UpperToLower[(u8)z[n-1]]=='s'
executed 113 times by 1 test: n--;Executed by:
| 33-113 | ||||||||||||||||||||||||
| 580 | computeJD(p); | - | ||||||||||||||||||||||||
| 581 | rc = 1; | - | ||||||||||||||||||||||||
| 582 | rRounder = r<0
| 59-87 | ||||||||||||||||||||||||
| 583 | for(i=0; i<((int)(sizeof(aXformType)/sizeof(aXformType[0])))
| 20-561 | ||||||||||||||||||||||||
| 584 | if( aXformType[i].nName==n
| 191-370 | ||||||||||||||||||||||||
| 585 | && sqlite3_strnicmp(aXformType[i].zName, z, n)==0
| 53-138 | ||||||||||||||||||||||||
| 586 | && r>-aXformType[i].rLimit
| 6-132 | ||||||||||||||||||||||||
| 587 | ){ | - | ||||||||||||||||||||||||
| 588 | switch( aXformType[i].eType ){ | - | ||||||||||||||||||||||||
| 589 | case executed 22 times by 1 test: 1:case 1:Executed by:
executed 22 times by 1 test: {case 1:Executed by:
| 22 | ||||||||||||||||||||||||
| 590 | int x; | - | ||||||||||||||||||||||||
| 591 | computeYMD_HMS(p); | - | ||||||||||||||||||||||||
| 592 | p->M += (int)r; | - | ||||||||||||||||||||||||
| 593 | x = p->M>0
| 9-13 | ||||||||||||||||||||||||
| 594 | p->Y += x; | - | ||||||||||||||||||||||||
| 595 | p->M -= x*12; | - | ||||||||||||||||||||||||
| 596 | p->validJD = 0; | - | ||||||||||||||||||||||||
| 597 | r -= (int)r; | - | ||||||||||||||||||||||||
| 598 | break; executed 22 times by 1 test: break;Executed by:
| 22 | ||||||||||||||||||||||||
| 599 | } | - | ||||||||||||||||||||||||
| 600 | case executed 21 times by 1 test: 2:case 2:Executed by:
executed 21 times by 1 test: {case 2:Executed by:
| 21 | ||||||||||||||||||||||||
| 601 | int y = (int)r; | - | ||||||||||||||||||||||||
| 602 | computeYMD_HMS(p); | - | ||||||||||||||||||||||||
| 603 | p->Y += y; | - | ||||||||||||||||||||||||
| 604 | p->validJD = 0; | - | ||||||||||||||||||||||||
| 605 | r -= (int)r; | - | ||||||||||||||||||||||||
| 606 | break; executed 21 times by 1 test: break;Executed by:
| 21 | ||||||||||||||||||||||||
| 607 | } | - | ||||||||||||||||||||||||
| 608 | } | - | ||||||||||||||||||||||||
| 609 | computeJD(p); | - | ||||||||||||||||||||||||
| 610 | p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder); | - | ||||||||||||||||||||||||
| 611 | rc = 0; | - | ||||||||||||||||||||||||
| 612 | break; executed 126 times by 1 test: break;Executed by:
| 126 | ||||||||||||||||||||||||
| 613 | } | - | ||||||||||||||||||||||||
| 614 | } executed 435 times by 1 test: end of blockExecuted by:
| 435 | ||||||||||||||||||||||||
| 615 | clearYMD_HMS_TZ(p); | - | ||||||||||||||||||||||||
| 616 | break; executed 146 times by 1 test: break;Executed by:
| 146 | ||||||||||||||||||||||||
| 617 | } | - | ||||||||||||||||||||||||
| 618 | default executed 2 times by 1 test: :default:Executed by:
executed 2 times by 1 test: {default:Executed by:
| 2 | ||||||||||||||||||||||||
| 619 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||||||||
| 620 | } | - | ||||||||||||||||||||||||
| 621 | } | - | ||||||||||||||||||||||||
| 622 | return executed 1246 times by 1 test: rc;return rc;Executed by:
executed 1246 times by 1 test: return rc;Executed by:
| 1246 | ||||||||||||||||||||||||
| 623 | } | - | ||||||||||||||||||||||||
| 624 | static int isDate( | - | ||||||||||||||||||||||||
| 625 | sqlite3_context *context, | - | ||||||||||||||||||||||||
| 626 | int argc, | - | ||||||||||||||||||||||||
| 627 | sqlite3_value **argv, | - | ||||||||||||||||||||||||
| 628 | DateTime *p | - | ||||||||||||||||||||||||
| 629 | ){ | - | ||||||||||||||||||||||||
| 630 | int i, n; | - | ||||||||||||||||||||||||
| 631 | const unsigned char *z; | - | ||||||||||||||||||||||||
| 632 | int eType; | - | ||||||||||||||||||||||||
| 633 | memset(p, 0, sizeof(*p)); | - | ||||||||||||||||||||||||
| 634 | if( argc==0
| 38-4709 | ||||||||||||||||||||||||
| 635 | return executed 38 times by 1 test: setDateTimeToCurrent(context, p);return setDateTimeToCurrent(context, p);Executed by:
executed 38 times by 1 test: return setDateTimeToCurrent(context, p);Executed by:
| 38 | ||||||||||||||||||||||||
| 636 | } | - | ||||||||||||||||||||||||
| 637 | if( (
| 340-4369 | ||||||||||||||||||||||||
| 638 | || eType==1
| 43-297 | ||||||||||||||||||||||||
| 639 | setRawDateNumber(p, sqlite3_value_double(argv[0])); | - | ||||||||||||||||||||||||
| 640 | } executed 4412 times by 1 test: else{end of blockExecuted by:
| 4412 | ||||||||||||||||||||||||
| 641 | z = sqlite3_value_text(argv[0]); | - | ||||||||||||||||||||||||
| 642 | if( !z
| 5-292 | ||||||||||||||||||||||||
| 643 | return executed 31 times by 1 test: 1;return 1;Executed by:
executed 31 times by 1 test: return 1;Executed by:
| 31 | ||||||||||||||||||||||||
| 644 | } | - | ||||||||||||||||||||||||
| 645 | } executed 266 times by 1 test: end of blockExecuted by:
| 266 | ||||||||||||||||||||||||
| 646 | for(i=1; i<argc
| 1258-4625 | ||||||||||||||||||||||||
| 647 | z = sqlite3_value_text(argv[i]); | - | ||||||||||||||||||||||||
| 648 | n = sqlite3_value_bytes(argv[i]); | - | ||||||||||||||||||||||||
| 649 | if( z==0
executed 53 times by 1 test: 1;return 1;Executed by:
executed 53 times by 1 test: return 1;Executed by:
| 12-1246 | ||||||||||||||||||||||||
| 650 | } executed 1205 times by 1 test: end of blockExecuted by:
| 1205 | ||||||||||||||||||||||||
| 651 | computeJD(p); | - | ||||||||||||||||||||||||
| 652 | if( p->isError
executed 2 times by 1 test: 1;return 1;Executed by:
executed 2 times by 1 test: return 1;Executed by:
| 1-4624 | ||||||||||||||||||||||||
| 653 | return executed 4623 times by 1 test: 0;return 0;Executed by:
executed 4623 times by 1 test: return 0;Executed by:
| 4623 | ||||||||||||||||||||||||
| 654 | } | - | ||||||||||||||||||||||||
| 655 | static void juliandayFunc( | - | ||||||||||||||||||||||||
| 656 | sqlite3_context *context, | - | ||||||||||||||||||||||||
| 657 | int argc, | - | ||||||||||||||||||||||||
| 658 | sqlite3_value **argv | - | ||||||||||||||||||||||||
| 659 | ){ | - | ||||||||||||||||||||||||
| 660 | DateTime x; | - | ||||||||||||||||||||||||
| 661 | if( isDate(context, argc, argv, &x)==0
| 18-52 | ||||||||||||||||||||||||
| 662 | computeJD(&x); | - | ||||||||||||||||||||||||
| 663 | sqlite3_result_double(context, x.iJD/86400000.0); | - | ||||||||||||||||||||||||
| 664 | } executed 52 times by 1 test: end of blockExecuted by:
| 52 | ||||||||||||||||||||||||
| 665 | } executed 70 times by 1 test: end of blockExecuted by:
| 70 | ||||||||||||||||||||||||
| 666 | - | |||||||||||||||||||||||||
| 667 | - | |||||||||||||||||||||||||
| 668 | - | |||||||||||||||||||||||||
| 669 | - | |||||||||||||||||||||||||
| 670 | - | |||||||||||||||||||||||||
| 671 | - | |||||||||||||||||||||||||
| 672 | static void datetimeFunc( | - | ||||||||||||||||||||||||
| 673 | sqlite3_context *context, | - | ||||||||||||||||||||||||
| 674 | int argc, | - | ||||||||||||||||||||||||
| 675 | sqlite3_value **argv | - | ||||||||||||||||||||||||
| 676 | ){ | - | ||||||||||||||||||||||||
| 677 | DateTime x; | - | ||||||||||||||||||||||||
| 678 | if( isDate(context, argc, argv, &x)==0
| 47-1953 | ||||||||||||||||||||||||
| 679 | char zBuf[100]; | - | ||||||||||||||||||||||||
| 680 | computeYMD_HMS(&x); | - | ||||||||||||||||||||||||
| 681 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d %02d:%02d:%02d", | - | ||||||||||||||||||||||||
| 682 | x.Y, x.M, x.D, x.h, x.m, (int)(x.s)); | - | ||||||||||||||||||||||||
| 683 | sqlite3_result_text(context, zBuf, -1, ((sqlite3_destructor_type)-1)); | - | ||||||||||||||||||||||||
| 684 | } executed 1953 times by 1 test: end of blockExecuted by:
| 1953 | ||||||||||||||||||||||||
| 685 | } executed 2000 times by 1 test: end of blockExecuted by:
| 2000 | ||||||||||||||||||||||||
| 686 | - | |||||||||||||||||||||||||
| 687 | - | |||||||||||||||||||||||||
| 688 | - | |||||||||||||||||||||||||
| 689 | - | |||||||||||||||||||||||||
| 690 | - | |||||||||||||||||||||||||
| 691 | - | |||||||||||||||||||||||||
| 692 | static void timeFunc( | - | ||||||||||||||||||||||||
| 693 | sqlite3_context *context, | - | ||||||||||||||||||||||||
| 694 | int argc, | - | ||||||||||||||||||||||||
| 695 | sqlite3_value **argv | - | ||||||||||||||||||||||||
| 696 | ){ | - | ||||||||||||||||||||||||
| 697 | DateTime x; | - | ||||||||||||||||||||||||
| 698 | if( isDate(context, argc, argv, &x)==0
| 3-14 | ||||||||||||||||||||||||
| 699 | char zBuf[100]; | - | ||||||||||||||||||||||||
| 700 | computeHMS(&x); | - | ||||||||||||||||||||||||
| 701 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%02d:%02d:%02d", x.h, x.m, (int)x.s); | - | ||||||||||||||||||||||||
| 702 | sqlite3_result_text(context, zBuf, -1, ((sqlite3_destructor_type)-1)); | - | ||||||||||||||||||||||||
| 703 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||||||||
| 704 | } executed 17 times by 1 test: end of blockExecuted by:
| 17 | ||||||||||||||||||||||||
| 705 | - | |||||||||||||||||||||||||
| 706 | - | |||||||||||||||||||||||||
| 707 | - | |||||||||||||||||||||||||
| 708 | - | |||||||||||||||||||||||||
| 709 | - | |||||||||||||||||||||||||
| 710 | - | |||||||||||||||||||||||||
| 711 | static void dateFunc( | - | ||||||||||||||||||||||||
| 712 | sqlite3_context *context, | - | ||||||||||||||||||||||||
| 713 | int argc, | - | ||||||||||||||||||||||||
| 714 | sqlite3_value **argv | - | ||||||||||||||||||||||||
| 715 | ){ | - | ||||||||||||||||||||||||
| 716 | DateTime x; | - | ||||||||||||||||||||||||
| 717 | if( isDate(context, argc, argv, &x)==0
| 15-1529 | ||||||||||||||||||||||||
| 718 | char zBuf[100]; | - | ||||||||||||||||||||||||
| 719 | computeYMD(&x); | - | ||||||||||||||||||||||||
| 720 | sqlite3_snprintf(sizeof(zBuf), zBuf, "%04d-%02d-%02d", x.Y, x.M, x.D); | - | ||||||||||||||||||||||||
| 721 | sqlite3_result_text(context, zBuf, -1, ((sqlite3_destructor_type)-1)); | - | ||||||||||||||||||||||||
| 722 | } executed 1529 times by 1 test: end of blockExecuted by:
| 1529 | ||||||||||||||||||||||||
| 723 | } executed 1544 times by 1 test: end of blockExecuted by:
| 1544 | ||||||||||||||||||||||||
| 724 | static void strftimeFunc( | - | ||||||||||||||||||||||||
| 725 | sqlite3_context *context, | - | ||||||||||||||||||||||||
| 726 | int argc, | - | ||||||||||||||||||||||||
| 727 | sqlite3_value **argv | - | ||||||||||||||||||||||||
| 728 | ){ | - | ||||||||||||||||||||||||
| 729 | DateTime x; | - | ||||||||||||||||||||||||
| 730 | u64 n; | - | ||||||||||||||||||||||||
| 731 | size_t i,j; | - | ||||||||||||||||||||||||
| 732 | char *z; | - | ||||||||||||||||||||||||
| 733 | sqlite3 *db; | - | ||||||||||||||||||||||||
| 734 | const char *zFmt; | - | ||||||||||||||||||||||||
| 735 | char zBuf[100]; | - | ||||||||||||||||||||||||
| 736 | if( argc==0
executed 2 times by 1 test: return;Executed by:
| 2-1117 | ||||||||||||||||||||||||
| 737 | zFmt = (const char*)sqlite3_value_text(argv[0]); | - | ||||||||||||||||||||||||
| 738 | if( zFmt==0
executed 4 times by 1 test: return;Executed by:
| 1-1116 | ||||||||||||||||||||||||
| 739 | db = sqlite3_context_db_handle(context); | - | ||||||||||||||||||||||||
| 740 | for(i=0, n=1; zFmt[i]
| 1063-6846 | ||||||||||||||||||||||||
| 741 | if( zFmt[i]=='%'
| 3274-3572 | ||||||||||||||||||||||||
| 742 | switch( zFmt[i+1] ){ | - | ||||||||||||||||||||||||
| 743 | case executed 11 times by 1 test: 'd':case 'd':Executed by:
executed 11 times by 1 test: case 'd':Executed by:
| 11 | ||||||||||||||||||||||||
| 744 | case executed 1010 times by 1 test: 'H':case 'H':Executed by:
executed 1010 times by 1 test: case 'H':Executed by:
| 1010 | ||||||||||||||||||||||||
| 745 | case executed 211 times by 1 test: 'm':case 'm':Executed by:
executed 211 times by 1 test: case 'm':Executed by:
| 211 | ||||||||||||||||||||||||
| 746 | case executed 1010 times by 1 test: 'M':case 'M':Executed by:
executed 1010 times by 1 test: case 'M':Executed by:
| 1010 | ||||||||||||||||||||||||
| 747 | case executed 5 times by 1 test: 'S':case 'S':Executed by:
executed 5 times by 1 test: case 'S':Executed by:
| 5 | ||||||||||||||||||||||||
| 748 | case executed 27 times by 1 test: 'W':case 'W':Executed by:
executed 27 times by 1 test: case 'W':Executed by:
| 27 | ||||||||||||||||||||||||
| 749 | n++; | - | ||||||||||||||||||||||||
| 750 | - | |||||||||||||||||||||||||
| 751 | case executed 1 time by 1 test: 'w':case 'w':Executed by:
executed 1 time by 1 test: case 'w':Executed by:
code before this statement executed 2274 times by 1 test: case 'w':Executed by:
| 1-2274 | ||||||||||||||||||||||||
| 752 | case executed 1 time by 1 test: '%':case '%':Executed by:
executed 1 time by 1 test: case '%':Executed by:
| 1 | ||||||||||||||||||||||||
| 753 | break; executed 2276 times by 1 test: break;Executed by:
| 2276 | ||||||||||||||||||||||||
| 754 | case executed 1007 times by 1 test: 'f':case 'f':Executed by:
executed 1007 times by 1 test: case 'f':Executed by:
| 1007 | ||||||||||||||||||||||||
| 755 | n += 8; | - | ||||||||||||||||||||||||
| 756 | break; executed 1007 times by 1 test: break;Executed by:
| 1007 | ||||||||||||||||||||||||
| 757 | case executed 14 times by 1 test: 'j':case 'j':Executed by:
executed 14 times by 1 test: case 'j':Executed by:
| 14 | ||||||||||||||||||||||||
| 758 | n += 3; | - | ||||||||||||||||||||||||
| 759 | break; executed 14 times by 1 test: break;Executed by:
| 14 | ||||||||||||||||||||||||
| 760 | case executed 211 times by 1 test: 'Y':case 'Y':Executed by:
executed 211 times by 1 test: case 'Y':Executed by:
| 211 | ||||||||||||||||||||||||
| 761 | n += 8; | - | ||||||||||||||||||||||||
| 762 | break; executed 211 times by 1 test: break;Executed by:
| 211 | ||||||||||||||||||||||||
| 763 | case executed 13 times by 1 test: 's':case 's':Executed by:
executed 13 times by 1 test: case 's':Executed by:
| 13 | ||||||||||||||||||||||||
| 764 | case executed 1 time by 1 test: 'J':case 'J':Executed by:
executed 1 time by 1 test: case 'J':Executed by:
| 1 | ||||||||||||||||||||||||
| 765 | n += 50; | - | ||||||||||||||||||||||||
| 766 | break; executed 14 times by 1 test: break;Executed by:
| 14 | ||||||||||||||||||||||||
| 767 | default executed 50 times by 1 test: :default:Executed by:
executed 50 times by 1 test: default:Executed by:
| 50 | ||||||||||||||||||||||||
| 768 | return; executed 50 times by 1 test: return;Executed by:
| 50 | ||||||||||||||||||||||||
| 769 | } | - | ||||||||||||||||||||||||
| 770 | i++; | - | ||||||||||||||||||||||||
| 771 | } executed 3522 times by 1 test: end of blockExecuted by:
| 3522 | ||||||||||||||||||||||||
| 772 | } executed 6796 times by 1 test: end of blockExecuted by:
| 6796 | ||||||||||||||||||||||||
| 773 | ; | - | ||||||||||||||||||||||||
| 774 | ; | - | ||||||||||||||||||||||||
| 775 | ; | - | ||||||||||||||||||||||||
| 776 | ; | - | ||||||||||||||||||||||||
| 777 | if( n<sizeof(zBuf)
| 2-1061 | ||||||||||||||||||||||||
| 778 | z = zBuf; | - | ||||||||||||||||||||||||
| 779 | } executed 1061 times by 1 test: else if( n>(u64)db->aLimit[0]end of blockExecuted by:
| 0-1061 | ||||||||||||||||||||||||
| 780 | sqlite3_result_error_toobig(context); | - | ||||||||||||||||||||||||
| 781 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 782 | }else{ | - | ||||||||||||||||||||||||
| 783 | z = sqlite3DbMallocRawNN(db, (int)n); | - | ||||||||||||||||||||||||
| 784 | if( z==0
| 0-2 | ||||||||||||||||||||||||
| 785 | sqlite3_result_error_nomem(context); | - | ||||||||||||||||||||||||
| 786 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 787 | } | - | ||||||||||||||||||||||||
| 788 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 789 | computeJD(&x); | - | ||||||||||||||||||||||||
| 790 | computeYMD_HMS(&x); | - | ||||||||||||||||||||||||
| 791 | for(i=j=0; zFmt[i]
| 1063-6796 | ||||||||||||||||||||||||
| 792 | if( zFmt[i]!='%'
| 3274-3522 | ||||||||||||||||||||||||
| 793 | z[j++] = zFmt[i]; | - | ||||||||||||||||||||||||
| 794 | } executed 3274 times by 1 test: else{end of blockExecuted by:
| 3274 | ||||||||||||||||||||||||
| 795 | i++; | - | ||||||||||||||||||||||||
| 796 | switch( zFmt[i] ){ | - | ||||||||||||||||||||||||
| 797 | case executed 11 times by 1 test: 'd':case 'd':Executed by:
executed 11 times by 1 test: sqlite3_snprintf(3, &z[j],"%02d",x.D); j+=2; break;case 'd':Executed by:
executed 11 times by 1 test: break;Executed by:
| 11 | ||||||||||||||||||||||||
| 798 | case executed 1007 times by 1 test: 'f':case 'f':Executed by:
executed 1007 times by 1 test: {case 'f':Executed by:
| 1007 | ||||||||||||||||||||||||
| 799 | double s = x.s; | - | ||||||||||||||||||||||||
| 800 | if( s>59.999
executed 1 time by 1 test: s = 59.999;Executed by:
| 1-1006 | ||||||||||||||||||||||||
| 801 | sqlite3_snprintf(7, &z[j],"%06.3f", s); | - | ||||||||||||||||||||||||
| 802 | j += sqlite3Strlen30(&z[j]); | - | ||||||||||||||||||||||||
| 803 | break; executed 1007 times by 1 test: break;Executed by:
| 1007 | ||||||||||||||||||||||||
| 804 | } | - | ||||||||||||||||||||||||
| 805 | case executed 1010 times by 1 test: 'H':case 'H':Executed by:
executed 1010 times by 1 test: sqlite3_snprintf(3, &z[j],"%02d",x.h); j+=2; break;case 'H':Executed by:
executed 1010 times by 1 test: break;Executed by:
| 1010 | ||||||||||||||||||||||||
| 806 | case executed 27 times by 1 test: 'W':case 'W':Executed by:
executed 27 times by 1 test: case 'W':Executed by:
| 27 | ||||||||||||||||||||||||
| 807 | case executed 14 times by 1 test: 'j':case 'j':Executed by:
executed 14 times by 1 test: {case 'j':Executed by:
| 14 | ||||||||||||||||||||||||
| 808 | int nDay; | - | ||||||||||||||||||||||||
| 809 | DateTime y = x; | - | ||||||||||||||||||||||||
| 810 | y.validJD = 0; | - | ||||||||||||||||||||||||
| 811 | y.M = 1; | - | ||||||||||||||||||||||||
| 812 | y.D = 1; | - | ||||||||||||||||||||||||
| 813 | computeJD(&y); | - | ||||||||||||||||||||||||
| 814 | nDay = (int)((x.iJD-y.iJD+43200000)/86400000); | - | ||||||||||||||||||||||||
| 815 | if( zFmt[i]=='W'
| 14-27 | ||||||||||||||||||||||||
| 816 | int wd; | - | ||||||||||||||||||||||||
| 817 | wd = (int)(((x.iJD+43200000)/86400000)%7); | - | ||||||||||||||||||||||||
| 818 | sqlite3_snprintf(3, &z[j],"%02d",(nDay+7-wd)/7); | - | ||||||||||||||||||||||||
| 819 | j += 2; | - | ||||||||||||||||||||||||
| 820 | } executed 27 times by 1 test: else{end of blockExecuted by:
| 27 | ||||||||||||||||||||||||
| 821 | sqlite3_snprintf(4, &z[j],"%03d",nDay+1); | - | ||||||||||||||||||||||||
| 822 | j += 3; | - | ||||||||||||||||||||||||
| 823 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||||||||
| 824 | break; executed 41 times by 1 test: break;Executed by:
| 41 | ||||||||||||||||||||||||
| 825 | } | - | ||||||||||||||||||||||||
| 826 | case executed 1 time by 1 test: 'J':case 'J':Executed by:
executed 1 time by 1 test: {case 'J':Executed by:
| 1 | ||||||||||||||||||||||||
| 827 | sqlite3_snprintf(20, &z[j],"%.16g",x.iJD/86400000.0); | - | ||||||||||||||||||||||||
| 828 | j+=sqlite3Strlen30(&z[j]); | - | ||||||||||||||||||||||||
| 829 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||||||||
| 830 | } | - | ||||||||||||||||||||||||
| 831 | case executed 211 times by 1 test: 'm':case 'm':Executed by:
executed 211 times by 1 test: sqlite3_snprintf(3, &z[j],"%02d",x.M); j+=2; break;case 'm':Executed by:
executed 211 times by 1 test: break;Executed by:
| 211 | ||||||||||||||||||||||||
| 832 | case executed 1010 times by 1 test: 'M':case 'M':Executed by:
executed 1010 times by 1 test: sqlite3_snprintf(3, &z[j],"%02d",x.m); j+=2; break;case 'M':Executed by:
executed 1010 times by 1 test: break;Executed by:
| 1010 | ||||||||||||||||||||||||
| 833 | case executed 13 times by 1 test: 's':case 's':Executed by:
executed 13 times by 1 test: {case 's':Executed by:
| 13 | ||||||||||||||||||||||||
| 834 | sqlite3_snprintf(30,&z[j],"%lld", | - | ||||||||||||||||||||||||
| 835 | (i64)(x.iJD/1000 - 21086676*(i64)10000)); | - | ||||||||||||||||||||||||
| 836 | j += sqlite3Strlen30(&z[j]); | - | ||||||||||||||||||||||||
| 837 | break; executed 13 times by 1 test: break;Executed by:
| 13 | ||||||||||||||||||||||||
| 838 | } | - | ||||||||||||||||||||||||
| 839 | case executed 5 times by 1 test: 'S':case 'S':Executed by:
executed 5 times by 1 test: sqlite3_snprintf(3,&z[j],"%02d",(int)x.s); j+=2; break;case 'S':Executed by:
executed 5 times by 1 test: break;Executed by:
| 5 | ||||||||||||||||||||||||
| 840 | case executed 1 time by 1 test: 'w':case 'w':Executed by:
executed 1 time by 1 test: {case 'w':Executed by:
| 1 | ||||||||||||||||||||||||
| 841 | z[j++] = (char)(((x.iJD+129600000)/86400000) % 7) + '0'; | - | ||||||||||||||||||||||||
| 842 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||||||||
| 843 | } | - | ||||||||||||||||||||||||
| 844 | case executed 211 times by 1 test: 'Y':case 'Y':Executed by:
executed 211 times by 1 test: {case 'Y':Executed by:
| 211 | ||||||||||||||||||||||||
| 845 | sqlite3_snprintf(5,&z[j],"%04d",x.Y); j+=sqlite3Strlen30(&z[j]); | - | ||||||||||||||||||||||||
| 846 | break; executed 211 times by 1 test: break;Executed by:
| 211 | ||||||||||||||||||||||||
| 847 | } | - | ||||||||||||||||||||||||
| 848 | default executed 1 time by 1 test: :default:Executed by:
executed 1 time by 1 test: z[j++] = '%'; break;default:Executed by:
executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||||||||
| 849 | } | - | ||||||||||||||||||||||||
| 850 | } | - | ||||||||||||||||||||||||
| 851 | } | - | ||||||||||||||||||||||||
| 852 | z[j] = 0; | - | ||||||||||||||||||||||||
| 853 | sqlite3_result_text(context, z, -1, | - | ||||||||||||||||||||||||
| 854 | z==zBuf ? ((sqlite3_destructor_type)-1) : ((sqlite3_destructor_type)sqlite3MallocSize)); | - | ||||||||||||||||||||||||
| 855 | } executed 1063 times by 1 test: end of blockExecuted by:
| 1063 | ||||||||||||||||||||||||
| 856 | - | |||||||||||||||||||||||||
| 857 | - | |||||||||||||||||||||||||
| 858 | - | |||||||||||||||||||||||||
| 859 | - | |||||||||||||||||||||||||
| 860 | - | |||||||||||||||||||||||||
| 861 | - | |||||||||||||||||||||||||
| 862 | static void ctimeFunc( | - | ||||||||||||||||||||||||
| 863 | sqlite3_context *context, | - | ||||||||||||||||||||||||
| 864 | int NotUsed, | - | ||||||||||||||||||||||||
| 865 | sqlite3_value **NotUsed2 | - | ||||||||||||||||||||||||
| 866 | ){ | - | ||||||||||||||||||||||||
| 867 | (void)(NotUsed),(void)(NotUsed2); | - | ||||||||||||||||||||||||
| 868 | timeFunc(context, 0, 0); | - | ||||||||||||||||||||||||
| 869 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||||||||
| 870 | - | |||||||||||||||||||||||||
| 871 | - | |||||||||||||||||||||||||
| 872 | - | |||||||||||||||||||||||||
| 873 | - | |||||||||||||||||||||||||
| 874 | - | |||||||||||||||||||||||||
| 875 | - | |||||||||||||||||||||||||
| 876 | static void cdateFunc( | - | ||||||||||||||||||||||||
| 877 | sqlite3_context *context, | - | ||||||||||||||||||||||||
| 878 | int NotUsed, | - | ||||||||||||||||||||||||
| 879 | sqlite3_value **NotUsed2 | - | ||||||||||||||||||||||||
| 880 | ){ | - | ||||||||||||||||||||||||
| 881 | (void)(NotUsed),(void)(NotUsed2); | - | ||||||||||||||||||||||||
| 882 | dateFunc(context, 0, 0); | - | ||||||||||||||||||||||||
| 883 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||||||||
| 884 | - | |||||||||||||||||||||||||
| 885 | - | |||||||||||||||||||||||||
| 886 | - | |||||||||||||||||||||||||
| 887 | - | |||||||||||||||||||||||||
| 888 | - | |||||||||||||||||||||||||
| 889 | - | |||||||||||||||||||||||||
| 890 | static void ctimestampFunc( | - | ||||||||||||||||||||||||
| 891 | sqlite3_context *context, | - | ||||||||||||||||||||||||
| 892 | int NotUsed, | - | ||||||||||||||||||||||||
| 893 | sqlite3_value **NotUsed2 | - | ||||||||||||||||||||||||
| 894 | ){ | - | ||||||||||||||||||||||||
| 895 | (void)(NotUsed),(void)(NotUsed2); | - | ||||||||||||||||||||||||
| 896 | datetimeFunc(context, 0, 0); | - | ||||||||||||||||||||||||
| 897 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 898 | void sqlite3RegisterDateTimeFunctions(void){ | - | ||||||||||||||||||||||||
| 899 | static FuncDef aDateTimeFuncs[] = { | - | ||||||||||||||||||||||||
| 900 | - | |||||||||||||||||||||||||
| 901 | {-1, 0x2000|1|0x0800, (void*)&sqlite3Config, 0, juliandayFunc, 0, 0, 0, "julianday", {0} }, | - | ||||||||||||||||||||||||
| 902 | {-1, 0x2000|1|0x0800, (void*)&sqlite3Config, 0, dateFunc, 0, 0, 0, "date", {0} }, | - | ||||||||||||||||||||||||
| 903 | {-1, 0x2000|1|0x0800, (void*)&sqlite3Config, 0, timeFunc, 0, 0, 0, "time", {0} }, | - | ||||||||||||||||||||||||
| 904 | {-1, 0x2000|1|0x0800, (void*)&sqlite3Config, 0, datetimeFunc, 0, 0, 0, "datetime", {0} }, | - | ||||||||||||||||||||||||
| 905 | {-1, 0x2000|1|0x0800, (void*)&sqlite3Config, 0, strftimeFunc, 0, 0, 0, "strftime", {0} }, | - | ||||||||||||||||||||||||
| 906 | {0, 0x2000|1, 0, 0, ctimeFunc, 0, 0, 0, "current_time", {0} }, | - | ||||||||||||||||||||||||
| 907 | {0, 0x2000|1, 0, 0, ctimestampFunc, 0, 0, 0, "current_timestamp", {0} }, | - | ||||||||||||||||||||||||
| 908 | {0, 0x2000|1, 0, 0, cdateFunc, 0, 0, 0, "current_date", {0} }, | - | ||||||||||||||||||||||||
| 909 | - | |||||||||||||||||||||||||
| 910 | - | |||||||||||||||||||||||||
| 911 | - | |||||||||||||||||||||||||
| 912 | - | |||||||||||||||||||||||||
| 913 | - | |||||||||||||||||||||||||
| 914 | }; | - | ||||||||||||||||||||||||
| 915 | sqlite3InsertBuiltinFuncs(aDateTimeFuncs, ((int)(sizeof(aDateTimeFuncs)/sizeof(aDateTimeFuncs[0])))); | - | ||||||||||||||||||||||||
| 916 | } executed 534 times by 438 tests: end of blockExecuted by:
| 534 | ||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |