Re: [sqlite] Hard time with blobs

2008-07-25 Thread Igor Tandetnik
"Sherief N. Farouk" <[EMAIL PROTECTED]>
wrote in message news:[EMAIL PROTECTED]
> That will make this case legal. What's the general behavior though?
> Is it not guaranteed to be consumed during the call to bind_blob? In
> other words, without providing SQLITE_TRANSIENT, can I get into
> trouble with this?

SQLITE_TRANSIENT does precisely that - it tells SQLite to "consume" the 
data during the call to sqlite3_bind_blob (by making its own copy and 
managing it itself). By not using SQLITE_TRANSIENT, you avoid an extra 
copy, but you promise SQLite that the data will still be around by the 
time it needs to be written to disk (e.g. when the surrounding 
transaction is committed).

You can use SQLITE_STATIC - then you will have to keep the data alive at 
least until the transaction is committed and the statement is reset. 
Otherwise, you can provide a callback function, which will be called 
when SQLite no longer needs the data.

Igor Tandetnik 



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


Re: [sqlite] Hard time with blobs

2008-07-25 Thread Sherief N. Farouk
That will make this case legal. What's the general behavior though? Is it
not guaranteed to be consumed during the call to bind_blob? In other words,
without providing SQLITE_TRANSIENT, can I get into trouble with this?

