On 14/05/2009 12:23 AM, Salvatore Di Guida wrote:
> Hi all!
> Since I am a newcomer in SQLite, as a preliminary question, what is the 
> difference between 
> sqlite> select length(X'01');
> and
> sqlite> select length('01');
> It seems that the former gives the size in bytes, the latter the length of 
> the string.
> 
> The SQLite documentation says that the length function returns the 
> string length of /X/ in characters if /X/ is a string, or in bytes if 
> /X/ is a blob.

The concept "blob length in characters" is meaningless. The first "b" in 
"blob" means "Binary". A blob contains whatever you know/hope it 
contains, or something completely different ... it could be an 80-bit 
float or a 128-bit integer; it could be some complicated structure that 
you have serialised; etc etc. Only the length in bytes has any meaning.

"Characters" have meaning only with TEXT data. A (Unicode) character 
will occupy 1, 2, or 3 bytes depending on the character itself, if 
encoded in UTF-8 (the SQLite default); 2 bytes if UTF-16.

> 
> However, I tried this example:
> 
> sqlite3 test.db
> 
> SQLite version 3.6.10
> 
> Enter ".help" for instructions
> 
> Enter SQL statements terminated with a ";"
> 
> sqlite> create table x ( a TEXT, b BLOB );
> 
> sqlite> insert into x values ( 'a', 'a' );

I see no blobs here.

> 
> sqlite> insert into x values ( 'abcd', 'abcd' );

Nor here.

Igor has already pointed you at http://www.sqlite.org/datatype3.html -- 
do read it carefully and ask questions here if some of it is puzzling.

> 
> sqlite> select length(a), length(b) from x;
> 
> 1|1
> 
> 4|4
> 
> 
> The length function, then, measures the length in characters of the 
> blob.

That is a non sequitur, to put it mildly.

> What can I do in order to obtain the size in bytes of the blob?

length(the_blob)

HTH,

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

Reply via email to