diff options
author | drh <drh@noemail.net> | 2003-03-27 12:51:24 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2003-03-27 12:51:24 +0000 |
commit | d24cc427b7f83ca65aefbb6cf1831d0461f16357 (patch) | |
tree | e8c0700ba474499cd46b5f6cc49c3bd1a4b607c0 /src/func.c | |
parent | 84e6335c0c244dfde752ee4e166b6770dd9d2e10 (diff) | |
download | sqlite-d24cc427b7f83ca65aefbb6cf1831d0461f16357.tar.gz sqlite-d24cc427b7f83ca65aefbb6cf1831d0461f16357.zip |
Changes to the "sqlite" structure that allow simultaneous operations on
multiple database files. Many regession tests pass - but not all of them.
Do not use this version except for debugging SQLite itself. (CVS 883)
FossilOrigin-Name: d2fb2bb50cf1e13feb90995079f291384abd6ba9
Diffstat (limited to 'src/func.c')
-rw-r--r-- | src/func.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/func.c b/src/func.c index 5892b1888..98de567b2 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.23 2002/11/04 19:32:25 drh Exp $ +** $Id: func.c,v 1.24 2003/03/27 12:51:25 drh Exp $ */ #include <ctype.h> #include <math.h> @@ -255,6 +255,46 @@ static void versionFunc(sqlite_func *context, int argc, const char **argv){ sqlite_set_result_string(context, sqlite_version, -1); } +#ifdef SQLITE_SOUNDEX +/* +** Compute the soundex encoding of a word. +*/ +static void soundexFunc(sqlite_func *context, int argc, const char **argv){ + char zResult[8]; + const char *zIn; + int i, j; + static const unsigned char iCode[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0, + 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0, + 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0, + 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0, + }; + assert( argc==1 ); + zIn = argv[0]; + for(i=0; zIn[i] && !isalpha(zIn[i]); i++){} + if( zIn[i] ){ + zResult[0] = toupper(zIn[i]); + for(j=1; j<4 && zIn[i]; i++){ + int code = iCode[zIn[i]&0x7f]; + if( code>0 ){ + zResult[j++] = code + '0'; + } + } + while( j<4 ){ + zResult[j++] = '0'; + } + zResult[j] = 0; + sqlite_set_result_string(context, zResult, 4); + }else{ + sqlite_set_result_string(context, zResult, "?000", 4); + } +} +#endif + #ifdef SQLITE_TEST /* ** This function generates a string of random characters. Used for @@ -490,6 +530,9 @@ void sqliteRegisterBuiltinFunctions(sqlite *db){ { "glob", 2, SQLITE_NUMERIC, globFunc }, { "nullif", 2, SQLITE_ARGS, nullifFunc }, { "sqlite_version",0,SQLITE_TEXT, versionFunc}, +#ifdef SQLITE_SOUNDEX + { "soundex", 1, SQLITE_TEXT, soundexFunc}, +#endif #ifdef SQLITE_TEST { "randstr", 2, SQLITE_TEXT, randStr }, #endif |