- Sherief

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:sqlite-users-
> [EMAIL PROTECTED] On Behalf Of Dan
> Sent: Friday, July 25, 2008 3:22 AM
> To: General Discussion of SQLite Database
> Subject: Re: [sqlite] Hard time with blobs
> 
> 
> On Jul 25, 2008, at 12:05 PM, Sherief N. Farouk wrote:
> 
> > I'm having a problem with the last parameter, the function used to
> > dispose
> > of the blob. Does sqlite defer actually inserting the blob into the
> > database
> > somehow? In other words, will I get into trouble if I do:
> >
> > Sqlite3_bind_blob(Statement, 1, BlobData, BlobSize, do_nothing);
> > Delete [] BlobData;
> >
> 
> Use SQLITE_TRANSIENT.
> 
> Dan.
> 
> > ?
> >
> > - Sherief
> >
> >> -Original Message-
> >> From: [EMAIL PROTECTED] [mailto:sqlite-users-
> >> [EMAIL PROTECTED] On Behalf Of Dan
> >> Sent: Friday, July 25, 2008 12:51 AM
> >> To: General Discussion of SQLite Database
> >> Subject: Re: [sqlite] Hard time with blobs
> >>
> >>
> >> On Jul 25, 2008, at 10:35 AM, Sherief N. Farouk wrote:
> >>
> >>> I want to use blobs to store binary objects in the database, but
> >>> I'm having
> >>> a hard time understanding how they work. First of all, I don't see
> >>> a way to
> >>> set a blob's size, and sqlite3_blob_write doesn't increase the size
> >>> of the
> >>> blob, which is putting me in a weird catch-22 situation.
> >>>
> >>> What's the best solution for storing a bunch of binary objects,
> >>> given the
> >>> two alternatives: They may be immutable (write once, read many), or
> >>> mutable
> >>> (write many, possibly overwriting regions or appending, write
> many)?
> >>
> >> You can work with blobs without using the sqlite3_blob_XXX() APIs.
> >> Insert
> >> blobs by binding them with sqlite3_bind_blob(), retrieve them using
> >> sqlite3_column_blob().
> >>
> >> Sometimes it is better to use the sqlite3_blob_XXX() APIs because
> >> they
> >> allow sqlite to work with large blobs without creating a copy of the
> >> blob in memory. To create a large zeroed blob in the database, use
> >> either sqlite3_bind_zeroblob() or the "zeroblob" SQL function. Then
> >> populate it using sqlite3_blob_XXX() after it has been inserted.
> >>
> >> Dan.
> >>
> >> ___
> >> sqlite-users mailing list
> >> sqlite-users@sqlite.org
> >> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> >
> > ___
> > sqlite-users mailing list
> > sqlite-users@sqlite.org
> > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

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


Re: [sqlite] Hard time with blobs

2008-07-25 Thread Dan

On Jul 25, 2008, at 12:05 PM, Sherief N. Farouk wrote:

> I'm having a problem with the last parameter, the function used to  
> dispose
> of the blob. Does sqlite defer actually inserting the blob into the  
> database
> somehow? In other words, will I get into trouble if I do:
>
> Sqlite3_bind_blob(Statement, 1, BlobData, BlobSize, do_nothing);
> Delete [] BlobData;
>

Use SQLITE_TRANSIENT.

Dan.

> ?
>
> - Sherief
>
>> -Original Message-
>> From: [EMAIL PROTECTED] [mailto:sqlite-users-
>> [EMAIL PROTECTED] On Behalf Of Dan
>> Sent: Friday, July 25, 2008 12:51 AM
>> To: General Discussion of SQLite Database
>> Subject: Re: [sqlite] Hard time with blobs
>>
>>
>> On Jul 25, 2008, at 10:35 AM, Sherief N. Farouk wrote:
>>
>>> I want to use blobs to store binary objects in the database, but
>>> I'm having
>>> a hard time understanding how they work. First of all, I don't see
>>> a way to
>>> set a blob's size, and sqlite3_blob_write doesn't increase the size
>>> of the
>>> blob, which is putting me in a weird catch-22 situation.
>>>
>>> What's the best solution for storing a bunch of binary objects,
>>> given the
>>> two alternatives: They may be immutable (write once, read many), or
>>> mutable
>>> (write many, possibly overwriting regions or appending, write many)?
>>
>> You can work with blobs without using the sqlite3_blob_XXX() APIs.
>> Insert
>> blobs by binding them with sqlite3_bind_blob(), retrieve them using
>> sqlite3_column_blob().
>>
>> Sometimes it is better to use the sqlite3_blob_XXX() APIs because  
>> they
>> allow sqlite to work with large blobs without creating a copy of the
>> blob in memory. To create a large zeroed blob in the database, use
>> either sqlite3_bind_zeroblob() or the "zeroblob" SQL function. Then
>> populate it using sqlite3_blob_XXX() after it has been inserted.
>>
>> Dan.
>>
>> ___
>> sqlite-users mailing list
>> sqlite-users@sqlite.org
>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

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


Re: [sqlite] Hard time with blobs

2008-07-24 Thread Sherief N. Farouk
I'm having a problem with the last parameter, the function used to dispose
of the blob. Does sqlite defer actually inserting the blob into the database
somehow? In other words, will I get into trouble if I do:

Sqlite3_bind_blob(Statement, 1, BlobData, BlobSize, do_nothing);
Delete [] BlobData;

?

- Sherief

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:sqlite-users-
> [EMAIL PROTECTED] On Behalf Of Dan
> Sent: Friday, July 25, 2008 12:51 AM
> To: General Discussion of SQLite Database
> Subject: Re: [sqlite] Hard time with blobs
> 
> 
> On Jul 25, 2008, at 10:35 AM, Sherief N. Farouk wrote:
> 
> > I want to use blobs to store binary objects in the database, but
> > I'm having
> > a hard time understanding how they work. First of all, I don't see
> > a way to
> > set a blob's size, and sqlite3_blob_write doesn't increase the size
> > of the
> > blob, which is putting me in a weird catch-22 situation.
> >
> > What's the best solution for storing a bunch of binary objects,
> > given the
> > two alternatives: They may be immutable (write once, read many), or
> > mutable
> > (write many, possibly overwriting regions or appending, write many)?
> 
> You can work with blobs without using the sqlite3_blob_XXX() APIs.
> Insert
> blobs by binding them with sqlite3_bind_blob(), retrieve them using
> sqlite3_column_blob().
> 
> Sometimes it is better to use the sqlite3_blob_XXX() APIs because they
> allow sqlite to work with large blobs without creating a copy of the
> blob in memory. To create a large zeroed blob in the database, use
> either sqlite3_bind_zeroblob() or the "zeroblob" SQL function. Then
> populate it using sqlite3_blob_XXX() after it has been inserted.
> 
> Dan.
> 
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

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


Re: [sqlite] Hard time with blobs

2008-07-24 Thread Dan

On Jul 25, 2008, at 10:35 AM, Sherief N. Farouk wrote:

> I want to use blobs to store binary objects in the database, but  
> I'm having
> a hard time understanding how they work. First of all, I don't see  
> a way to
> set a blob's size, and sqlite3_blob_write doesn't increase the size  
> of the
> blob, which is putting me in a weird catch-22 situation.
>
> What's the best solution for storing a bunch of binary objects,  
> given the
> two alternatives: They may be immutable (write once, read many), or  
> mutable
> (write many, possibly overwriting regions or appending, write many)?

You can work with blobs without using the sqlite3_blob_XXX() APIs.  
Insert
blobs by binding them with sqlite3_bind_blob(), retrieve them using
sqlite3_column_blob().

Sometimes it is better to use the sqlite3_blob_XXX() APIs because they
allow sqlite to work with large blobs without creating a copy of the
blob in memory. To create a large zeroed blob in the database, use
either sqlite3_bind_zeroblob() or the "zeroblob" SQL function. Then
populate it using sqlite3_blob_XXX() after it has been inserted.

Dan.

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


[sqlite] Hard time with blobs

2008-07-24 Thread Sherief N. Farouk
I want to use blobs to store binary objects in the database, but I'm having
a hard time understanding how they work. First of all, I don't see a way to
set a blob's size, and sqlite3_blob_write doesn't increase the size of the
blob, which is putting me in a weird catch-22 situation.

What's the best solution for storing a bunch of binary objects, given the
two alternatives: They may be immutable (write once, read many), or mutable
(write many, possibly overwriting regions or appending, write many)?

- Sherief

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