On 9 Jul 2010, at 5:48pm, Eric Smith wrote:

> Simon Slavin wrote: 
>> BLOBs can handle any sequences of bytes without problems, 
>> including nulls, ETX, and sequences which be illegal if they were used to 
>> express Unicode characters.  You can put anything you like in a BLOB.  
> I assume, due to the manifest typing semantics of the library, that 
> the declared type of the column will make no difference when I bind a 
> weird datum to a variable (as long as it's not an 'INTEGER PRIMARY KEY' 
> column).

You can use the _bind_blob routine to bind something which will eventually be 
stored in a column with TEXT affinity.  (Sorry, I hate that sentence but I 
can't figure out how to improve it.)  There are no problems doing this.

> Will sqlite3_bind_text work properly if the string contains (internal) 
> nulls?

There are many different meanings for 'string' and I can't answer any question 
about 'properly' until you describe in great detail what you mean by 'string'.  
On the other hand _bind_blob doesn't refer to strings at all.

> What if I did something like: 
> char zText[100];
> memset(zText, 0, sizeof(zText)); 
> sqlite3_bind_text(stmt, idx, zText, sizeof(zText), SQLITE_TRANSIENT);

Read the documentation for memset().  It does not take chars as parameters and 
does not use them internally.

You are using a _text routine with an array of 'char's.  Those lines will work 
perfectly together.  But they has nothing to do with using BLOBs in SQLite.  
For that you would not use _bind_text, you'd use _bind_blob with things that 
probably do not represent characters.  Possibly 'unsigned int' would be a more 
appropriate type than 'char'.

> According to a strict reading of the doc, sqlite will blindly copy
> sizeof(zText) characters (starting from zText[0]) into the column.  
> That is, this will store 100 null bytes into the column.  Is that 
> right?

Text is not bytes, it's characters.  Text involves interpretation.  BLOBs, on 
the other hand, are just sequences of bytes which are treated without any 
attempt to interpret or convert them at all.  Since this is what your data 
actually is (according to your earlier post) you should be declaring your 
column as a BLOB column and using _blob routines to handle them.

sqlite-users mailing list

Reply via email to