/ Check-in [af542c82]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the char() function so that it works even if SQLITE_OMIT_UTF16 is defined.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: af542c82e8e7f0415530b639fa397429c5f377f6
User & Date: drh 2013-03-07 14:00:04
Context
2013-03-08
18:16
If SQLITE_OMIT_UTF16 is defined, avoid setting the 'enc' field of Schema objects to any value except SQLITE_UTF8. Otherwise, assert() statements may fail or spurious SQLITE_NOMEM errors may be returned at the vdbe level later on. check-in: f2fecfb2 user: dan tags: trunk
2013-03-07
14:00
Fix the char() function so that it works even if SQLITE_OMIT_UTF16 is defined. check-in: af542c82 user: drh tags: trunk
09:39
Skip tests that require UTF-16 support when compiled with SQLITE_OMIT_UTF16. check-in: e3939142 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/func.c.

   977    977   }
   978    978   
   979    979   /*
   980    980   ** The char() function takes zero or more arguments, each of which is
   981    981   ** an integer.  It constructs a string where each character of the string
   982    982   ** is the unicode character for the corresponding integer argument.
   983    983   */
   984         -#ifndef SQLITE_OMIT_UTF16
   985    984   static void charFunc(
   986    985     sqlite3_context *context,
   987    986     int argc,
   988    987     sqlite3_value **argv
   989    988   ){
   990    989     unsigned char *z, *zOut;
   991    990     int i;
................................................................................
   996    995     }
   997    996     for(i=0; i<argc; i++){
   998    997       sqlite3_int64 x;
   999    998       unsigned c;
  1000    999       x = sqlite3_value_int64(argv[i]);
  1001   1000       if( x<0 || x>0x10ffff ) x = 0xfffd;
  1002   1001       c = (unsigned)(x & 0x1fffff);
  1003         -    if( c<=0xFFFF ){
  1004         -      if( c>=0xd800 && c<=0xdfff ) c = 0xfffd;
  1005         -      *zOut++ = (u8)(c&0x00FF);
  1006         -      *zOut++ = (u8)((c>>8)&0x00FF);
         1002  +    if( c<0x00080 ){
         1003  +      *zOut++ = (u8)(c&0xFF);
         1004  +    }else if( c<0x00800 ){
         1005  +      *zOut++ = 0xC0 + (u8)((c>>6)&0x1F);
         1006  +      *zOut++ = 0x80 + (u8)(c & 0x3F);
         1007  +    }else if( c<0x10000 ){
         1008  +      *zOut++ = 0xE0 + (u8)((c>>12)&0x0F);
         1009  +      *zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
         1010  +      *zOut++ = 0x80 + (u8)(c & 0x3F);
  1007   1011       }else{
  1008         -      *zOut++ = (u8)(((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0));
  1009         -      *zOut++ = (u8)(0x00D8 + (((c-0x10000)>>18)&0x03));
  1010         -      *zOut++ = (u8)(c&0x00FF);
  1011         -      *zOut++ = (u8)(0x00DC + ((c>>8)&0x03));
  1012         -    }
         1012  +      *zOut++ = 0xF0 + (u8)((c>>18) & 0x07);
         1013  +      *zOut++ = 0x80 + (u8)((c>>12) & 0x3F);
         1014  +      *zOut++ = 0x80 + (u8)((c>>6) & 0x3F);
         1015  +      *zOut++ = 0x80 + (u8)(c & 0x3F);
         1016  +    }                                                    \
  1013   1017     }
  1014         -  sqlite3_result_text16le(context, (char*)z, (int)(zOut-z), sqlite3_free);
         1018  +  sqlite3_result_text(context, (char*)z, (int)(zOut-z), sqlite3_free);
  1015   1019   }
  1016         -#endif
  1017   1020   
  1018   1021   /*
  1019   1022   ** The hex() function.  Interpret the argument as a blob.  Return
  1020   1023   ** a hexadecimal rendering as text.
  1021   1024   */
  1022   1025   static void hexFunc(
  1023   1026     sqlite3_context *context,
................................................................................
  1639   1642       AGGREGATE(max,               1, 1, 1, minmaxStep,      minMaxFinalize ),
  1640   1643       FUNCTION2(typeof,            1, 0, 0, typeofFunc,  SQLITE_FUNC_TYPEOF),
  1641   1644       FUNCTION2(length,            1, 0, 0, lengthFunc,  SQLITE_FUNC_LENGTH),
  1642   1645       FUNCTION(instr,              2, 0, 0, instrFunc        ),
  1643   1646       FUNCTION(substr,             2, 0, 0, substrFunc       ),
  1644   1647       FUNCTION(substr,             3, 0, 0, substrFunc       ),
  1645   1648       FUNCTION(unicode,            1, 0, 0, unicodeFunc      ),
  1646         -#ifndef SQLITE_OMIT_UTF16
  1647   1649       FUNCTION(char,              -1, 0, 0, charFunc         ),
  1648         -#endif
  1649   1650       FUNCTION(abs,                1, 0, 0, absFunc          ),
  1650   1651   #ifndef SQLITE_OMIT_FLOATING_POINT
  1651   1652       FUNCTION(round,              1, 0, 0, roundFunc        ),
  1652   1653       FUNCTION(round,              2, 0, 0, roundFunc        ),
  1653   1654   #endif
  1654   1655       FUNCTION(upper,              1, 0, 0, upperFunc        ),
  1655   1656       FUNCTION(lower,              1, 0, 0, lowerFunc        ),

Changes to test/func.test.

  1289   1289     if {$x<5} {set x 1}
  1290   1290     set x
  1291   1291   } {1}
  1292   1292   
  1293   1293   do_execsql_test func-30.1 {SELECT unicode('$');} 36
  1294   1294   do_execsql_test func-30.2 [subst {SELECT unicode('\u00A2');}] 162
  1295   1295   do_execsql_test func-30.3 [subst {SELECT unicode('\u20AC');}] 8364
  1296         -
  1297         -ifcapable !utf16 {
  1298         -  finish_test
  1299         -  return
  1300         -}
  1301         -
  1302   1296   do_execsql_test func-30.4 {SELECT char(36,162,8364);} [subst {$\u00A2\u20AC}]
  1303   1297   
  1304   1298   for {set i 1} {$i<0xd800} {incr i 13} {
  1305   1299     do_execsql_test func-30.5.$i {SELECT unicode(char($i))} $i
  1306   1300   }
  1307   1301   for {set i 57344} {$i<=0xfffd} {incr i 17} {
  1308   1302     if {$i==0xfeff} continue