Re: [sqlite] lifetime of buffer referred to with SQLITE_STATIC

2014-06-13 Thread Igor Tandetnik

On 6/13/2014 1:27 PM, Richard Hipp wrote:

On Fri, Jun 13, 2014 at 1:20 PM, Eric Rubin-Smith  wrote:


If I say sqlite_bind_text(...SQLITE_STATIC), I am promising that the buffer
is going to stick around for a while.  How long am I promising that it will
stick around?  Til the next statement reset()?  Til the statement
finalize()?  Til the database close()?



Until the parameter you are binding against cannot long be used.  Which
will be either (1) sqlite3_reset() or (2) sqlite3_finalize() or (3) the
next sqlite3_bind() against the same parameter, whichever comes first.


I believe it's possible, though unusual, to step, then reset, then step 
again without rebinding, at which point the previous parameter value 
will be used and must remain alive.


Perhaps something like this: the buffer must remain alive through any 
call to sqlite3_step that "uses" it. sqlite3_step uses the buffer if a) 
it was bound to a parameter by a prior sqlite3_bind_* call, and b) there 
was no intervening sqlite3_bind_* call for the same parameter, nor 
sqlite3_clear_bindings call.


As a corollary, the buffer is no longer needed after sqlite3_finalize, 
simply because it would not be possible to call sqlite3_step anymore on 
the finalized statement.

--
Igor Tandetnik

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


Re: [sqlite] lifetime of buffer referred to with SQLITE_STATIC

2014-06-13 Thread Richard Hipp
On Fri, Jun 13, 2014 at 1:20 PM, Eric Rubin-Smith  wrote:

> If I say sqlite_bind_text(...SQLITE_STATIC), I am promising that the buffer
> is going to stick around for a while.  How long am I promising that it will
> stick around?  Til the next statement reset()?  Til the statement
> finalize()?  Til the database close()?
>

Until the parameter you are binding against cannot long be used.  Which
will be either (1) sqlite3_reset() or (2) sqlite3_finalize() or (3) the
next sqlite3_bind() against the same parameter, whichever comes first.



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



-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] lifetime of buffer referred to with SQLITE_STATIC

2014-06-13 Thread Stephan Beal
On Fri, Jun 13, 2014 at 7:20 PM, Eric Rubin-Smith  wrote:

> If I say sqlite_bind_text(...SQLITE_STATIC), I am promising that the buffer
> is going to stick around for a while.  How long am I promising that it will
> stick around?  Til the next statement reset()?  Til the statement
> finalize()?  Til the database close()?
>

Until the statement is done with that specific value. My rule of thumb is:
the bytes must outlive the step() call. After step(), the statement won't
do anything with those bytes (won't read/inspect them) because it has no
need to. i use SQLITE_STATIC quite a lot for non-static data (b/c copying
bytes for this type of thing pains me greatly), and the only guaranty i've
ever needed making is that the bytes outlive the step() which accesses them.

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal
"Freedom is sloppy. But since tyranny's the only guaranteed byproduct of
those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users