If the register object contains "text" and you cast it to a blob (remove the 
text affinity) you are left with just the bag-o-bytes, and length() will return 
the size of the bag encoded in the register.  If the data in the register is 
other than type "text" then it must be converted to text first (in the database 
encoding) and then the cast will remove the text affinity, after which the 
value returned by the length() function will be the number of bytes in the bag 
that holds that text representation:

SQLite version 3.31.0 2020-01-12 23:30:01
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> pragma encoding;
UTF-8
sqlite> create table x(x);
sqlite> insert into x values ('text' || char(0) || 'text');
sqlite> insert into x values (3.14159);
sqlite> select x, typeof(x), length(x), length(cast(x as blob)) from x;
text|text|4|9
3.14159|real|7|7
sqlite> .q

SQLite version 3.31.0 2020-01-12 23:30:01
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> pragma encoding='utf-16';
sqlite> pragma encoding;
UTF-16le
sqlite> create table x(x);
sqlite> insert into x values ('text' || char(0) || 'text');
sqlite> insert into x values (3.14159);
sqlite> select x, typeof(x), length(x), length(cast(x as blob)) from x;
text|text|4|18
3.14159|real|7|14
sqlite> .q

-- 
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.



_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to