?? util.c
字號(hào):
break; }else{ res = strcmp(&a[1],&b[1]); if( res ) break; } } a += strlen(&a[1]) + 2; b += strlen(&b[1]) + 2; } if( dir=='-' || dir=='D' ) res = -res; return res;}/*** Some powers of 64. These constants are needed in the** sqliteRealToSortable() routine below.*/#define _64e3 (64.0 * 64.0 * 64.0)#define _64e4 (64.0 * 64.0 * 64.0 * 64.0)#define _64e15 (_64e3 * _64e4 * _64e4 * _64e4)#define _64e16 (_64e4 * _64e4 * _64e4 * _64e4)#define _64e63 (_64e15 * _64e16 * _64e16 * _64e16)#define _64e64 (_64e16 * _64e16 * _64e16 * _64e16)/*** The following procedure converts a double-precision floating point** number into a string. The resulting string has the property that** two such strings comparied using strcmp() or memcmp() will give the** same results as a numeric comparison of the original floating point** numbers.**** This routine is used to generate database keys from floating point** numbers such that the keys sort in the same order as the original** floating point numbers even though the keys are compared using** memcmp().**** The calling function should have allocated at least 14 characters** of space for the buffer z[].*/void sqliteRealToSortable(double r, char *z){ int neg; int exp; int cnt = 0; /* This array maps integers between 0 and 63 into base-64 digits. ** The digits must be chosen such at their ASCII codes are increasing. ** This means we can not use the traditional base-64 digit set. */ static const char zDigit[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "|~"; if( r<0.0 ){ neg = 1; r = -r; *z++ = '-'; } else { neg = 0; *z++ = '0'; } exp = 0; if( r==0.0 ){ exp = -1024; }else if( r<(0.5/64.0) ){ while( r < 0.5/_64e64 && exp > -961 ){ r *= _64e64; exp -= 64; } while( r < 0.5/_64e16 && exp > -1009 ){ r *= _64e16; exp -= 16; } while( r < 0.5/_64e4 && exp > -1021 ){ r *= _64e4; exp -= 4; } while( r < 0.5/64.0 && exp > -1024 ){ r *= 64.0; exp -= 1; } }else if( r>=0.5 ){ while( r >= 0.5*_64e63 && exp < 960 ){ r *= 1.0/_64e64; exp += 64; } while( r >= 0.5*_64e15 && exp < 1008 ){ r *= 1.0/_64e16; exp += 16; } while( r >= 0.5*_64e3 && exp < 1020 ){ r *= 1.0/_64e4; exp += 4; } while( r >= 0.5 && exp < 1023 ){ r *= 1.0/64.0; exp += 1; } } if( neg ){ exp = -exp; r = -r; } exp += 1024; r += 0.5; if( exp<0 ) return; if( exp>=2048 || r>=1.0 ){ strcpy(z, "~~~~~~~~~~~~"); return; } *z++ = zDigit[(exp>>6)&0x3f]; *z++ = zDigit[exp & 0x3f]; while( r>0.0 && cnt<10 ){ int digit; r *= 64.0; digit = (int)r; assert( digit>=0 && digit<64 ); *z++ = zDigit[digit & 0x3f]; r -= digit; cnt++; } *z = 0;}#ifdef SQLITE_UTF8/*** X is a pointer to the first byte of a UTF-8 character. Increment** X so that it points to the next character. This only works right** if X points to a well-formed UTF-8 string.*/#define sqliteNextChar(X) while( (0xc0&*++(X))==0x80 ){}#define sqliteCharVal(X) sqlite_utf8_to_int(X)#else /* !defined(SQLITE_UTF8) *//*** For iso8859 encoding, the next character is just the next byte.*/#define sqliteNextChar(X) (++(X));#define sqliteCharVal(X) ((int)*(X))#endif /* defined(SQLITE_UTF8) */#ifdef SQLITE_UTF8/*** Convert the UTF-8 character to which z points into a 31-bit** UCS character. This only works right if z points to a well-formed** UTF-8 string.*/static int sqlite_utf8_to_int(const unsigned char *z){ int c; static const int initVal[] = { 0, 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, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 0, 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, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 0, 1, 254, 255, }; c = initVal[*(z++)]; while( (0xc0&*z)==0x80 ){ c = (c<<6) | (0x3f&*(z++)); } return c;}#endif/*** Compare two UTF-8 strings for equality where the first string can** potentially be a "glob" expression. Return true (1) if they** are the same and false (0) if they are different.**** Globbing rules:**** '*' Matches any sequence of zero or more characters.**** '?' Matches exactly one character.**** [...] Matches one character from the enclosed list of** characters.**** [^...] Matches one character not in the enclosed list.**** With the [...] and [^...] matching, a ']' character can be included** in the list by making it the first character after '[' or '^'. A** range of characters can be specified using '-'. Example:** "[a-z]" matches any single lower-case letter. To match a '-', make** it the last character in the list.**** This routine is usually quick, but can be N**2 in the worst case.**** Hints: to match '*' or '?', put them in "[]". Like this:**** abc[*]xyz Matches "abc*xyz" only*/int sqliteGlobCompare(const unsigned char *zPattern, const unsigned char *zString){ register int c; int invert; int seen; int c2; while( (c = *zPattern)!=0 ){ switch( c ){ case '*': while( (c=zPattern[1]) == '*' || c == '?' ){ if( c=='?' ){ if( *zString==0 ) return 0; sqliteNextChar(zString); } zPattern++; } if( c==0 ) return 1; if( c=='[' ){ while( *zString && sqliteGlobCompare(&zPattern[1],zString)==0 ){ sqliteNextChar(zString); } return *zString!=0; }else{ while( (c2 = *zString)!=0 ){ while( c2 != 0 && c2 != c ){ c2 = *++zString; } if( c2==0 ) return 0; if( sqliteGlobCompare(&zPattern[1],zString) ) return 1; sqliteNextChar(zString); } return 0; } case '?': { if( *zString==0 ) return 0; sqliteNextChar(zString); zPattern++; break; } case '[': { int prior_c = 0; seen = 0; invert = 0; c = sqliteCharVal(zString); if( c==0 ) return 0; c2 = *++zPattern; if( c2=='^' ){ invert = 1; c2 = *++zPattern; } if( c2==']' ){ if( c==']' ) seen = 1; c2 = *++zPattern; } while( (c2 = sqliteCharVal(zPattern))!=0 && c2!=']' ){ if( c2=='-' && zPattern[1]!=']' && zPattern[1]!=0 && prior_c>0 ){ zPattern++; c2 = sqliteCharVal(zPattern); if( c>=prior_c && c<=c2 ) seen = 1; prior_c = 0; }else if( c==c2 ){ seen = 1; prior_c = c2; }else{ prior_c = c2; } sqliteNextChar(zPattern); } if( c2==0 || (seen ^ invert)==0 ) return 0; sqliteNextChar(zString); zPattern++; break; } default: { if( c != *zString ) return 0; zPattern++; zString++; break; } } } return *zString==0;}/*** Compare two UTF-8 strings for equality using the "LIKE" operator of** SQL. The '%' character matches any sequence of 0 or more** characters and '_' matches any single character. Case is** not significant.**** This routine is just an adaptation of the sqliteGlobCompare()** routine above.*/int sqliteLikeCompare(const unsigned char *zPattern, const unsigned char *zString){ register int c; int c2; while( (c = UpperToLower[*zPattern])!=0 ){ switch( c ){ case '%': { while( (c=zPattern[1]) == '%' || c == '_' ){ if( c=='_' ){ if( *zString==0 ) return 0; sqliteNextChar(zString); } zPattern++; } if( c==0 ) return 1; c = UpperToLower[c]; while( (c2=UpperToLower[*zString])!=0 ){ while( c2 != 0 && c2 != c ){ c2 = UpperToLower[*++zString]; } if( c2==0 ) return 0; if( sqliteLikeCompare(&zPattern[1],zString) ) return 1; sqliteNextChar(zString); } return 0; } case '_': { if( *zString==0 ) return 0; sqliteNextChar(zString); zPattern++; break; } default: { if( c != UpperToLower[*zString] ) return 0; zPattern++; zString++; break; } } } return *zString==0;}/*** Change the sqlite.magic from SQLITE_MAGIC_OPEN to SQLITE_MAGIC_BUSY.** Return an error (non-zero) if the magic was not SQLITE_MAGIC_OPEN** when this routine is called.**** This routine is a attempt to detect if two threads use the** same sqlite* pointer at the same time. There is a race ** condition so it is possible that the error is not detected.** But usually the problem will be seen. The result will be an** error which can be used to debug the application that is** using SQLite incorrectly.**** Ticket #202: If db->magic is not a valid open value, take care not** to modify the db structure at all. It could be that db is a stale** pointer. In other words, it could be that there has been a prior** call to sqlite_close(db) and db has been deallocated. And we do** not want to write into deallocated memory.*/int sqliteSafetyOn(sqlite *db){ if( db->magic==SQLITE_MAGIC_OPEN ){ db->magic = SQLITE_MAGIC_BUSY; return 0; }else if( db->magic==SQLITE_MAGIC_BUSY || db->magic==SQLITE_MAGIC_ERROR || db->want_to_close ){ db->magic = SQLITE_MAGIC_ERROR; db->flags |= SQLITE_Interrupt; } return 1;}/*** Change the magic from SQLITE_MAGIC_BUSY to SQLITE_MAGIC_OPEN.** Return an error (non-zero) if the magic was not SQLITE_MAGIC_BUSY** when this routine is called.*/int sqliteSafetyOff(sqlite *db){ if( db->magic==SQLITE_MAGIC_BUSY ){ db->magic = SQLITE_MAGIC_OPEN; return 0; }else if( db->magic==SQLITE_MAGIC_OPEN || db->magic==SQLITE_MAGIC_ERROR || db->want_to_close ){ db->magic = SQLITE_MAGIC_ERROR; db->flags |= SQLITE_Interrupt; } return 1;}/*** Check to make sure we are not currently executing an sqlite_exec().** If we are currently in an sqlite_exec(), return true and set** sqlite.magic to SQLITE_MAGIC_ERROR. This will cause a complete** shutdown of the database.**** This routine is used to try to detect when API routines are called** at the wrong time or in the wrong sequence.*/int sqliteSafetyCheck(sqlite *db){ if( db->pVdbe!=0 ){ db->magic = SQLITE_MAGIC_ERROR; return 1; } return 0;}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -