SQLite Forum

length function for BLOB out of sync with documentation
Login
> However, when a BLOB contains valid UTF-8 sequences, length returns the number of characters, not bytes.

This is incorrect.  Each value has a type and you can find out the type of X by using the typeof(X) function.

If typeof(X) == 'blob' then length(X) is the number of bytes in X.

If typeof(X) == 'text' then length(X) is the number of characters in X.

If typeof(X) == 'null' then length(X) is null.

If typeof(X) in ('integer', 'real') then the value is cast to text (ie, as if printed) and the number of characters in the resulting text returned.

The declared affinity of X does not mean that any particular instance of X is of that preferred type.  Each instance of X may have a different type which you may determine using various API methods or the typeof(X) SQL function (which returns a text string of 'blob', 'text', 'integer', 'real', 'null').

It is likely that the typeof(X) is not what you believe it to be.