Two new SQL functions: unicode() and char().

FossilOrigin-Name: 209b21085b9767f10f6ffb7c7cac756fcb74ded5
This commit is contained in:
drh 2013-02-22 19:34:25 +00:00
parent d5d0f6432c
commit d495d8c9a3
4 changed files with 68 additions and 9 deletions

View File

@ -1,5 +1,5 @@
C On\sMinix,\sdisable\sthe\s".timer"\scommand\sin\sthe\sshell\sin\sorder\sto\savoid\ncalling\sgetrusage(). C Two\snew\sSQL\sfunctions:\sunicode()\sand\schar().
D 2013-02-20T00:54:21.855 D 2013-02-22T19:34:25.685
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in a48faa9e7dd7d556d84f5456eabe5825dd8a6282 F Makefile.in a48faa9e7dd7d556d84f5456eabe5825dd8a6282
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -133,7 +133,7 @@ F src/delete.c 9b8d308979114991e5dc7cee958316e07186941d
F src/expr.c f6c20285bd36e87ec47f4d840e90a32755e2a90c F src/expr.c f6c20285bd36e87ec47f4d840e90a32755e2a90c
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c e16942bd5c8a868ac53287886464a5ed0e72b179 F src/fkey.c e16942bd5c8a868ac53287886464a5ed0e72b179
F src/func.c 8147799b048065a1590805be464d05b4913e652c F src/func.c 18b120b9a34daf6d38d50969b6f3471c09b2934a
F src/global.c e59ecd2c553ad0d4bfbc84ca71231336f8993a7a F src/global.c e59ecd2c553ad0d4bfbc84ca71231336f8993a7a
F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4 F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4
F src/hash.h 2894c932d84d9f892d4b4023a75e501f83050970 F src/hash.h 2894c932d84d9f892d4b4023a75e501f83050970
@ -508,7 +508,7 @@ F test/fts4merge2.test 5faa558d1b672f82b847d2a337465fa745e46891
F test/fts4merge3.test aab02a09f50fe6baaddc2e159c3eabc116d45fc7 F test/fts4merge3.test aab02a09f50fe6baaddc2e159c3eabc116d45fc7
F test/fts4unicode.test 25ccad45896f8e50f6a694cff738a35f798cdb40 F test/fts4unicode.test 25ccad45896f8e50f6a694cff738a35f798cdb40
F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d
F test/func.test 0d89043dab9a8853358d14c68e028ee0093bf066 F test/func.test 0ea54895539c0586e86e2dcea59b05cc9e7dd6b2
F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
F test/func3.test 001021e5b88bd02a3b365a5c5fd8f6f49d39744a F test/func3.test 001021e5b88bd02a3b365a5c5fd8f6f49d39744a
F test/fuzz-oss1.test 4912e528ec9cf2f42134456933659d371c9e0d74 F test/fuzz-oss1.test 4912e528ec9cf2f42134456933659d371c9e0d74
@ -1034,7 +1034,10 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
P 06bd91305ed6752315c5224be5f89e87cafa6687 P 9bd9bd9cab8c804c1a51d472199459176044a633
R 14c0fedf89f00b14b7845aeac312ffca R 57460c96631f0b503379401f124964ab
T *branch * unicode-function
T *sym-unicode-function *
T -sym-trunk *
U drh U drh
Z 673b617e6189db9a51be1e6b0160e6d4 Z ff410097880c23c389e99514cc7f5a15

View File

@ -1 +1 @@
9bd9bd9cab8c804c1a51d472199459176044a633 209b21085b9767f10f6ffb7c7cac756fcb74ded5

View File

@ -962,6 +962,56 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
} }
} }
/*
** The unicode() function. Return the integer unicode code-point value
** for the first character of the input string.
*/
static void unicodeFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
const unsigned char *z = sqlite3_value_text(argv[0]);
if( z && z[0] ) sqlite3_result_int(context, sqlite3Utf8Read(&z));
}
/*
** The char() function takes zero or more arguments, each of which is
** an integer. It constructs a string where each character of the string
** is the unicode character for the corresponding integer argument.
*/
static void charFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
unsigned char *z, *zOut;
int i;
zOut = z = sqlite3_malloc( argc*4 );
if( z==0 ){
sqlite3_result_error_nomem(context);
return;
}
for(i=0; i<argc; i++){
sqlite3_int64 x = sqlite3_value_int64(argv[i]);
unsigned c;
x = sqlite3_value_int64(argv[i]);
if( x<0 || x>0x10ffff ) x = 0xfffd;
c = (unsigned)(x & 0x1fffff);
if( c<=0xFFFF ){
*zOut++ = (u8)(c&0x00FF);
*zOut++ = (u8)((c>>8)&0x00FF);
}else{
if( c>=0xd800 && c<=0xdbff ) c = 0xfffd;
*zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0));
*zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03));
*zOut++ = (u8)(c&0x00FF);
*zOut++ = (u8)(0x00DC + ((c>>8)&0x03));
}
}
sqlite3_result_text16le(context, (char*)z, (int)(zOut-z), sqlite3_free);
}
/* /*
** The hex() function. Interpret the argument as a blob. Return ** The hex() function. Interpret the argument as a blob. Return
** a hexadecimal rendering as text. ** a hexadecimal rendering as text.
@ -1589,6 +1639,8 @@ void sqlite3RegisterGlobalFunctions(void){
FUNCTION(instr, 2, 0, 0, instrFunc ), FUNCTION(instr, 2, 0, 0, instrFunc ),
FUNCTION(substr, 2, 0, 0, substrFunc ), FUNCTION(substr, 2, 0, 0, substrFunc ),
FUNCTION(substr, 3, 0, 0, substrFunc ), FUNCTION(substr, 3, 0, 0, substrFunc ),
FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
FUNCTION(char, -1, 0, 0, charFunc ),
FUNCTION(abs, 1, 0, 0, absFunc ), FUNCTION(abs, 1, 0, 0, absFunc ),
#ifndef SQLITE_OMIT_FLOATING_POINT #ifndef SQLITE_OMIT_FLOATING_POINT
FUNCTION(round, 1, 0, 0, roundFunc ), FUNCTION(round, 1, 0, 0, roundFunc ),

View File

@ -1290,5 +1290,9 @@ do_test func-29.6 {
set x set x
} {1} } {1}
do_execsql_test func-30.1 {SELECT unicode('$');} 36
do_execsql_test func-30.2 {SELECT unicode('¢');} 162
do_execsql_test func-30.3 {SELECT unicode('€');} 8364
do_execsql_test func-30.4 {SELECT char(36,162,8364);} {$¢€}
finish_test finish_test