ahhhh. This is what confused me-- the documentation for the prepare statement 
mentions this perf boost being quite explicit about including the null, then 
also makes the ambiguous statement that "the zSQL string ends at either the 
first '\000' or '\u0000' character or the nbyteth byte, whichever comes first." 
Since the null gets ignored, I interpreted this as meaning that the nth byte 
was ignored, and that providing the proper data size was the source of the 
performance boost (possibly by eliminating a search for null termination). 

Thank you for the clarification :-).


-sean

-----Original Message-----
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Richard Hipp
Sent: Wednesday, September 21, 2011 12:23 PM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] c-api document suggestion

On Wed, Sep 21, 2011 at 3:05 PM, Sean Pieper <spie...@nvidia.com> wrote:

> There's an apparent inconsistency in the behavior of  sqlite3_bind_text and
> sqlite3_prepare_v2.
> If the user supplies the length of the argument rather than using -1,
> bind_text expects that this length exclude the null termination, whereas
> prepare apparently expects it to include the null termination.
>

No, sqlite3_prepare_v2() does not *expect* N to be size+1.
sqlite3_prepare_v2() with length N will process all text up to the first
zero-character, or the first N bytes, whichever come first.  So you are
perfectly free to set N equal to the length of the string exclusive of the
zero-terminator, just as in bind_text().

However, if you are willing to make N equal to the length of the string plus
one, then SQLite can avoid a memcpy() and thus give a very small performance
advantage.  But that is purely an optimization, and a minor one at that.  It
will work correctly regardless of whether N is strlen() or strlen()+1.

-- 
D. Richard Hipp
d...@sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may 
contain
confidential information.  Any unauthorized review, use, disclosure or 
distribution
is prohibited.  If you are not the intended recipient, please contact the 
sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to