/ Check-in [9984cc20]
Login

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

Overview
Comment:Simplifications to the upper() and lower() SQL functions. Updates to documentation on sqlite3_bind_text() and sqlite3_result_text() to make it clear that users should not try to create strings with embedded NULs and that if they do the result of expression on those strings is undefined. Ticket [57c971fc74524a]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9984cc20ca70b7fb39c0b99580a1317a7b0c9c85
User & Date: drh 2011-10-13 18:00:11
Context
2011-10-13
18:08
Change the makefile to delete both plain and ".exe" variants of build tools. Ticket [92bd6eaf04e117] check-in: 19536a38 user: drh tags: trunk
18:00
Simplifications to the upper() and lower() SQL functions. Updates to documentation on sqlite3_bind_text() and sqlite3_result_text() to make it clear that users should not try to create strings with embedded NULs and that if they do the result of expression on those strings is undefined. Ticket [57c971fc74524a] check-in: 9984cc20 user: drh tags: trunk
17:16
Handle updating the only row of an FTS table correctly. Fix for [9fd058691]. check-in: 7e24645b user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/func.c.

   328    328     z2 = (char*)sqlite3_value_text(argv[0]);
   329    329     n = sqlite3_value_bytes(argv[0]);
   330    330     /* Verify that the call to _bytes() does not invalidate the _text() pointer */
   331    331     assert( z2==(char*)sqlite3_value_text(argv[0]) );
   332    332     if( z2 ){
   333    333       z1 = contextMalloc(context, ((i64)n)+1);
   334    334       if( z1 ){
   335         -      memcpy(z1, z2, n+1);
   336         -      for(i=0; z1[i]; i++){
   337         -        z1[i] = (char)sqlite3Toupper(z1[i]);
          335  +      for(i=0; i<n; i++){
          336  +        z1[i] = (char)sqlite3Toupper(z2[i]);
   338    337         }
   339         -      sqlite3_result_text(context, z1, -1, sqlite3_free);
          338  +      sqlite3_result_text(context, z1, n, sqlite3_free);
   340    339       }
   341    340     }
   342    341   }
   343    342   static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
   344         -  u8 *z1;
          343  +  char *z1;
   345    344     const char *z2;
   346    345     int i, n;
   347    346     UNUSED_PARAMETER(argc);
   348    347     z2 = (char*)sqlite3_value_text(argv[0]);
   349    348     n = sqlite3_value_bytes(argv[0]);
   350    349     /* Verify that the call to _bytes() does not invalidate the _text() pointer */
   351    350     assert( z2==(char*)sqlite3_value_text(argv[0]) );
   352    351     if( z2 ){
   353    352       z1 = contextMalloc(context, ((i64)n)+1);
   354    353       if( z1 ){
   355         -      memcpy(z1, z2, n+1);
   356         -      for(i=0; z1[i]; i++){
   357         -        z1[i] = sqlite3Tolower(z1[i]);
          354  +      for(i=0; i<n; i++){
          355  +        z1[i] = sqlite3Tolower(z2[i]);
   358    356         }
   359         -      sqlite3_result_text(context, (char *)z1, -1, sqlite3_free);
          357  +      sqlite3_result_text(context, z1, n, sqlite3_free);
   360    358       }
   361    359     }
   362    360   }
   363    361   
   364    362   
   365    363   #if 0  /* This function is never used. */
   366    364   /*

Changes to src/sqlite.h.in.

  2795   2795   ** first zero terminator. ^If nByte is non-negative, then it is the maximum
  2796   2796   ** number of  bytes read from zSql.  ^When nByte is non-negative, the
  2797   2797   ** zSql string ends at either the first '\000' or '\u0000' character or
  2798   2798   ** the nByte-th byte, whichever comes first. If the caller knows
  2799   2799   ** that the supplied string is nul-terminated, then there is a small
  2800   2800   ** performance advantage to be gained by passing an nByte parameter that
  2801   2801   ** is equal to the number of bytes in the input string <i>including</i>
  2802         -** the nul-terminator bytes.
         2802  +** the nul-terminator bytes as this saves SQLite from having to
         2803  +** make a copy of the input string.
  2803   2804   **
  2804   2805   ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
  2805   2806   ** past the end of the first SQL statement in zSql.  These routines only
  2806   2807   ** compile the first statement in zSql, so *pzTail is left pointing to
  2807   2808   ** what remains uncompiled.
  2808   2809   **
  2809   2810   ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
................................................................................
  3016   3017   ** ^The third argument is the value to bind to the parameter.
  3017   3018   **
  3018   3019   ** ^(In those routines that have a fourth argument, its value is the
  3019   3020   ** number of bytes in the parameter.  To be clear: the value is the
  3020   3021   ** number of <u>bytes</u> in the value, not the number of characters.)^
  3021   3022   ** ^If the fourth parameter is negative, the length of the string is
  3022   3023   ** the number of bytes up to the first zero terminator.
         3024  +** If a non-negative fourth parameter is provided to sqlite3_bind_text()
         3025  +** or sqlite3_bind_text16() then that parameter must be the byte offset
         3026  +** where the NUL terminator would occur assuming the string were NUL
         3027  +** terminated.  If any NUL characters occur at byte offsets less than 
         3028  +** the value of the fourth parameter then the resulting string value will
         3029  +** contain embedded NULs.  The result of expressions involving strings
         3030  +** with embedded NULs is undefined.
  3023   3031   **
  3024   3032   ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
  3025   3033   ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
  3026   3034   ** string after SQLite has finished with it.  ^The destructor is called
  3027   3035   ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
  3028   3036   ** sqlite3_bind_text(), or sqlite3_bind_text16() fails.  
  3029   3037   ** ^If the fifth argument is
................................................................................
  4034   4042   ** the 2nd parameter of the sqlite3_result_text* interfaces.
  4035   4043   ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
  4036   4044   ** is negative, then SQLite takes result text from the 2nd parameter
  4037   4045   ** through the first zero character.
  4038   4046   ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
  4039   4047   ** is non-negative, then as many bytes (not characters) of the text
  4040   4048   ** pointed to by the 2nd parameter are taken as the application-defined
  4041         -** function result.
         4049  +** function result.  If the 3rd parameter is non-negative, then it
         4050  +** must be the byte offset into the string where the NUL terminator would
         4051  +** appear if the string where NUL terminated.  If any NUL characters occur
         4052  +** in the string at a byte offset that is less than the value of the 3rd
         4053  +** parameter, then the resulting string will contain embedded NULs and the
         4054  +** result of expressions operating on strings with embedded NULs is undefined.
  4042   4055   ** ^If the 4th parameter to the sqlite3_result_text* interfaces
  4043   4056   ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
  4044   4057   ** function as the destructor on the text or BLOB result when it has
  4045   4058   ** finished using that result.
  4046   4059   ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
  4047   4060   ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
  4048   4061   ** assumes that the text or BLOB result is in constant space and does not