Re: [sqlite] [EXTERNAL] bind blob lifetime

2018-01-10 Thread Dave Milter
On Tue, Jan 9, 2018 at 7:28 PM, Hick Gunter  wrote:
> A bound blob or string is destroyed "after SQLite has finished with it". This 
> should be the case when sqlite3_clear_bindings() is called. Are you sure it 
> is not deleted then? Code reading suggests it should be.
>
> Other times are when the parameter is re-bound, or the statement finalized.
>

Sorry for misunderstanding. I did not do any experiments, I only read
documentation couple of times about "bind_blob",
and it was not clear when destructor will be called by sqlite.
Thank you!
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] bind blob lifetime

2018-01-09 Thread Dave Milter
I have cycle like this:

```c
const char sql[] = "INSERT INTO test (pk, geom) VALUES (?, ?)";
sqlite3_stmt *stmt;
sqlite3_prepare_v2 (handle, sql, strlen (sql), , NULL);

for (...) {
sqlite3_reset (stmt);
sqlite3_clear_bindings (stmt);
int blob_size = ..;
unsigned char *blob = malloc(blob_size);
sqlite3_bind_int64 (stmt, 1, pk);
sqlite3_bind_blob (stmt, 2, blob, blob_size, free);
sqlite3_step (stmt);
}
//sqlite3_finalize
```

I wonder is it necessary to allocate memory on every cycle?
I know that I can pass SQLITE_TRANSIENT, but in this case code would
be exactly the same, just allocation on every cycle happens inside
sqlite.

According to documentation  it is not clear when sqlite call
destructor of blob (in our case  "free"), is it happens after:
sqlite3_reset
sqlite3_clear_bindings
sqlite3_bind_blob
step

sqlite3_reset
sqlite3_clear_bindings
sqlite3_bind_blob
<< here previous memory was freed???
step

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