--- Nuno Lucas <[EMAIL PROTECTED]> wrote:

> On 10/25/05, Joe Wilson <[EMAIL PROTECTED]> wrote:
> > The built-in Sqlite length() function works just fine on blobs:
> >
> >   sqlite> select length(X'0000000000');
> >   5
> >
> > Why do you think it doesn't?
> 
> I remember a few months ago noticing it would count UTF-8 chars, not
> bytes, so it would not return the right length for blobs in all cases
> (a '\0' is a valid UTF-8 char, but try with the '(c)' [copyright] sign,
> which is 2 bytes).
> 
> I don't have the code in front of me, and can be just my memory, but I
> don't see that behaviour changing or would break a lot of SQL during
> normal text manipulation.
> 
> Regards,
> ~Nuno Lucas

You are mistaken. Text and blobs are different.
TEXT is of type "SQLITE_TEXT". BLOB is of type "SQLITE_BLOB".
length() has always correctly returned the size of a blob - look at the code:

/*
** Implementation of the length() function
*/
static void lengthFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  int len;
  
  assert( argc==1 );
  switch( sqlite3_value_type(argv[0]) ){
    case SQLITE_BLOB:
    case SQLITE_INTEGER:
    case SQLITE_FLOAT: {
      sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
      break;
    }
    case SQLITE_TEXT: {
      const char *z = sqlite3_value_text(argv[0]);
      for(len=0; *z; z++){ if( (0xc0&*z)!=0x80 ) len++; }
      sqlite3_result_int(context, len);
      break;
    }
    default: {
      sqlite3_result_null(context);
      break;
    }
  }
}



                
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs

Reply via email to