Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch hex-literal Excluding Merge-Ins
This is equivalent to a diff from 48f40861 to a3cc027f
2014-07-24
| ||
12:19 | Add support for hexadecimal integer literals in the parser. (check-in: f8f79f28 user: drh tags: trunk) | |
2014-07-23
| ||
19:04 | Enhancements to the hex literal tests. (Closed-Leaf check-in: a3cc027f user: mistachkin tags: hex-literal) | |
15:51 | Updated documentation on sqlite3_temp_directory. No changes to code. (check-in: e6225a7b user: drh tags: trunk) | |
14:52 | Remove a surplus function prototype. #ifdef code that is not used when hex integers are omitted at compile time. (check-in: a5b383e0 user: drh tags: hex-literal) | |
01:26 | Add support for parsing C-style hexadecimal literals. (check-in: 34a1f38b user: drh tags: hex-literal) | |
2014-07-22
| ||
22:46 | When running ANALYZE, it is not necessary to check the right-most key column for changes since that column will always change if none of the previous columns have. (check-in: 48f40861 user: drh tags: trunk) | |
20:02 | Add the OP_ReopenIdx opcode that works like OP_OpenRead except that it becomes a no-op if the cursor is already open on the same index. Update the OR-optimization logic to make use of OP_ReopenIdx in order to avoid unnecessary cursor open requests sent to the B-Tree layer. (check-in: 77f412ca user: drh tags: trunk) | |
Changes to src/expr.c.
︙ | ︙ | |||
2071 2072 2073 2074 2075 2076 2077 | if( negFlag ) i = -i; sqlite3VdbeAddOp2(v, OP_Integer, i, iMem); }else{ int c; i64 value; const char *z = pExpr->u.zToken; assert( z!=0 ); | | > > > > > > | > | 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 | if( negFlag ) i = -i; sqlite3VdbeAddOp2(v, OP_Integer, i, iMem); }else{ int c; i64 value; const char *z = pExpr->u.zToken; assert( z!=0 ); c = sqlite3DecOrHexToI64(z, &value); if( c==0 || (c==2 && negFlag) ){ char *zV; if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; } zV = dup8bytes(v, (char*)&value); sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64); }else{ #ifdef SQLITE_OMIT_FLOATING_POINT sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z); #else #ifndef SQLITE_OMIT_HEX_INTEGER if( sqlite3_strnicmp(z,"0x",2)==0 ){ sqlite3ErrorMsg(pParse, "hex literal too big: %s", z); }else #endif { codeReal(v, z, negFlag, iMem); } #endif } } } /* ** Clear a cache entry. |
︙ | ︙ |
Changes to src/main.c.
︙ | ︙ | |||
3405 3406 3407 3408 3409 3410 3411 | sqlite3_int64 sqlite3_uri_int64( const char *zFilename, /* Filename as passed to xOpen */ const char *zParam, /* URI parameter sought */ sqlite3_int64 bDflt /* return if parameter is missing */ ){ const char *z = sqlite3_uri_parameter(zFilename, zParam); sqlite3_int64 v; | | | 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 | sqlite3_int64 sqlite3_uri_int64( const char *zFilename, /* Filename as passed to xOpen */ const char *zParam, /* URI parameter sought */ sqlite3_int64 bDflt /* return if parameter is missing */ ){ const char *z = sqlite3_uri_parameter(zFilename, zParam); sqlite3_int64 v; if( z && sqlite3DecOrHexToI64(z, &v)==SQLITE_OK ){ bDflt = v; } return bDflt; } /* ** Return the Btree pointer identified by zDbName. Return NULL if not found. |
︙ | ︙ |
Changes to src/pragma.c.
︙ | ︙ | |||
1044 1045 1046 1047 1048 1049 1050 | ** ** Get or set the size limit on rollback journal files. */ case PragTyp_JOURNAL_SIZE_LIMIT: { Pager *pPager = sqlite3BtreePager(pDb->pBt); i64 iLimit = -2; if( zRight ){ | | | 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | ** ** Get or set the size limit on rollback journal files. */ case PragTyp_JOURNAL_SIZE_LIMIT: { Pager *pPager = sqlite3BtreePager(pDb->pBt); i64 iLimit = -2; if( zRight ){ sqlite3DecOrHexToI64(zRight, &iLimit); if( iLimit<-1 ) iLimit = -1; } iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit); returnSingleInt(pParse, "journal_size_limit", iLimit); break; } |
︙ | ︙ | |||
1172 1173 1174 1175 1176 1177 1178 | */ case PragTyp_MMAP_SIZE: { sqlite3_int64 sz; #if SQLITE_MAX_MMAP_SIZE>0 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); if( zRight ){ int ii; | | | 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 | */ case PragTyp_MMAP_SIZE: { sqlite3_int64 sz; #if SQLITE_MAX_MMAP_SIZE>0 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); if( zRight ){ int ii; sqlite3DecOrHexToI64(zRight, &sz); if( sz<0 ) sz = sqlite3GlobalConfig.szMmap; if( pId2->n==0 ) db->szMmap = sz; for(ii=db->nDb-1; ii>=0; ii--){ if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){ sqlite3BtreeSetMmapLimit(db->aDb[ii].pBt, sz); } } |
︙ | ︙ | |||
2215 2216 2217 2218 2219 2220 2221 | ** PRAGMA soft_heap_limit = N ** ** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted, ** use -1. */ case PragTyp_SOFT_HEAP_LIMIT: { sqlite3_int64 N; | | | 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 | ** PRAGMA soft_heap_limit = N ** ** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted, ** use -1. */ case PragTyp_SOFT_HEAP_LIMIT: { sqlite3_int64 N; if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){ sqlite3_soft_heap_limit64(N); } returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1)); break; } #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
︙ | ︙ |
Changes to src/sqliteInt.h.
︙ | ︙ | |||
3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 | const char *sqlite3IndexAffinityStr(Vdbe *, Index *); void sqlite3TableAffinity(Vdbe*, Table*, int); char sqlite3CompareAffinity(Expr *pExpr, char aff2); int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); char sqlite3ExprAffinity(Expr *pExpr); int sqlite3Atoi64(const char*, i64*, int, u8); void sqlite3Error(sqlite3*, int, const char*,...); void *sqlite3HexToBlob(sqlite3*, const char *z, int n); u8 sqlite3HexToInt(int h); int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); #if defined(SQLITE_TEST) const char *sqlite3ErrName(int); | > | 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 | const char *sqlite3IndexAffinityStr(Vdbe *, Index *); void sqlite3TableAffinity(Vdbe*, Table*, int); char sqlite3CompareAffinity(Expr *pExpr, char aff2); int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); char sqlite3ExprAffinity(Expr *pExpr); int sqlite3Atoi64(const char*, i64*, int, u8); int sqlite3DecOrHexToI64(const char*, i64*); void sqlite3Error(sqlite3*, int, const char*,...); void *sqlite3HexToBlob(sqlite3*, const char *z, int n); u8 sqlite3HexToInt(int h); int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); #if defined(SQLITE_TEST) const char *sqlite3ErrName(int); |
︙ | ︙ |
Changes to src/tokenize.c.
︙ | ︙ | |||
266 267 268 269 270 271 272 273 274 275 276 277 278 279 | case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' ); testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' ); testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' ); testcase( z[0]=='9' ); *tokenType = TK_INTEGER; for(i=0; sqlite3Isdigit(z[i]); i++){} #ifndef SQLITE_OMIT_FLOATING_POINT if( z[i]=='.' ){ i++; while( sqlite3Isdigit(z[i]) ){ i++; } *tokenType = TK_FLOAT; } | > > > > > > | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' ); testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' ); testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' ); testcase( z[0]=='9' ); *tokenType = TK_INTEGER; #ifndef SQLITE_OMIT_HEX_INTEGER if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){ for(i=3; sqlite3Isxdigit(z[i]); i++){} return i; } #endif for(i=0; sqlite3Isdigit(z[i]); i++){} #ifndef SQLITE_OMIT_FLOATING_POINT if( z[i]=='.' ){ i++; while( sqlite3Isdigit(z[i]) ){ i++; } *tokenType = TK_FLOAT; } |
︙ | ︙ |
Changes to src/util.c.
︙ | ︙ | |||
471 472 473 474 475 476 477 | testcase( c==(-1) ); testcase( c==0 ); testcase( c==(+1) ); } return c; } | < | > | 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | testcase( c==(-1) ); testcase( c==0 ); testcase( c==(+1) ); } return c; } /* ** Convert zNum to a 64-bit signed integer. zNum must be decimal. This ** routine does *not* accept hexadecimal notation. ** ** If the zNum value is representable as a 64-bit twos-complement ** integer, then write that value into *pNum and return 0. ** ** If zNum is exactly 9223372036854775808, return 2. This special ** case is broken out because while 9223372036854775808 cannot be a ** signed 64-bit integer, its negative -9223372036854775808 can be. |
︙ | ︙ | |||
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | /* zNum is exactly 9223372036854775808. Fits if negative. The ** special case 2 overflow if positive */ assert( u-1==LARGEST_INT64 ); return neg ? 0 : 2; } } } /* ** If zNum represents an integer that will fit in 32-bits, then set ** *pValue to that integer and return true. Otherwise return false. ** ** Any non-numeric characters that following zNum are ignored. ** This is different from sqlite3Atoi64() which requires the ** input number to be zero-terminated. */ int sqlite3GetInt32(const char *zNum, int *pValue){ sqlite_int64 v = 0; int i, c; int neg = 0; if( zNum[0]=='-' ){ neg = 1; zNum++; }else if( zNum[0]=='+' ){ zNum++; } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > | 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | /* zNum is exactly 9223372036854775808. Fits if negative. The ** special case 2 overflow if positive */ assert( u-1==LARGEST_INT64 ); return neg ? 0 : 2; } } } /* ** Transform a UTF-8 integer literal, in either decimal or hexadecimal, ** into a 64-bit signed integer. This routine accepts hexadecimal literals, ** whereas sqlite3Atoi64() does not. ** ** Returns: ** ** 0 Successful transformation. Fits in a 64-bit signed integer. ** 1 Integer too large for a 64-bit signed integer or is malformed ** 2 Special case of 9223372036854775808 */ int sqlite3DecOrHexToI64(const char *z, i64 *pOut){ #ifndef SQLITE_OMIT_HEX_INTEGER if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){ u64 u = 0; int i, k; for(i=2; z[i]=='0'; i++){} for(k=i; sqlite3Isxdigit(z[k]); k++){ u = u*16 + sqlite3HexToInt(z[k]); } memcpy(pOut, &u, 8); return (z[k]==0 && k-i<=16) ? 0 : 1; }else #endif /* SQLITE_OMIT_HEX_INTEGER */ { return sqlite3Atoi64(z, pOut, sqlite3Strlen30(z), SQLITE_UTF8); } } /* ** If zNum represents an integer that will fit in 32-bits, then set ** *pValue to that integer and return true. Otherwise return false. ** ** This routine accepts both decimal and hexadecimal notation for integers. ** ** Any non-numeric characters that following zNum are ignored. ** This is different from sqlite3Atoi64() which requires the ** input number to be zero-terminated. */ int sqlite3GetInt32(const char *zNum, int *pValue){ sqlite_int64 v = 0; int i, c; int neg = 0; if( zNum[0]=='-' ){ neg = 1; zNum++; }else if( zNum[0]=='+' ){ zNum++; } #ifndef SQLITE_OMIT_HEX_INTEGER else if( zNum[0]=='0' && (zNum[1]=='x' || zNum[1]=='X') && sqlite3Isxdigit(zNum[2]) ){ u32 u = 0; zNum += 2; while( zNum[0]=='0' ) zNum++; for(i=0; sqlite3Isxdigit(zNum[i]) && i<8; i++){ u = u*16 + sqlite3HexToInt(zNum[i]); } if( (u&0x80000000)==0 && sqlite3Isxdigit(zNum[i])==0 ){ memcpy(pValue, &u, 4); return 1; }else{ return 0; } } #endif for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){ v = v*10 + c; } /* The longest decimal representation of a 32 bit integer is 10 digits: ** ** 1234567890 |
︙ | ︙ |
Added test/hexlit.test.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | # 2014-07-23 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # # This file implements tests for hexadecimal literals set testdir [file dirname $argv0] source $testdir/tester.tcl proc hexlit1 {tnum val ans} { do_execsql_test hexlit-$tnum "SELECT $val" $ans } hexlit1 100 0x0 0 hexlit1 101 0x0000000000000000000000000000000000000000000001 1 hexlit1 102 0x2 2 hexlit1 103 0x4 4 hexlit1 104 0x8 8 hexlit1 105 0x00000000000000000000000000000000000000000000010 16 hexlit1 103 0x20 32 hexlit1 106 0x40 64 hexlit1 107 0x80 128 hexlit1 108 0x100 256 hexlit1 109 0x200 512 hexlit1 110 0X400 1024 hexlit1 111 0x800 2048 hexlit1 112 0x1000 4096 hexlit1 113 0x2000 8192 hexlit1 114 0x4000 16384 hexlit1 115 0x8000 32768 hexlit1 116 0x10000 65536 hexlit1 117 0x20000 131072 hexlit1 118 0x40000 262144 hexlit1 119 0x80000 524288 hexlit1 120 0x100000 1048576 hexlit1 121 0x200000 2097152 hexlit1 122 0x400000 4194304 hexlit1 123 0x800000 8388608 hexlit1 124 0x1000000 16777216 hexlit1 125 0x2000000 33554432 hexlit1 126 0x4000000 67108864 hexlit1 127 0x8000000 134217728 hexlit1 128 0x10000000 268435456 hexlit1 129 0x20000000 536870912 hexlit1 130 0x40000000 1073741824 hexlit1 131 0x80000000 2147483648 hexlit1 132 0x100000000 4294967296 hexlit1 133 0x200000000 8589934592 hexlit1 134 0x400000000 17179869184 hexlit1 135 0x800000000 34359738368 hexlit1 136 0x1000000000 68719476736 hexlit1 137 0x2000000000 137438953472 hexlit1 138 0x4000000000 274877906944 hexlit1 139 0x8000000000 549755813888 hexlit1 140 0x10000000000 1099511627776 hexlit1 141 0x20000000000 2199023255552 hexlit1 142 0x40000000000 4398046511104 hexlit1 143 0x80000000000 8796093022208 hexlit1 144 0x100000000000 17592186044416 hexlit1 145 0x200000000000 35184372088832 hexlit1 146 0x400000000000 70368744177664 hexlit1 147 0x800000000000 140737488355328 hexlit1 148 0x1000000000000 281474976710656 hexlit1 149 0x2000000000000 562949953421312 hexlit1 150 0x4000000000000 1125899906842624 hexlit1 151 0x8000000000000 2251799813685248 hexlit1 152 0x10000000000000 4503599627370496 hexlit1 153 0x20000000000000 9007199254740992 hexlit1 154 0x40000000000000 18014398509481984 hexlit1 155 0x80000000000000 36028797018963968 hexlit1 156 0x100000000000000 72057594037927936 hexlit1 157 0x200000000000000 144115188075855872 hexlit1 158 0x400000000000000 288230376151711744 hexlit1 159 0x800000000000000 576460752303423488 hexlit1 160 0X1000000000000000 1152921504606846976 hexlit1 161 0x2000000000000000 2305843009213693952 hexlit1 162 0X4000000000000000 4611686018427387904 hexlit1 163 0x8000000000000000 -9223372036854775808 hexlit1 164 0XFFFFFFFFFFFFFFFF -1 for {set n 1} {$n < 0x10} {incr n} { hexlit1 200.$n.1 0X[format %03X $n] $n hexlit1 200.$n.2 0x[format %03X $n] $n hexlit1 200.$n.3 0X[format %03x $n] $n hexlit1 200.$n.4 0x[format %03x $n] $n } # String literals that look like hex do not get cast or coerced. # do_execsql_test hexlit-300 { CREATE TABLE t1(x INT, y REAL); INSERT INTO t1 VALUES('1234','4567'),('0x1234','0x4567'); SELECT typeof(x), x, typeof(y), y, '#' FROM t1 ORDER BY rowid; } {integer 1234 real 4567.0 # text 0x1234 text 0x4567 #} do_execsql_test hexlit-301 { SELECT CAST('0x1234' AS INTEGER); } {0} # Oversized hex literals are rejected # do_catchsql_test hexlist-400 { SELECT 0x10000000000000000; } {1 {hex literal too big: 0x10000000000000000}} finish_test |