diff options
author | Wez Furlong <wez@php.net> | 2003-06-04 22:40:00 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2003-06-04 22:40:00 +0000 |
commit | 80e7f7001d39add9010ba78be636245410b79c24 (patch) | |
tree | 23ae7f9f01ea9bb1add35b1ff85efa2421d05142 /ext/sqlite/libsqlite/src/util.c | |
parent | 82a1818fdec3afe8e3a5cc8aa7171f4472ea1e4a (diff) | |
download | php-git-80e7f7001d39add9010ba78be636245410b79c24.tar.gz |
Update bundled library to version 2.8.2.
Make OnUpdateInt compatible with ZE2.
Fix the makefile fragment for non-gnu makes
Diffstat (limited to 'ext/sqlite/libsqlite/src/util.c')
-rw-r--r-- | ext/sqlite/libsqlite/src/util.c | 155 |
1 files changed, 140 insertions, 15 deletions
diff --git a/ext/sqlite/libsqlite/src/util.c b/ext/sqlite/libsqlite/src/util.c index 292df5d977..8520704ea6 100644 --- a/ext/sqlite/libsqlite/src/util.c +++ b/ext/sqlite/libsqlite/src/util.c @@ -393,6 +393,134 @@ void sqliteSetNString(char **pz, ...){ } /* +** Add an error message to pParse->zErrMsg and increment pParse->nErr. +** The following formatting characters are allowed: +** +** %s Insert a string +** %z A string that should be freed after use +** %d Insert an integer +** %T Insert a token +** %S Insert the first element of a SrcList +*/ +void sqliteErrorMsg(Parse *pParse, const char *zFormat, ...){ + va_list ap; + int nByte; + int i, j; + char *z; + static char zNull[] = "NULL"; + + pParse->nErr++; + nByte = 1 + strlen(zFormat); + va_start(ap, zFormat); + for(i=0; zFormat[i]; i++){ + if( zFormat[i]!='%' || zFormat[i+1]==0 ) continue; + i++; + switch( zFormat[i] ){ + case 'd': { + (void)va_arg(ap, int); + nByte += 20; + break; + } + case 'z': + case 's': { + char *z2 = va_arg(ap, char*); + if( z2==0 ) z2 = zNull; + nByte += strlen(z2); + break; + } + case 'T': { + Token *p = va_arg(ap, Token*); + nByte += p->n; + break; + } + case 'S': { + SrcList *p = va_arg(ap, SrcList*); + int k = va_arg(ap, int); + assert( p->nSrc>k && k>=0 ); + nByte += strlen(p->a[k].zName); + if( p->a[k].zDatabase && p->a[k].zDatabase[0] ){ + nByte += strlen(p->a[k].zDatabase)+1; + } + break; + } + default: { + nByte++; + break; + } + } + } + va_end(ap); + z = sqliteMalloc( nByte ); + if( z==0 ) return; + sqliteFree(pParse->zErrMsg); + pParse->zErrMsg = z; + va_start(ap, zFormat); + for(i=j=0; zFormat[i]; i++){ + if( zFormat[i]!='%' || zFormat[i+1]==0 ) continue; + if( i>j ){ + memcpy(z, &zFormat[j], i-j); + z += i-j; + } + j = i+2; + i++; + switch( zFormat[i] ){ + case 'd': { + int x = va_arg(ap, int); + sprintf(z, "%d", x); + z += strlen(z); + break; + } + case 'z': + case 's': { + int len; + char *z2 = va_arg(ap, char*); + if( z2==0 ) z2 = zNull; + len = strlen(z2); + memcpy(z, z2, len); + z += len; + if( zFormat[i]=='z' && z2!=zNull ){ + sqliteFree(z2); + } + break; + } + case 'T': { + Token *p = va_arg(ap, Token*); + memcpy(z, p->z, p->n); + z += p->n; + break; + } + case 'S': { + int len; + SrcList *p = va_arg(ap, SrcList*); + int k = va_arg(ap, int); + assert( p->nSrc>k && k>=0 ); + if( p->a[k].zDatabase && p->a[k].zDatabase[0] ){ + len = strlen(p->a[k].zDatabase); + memcpy(z, p->a[k].zDatabase, len); + z += len; + *(z++) = '.'; + } + len = strlen(p->a[k].zName); + memcpy(z, p->a[k].zName, len); + z += len; + break; + } + default: { + *(z++) = zFormat[i]; + break; + } + } + } + va_end(ap); + if( i>j ){ + memcpy(z, &zFormat[j], i-j); + z += i-j; + } + assert( (z - pParse->zErrMsg) < nByte ); + *z = 0; +} + +/* ** Convert an SQL-style quoted string into a normal string by removing ** the quote characters. The conversion is done in-place. If the ** input does not begin with a quote character, then this routine @@ -460,8 +588,7 @@ int sqliteHashNoCase(const char *z, int n){ h = (h<<3) ^ h ^ UpperToLower[(unsigned char)*z++]; n--; } - if( h<0 ) h = -h; - return h; + return h & 0x7fffffff; } /* @@ -669,12 +796,12 @@ static int sortStrCmp(const char *atext, const char *btext, int useCase){ ** Return TRUE if z is a pure numeric string. Return FALSE if the ** string contains any character which is not part of a number. ** -** Am empty string is considered numeric. +** Am empty string is considered non-numeric. */ -static int sqliteIsNumber(const char *z){ +int sqliteIsNumber(const char *z){ if( *z=='-' || *z=='+' ) z++; if( !isdigit(*z) ){ - return *z==0; + return 0; } z++; while( isdigit(*z) ){ z++; } @@ -682,12 +809,12 @@ static int sqliteIsNumber(const char *z){ z++; if( !isdigit(*z) ) return 0; while( isdigit(*z) ){ z++; } - if( *z=='e' || *z=='E' ){ - z++; - if( *z=='+' || *z=='-' ) z++; - if( !isdigit(*z) ) return 0; - while( isdigit(*z) ){ z++; } - } + } + if( *z=='e' || *z=='E' ){ + z++; + if( *z=='+' || *z=='-' ) z++; + if( !isdigit(*z) ) return 0; + while( isdigit(*z) ){ z++; } } return *z==0; } @@ -780,7 +907,6 @@ int sqliteCompare(const char *atext, const char *btext){ ** 2.6.3 and earlier. */ int sqliteSortCompare(const char *a, const char *b){ - int len; int res = 0; int isNumA, isNumB; int dir = 0; @@ -832,9 +958,8 @@ int sqliteSortCompare(const char *a, const char *b){ if( res ) break; } } - len = strlen(&a[1]) + 2; - a += len; - b += len; + a += strlen(&a[1]) + 2; + b += strlen(&b[1]) + 2; } if( dir=='-' || dir=='D' ) res = -res; return res; |