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