Dennis Cote wrote:
Shawn Walker wrote:
How do I determine the size of the value of the string/blob that is in
the database? I would like to know how big the data so that I can
determine how to handle the data if it's a large data so that I can
put the data in a file instead of in memory.
Shawn,
You can use the sqlite3_column_bytes() API function to get the size of a
string or blob, but by the time you can do this (i.e. after calling
sqlite3_step()) it is already in memory and ready to be returned to you
using sqlite3_column_blob() or sqlite3_column_text(). These functions
return pointers to the buffer that holds the blob or string. You could
perhaps use this to copy each individual blob to a file so you only have
the current one in memory (rather than having many large blobs in memory).
Sqlite deals with blobs a single objects, and doesn't let you read or
write the value in small chunks as you seem to be looking for. You can't
store and retrieve blobs that are bigger than your available memory.
For large blobs, the consensus seems to be that you are best off storing
the data in a file and storing the filename in your database. However
you do lose the nice "one file per database" characteristic of sqlite by
doing this.
HTH
Dennis Cote
Thanks Dennis,
We are currently storing very large data in a seperate file and store
the filename in the database. The type of strings/blob that we are
storing the DB can sometimes get big, but not so big that we require
those to be in a file. The reason I would like to get the size of the
data before they are in memory is to decide if I want to store that
string/blob in memory or redirect them to a temporary file for the user
to view the data.
Shawn
- Re: [sqlite] How to get the size of the value Shawn Walker
-