--- Nathan Kurz <[EMAIL PROTECTED]> wrote:

> On Wed, Dec 07, 2005 at 08:49:42PM +0100, [EMAIL PROTECTED] wrote:
> > Hello,
> > I have a following problem.
> > In my program I have a vector of elements let say defined as follow:
> > 
> > struct intDouble {
> >   int x;
> >   int y; 
> > };
> 
> It's pretty straightforward, presuming you've already figured out the
> basics of connecting to the database.  You need to use 'blobs', which
> are traditionally Binary Large Objects, but they can easily be small
> objects as well.  Check out the documentation for:
> http://www.sqlite.org/capi3ref.html#sqlite3_bind_blob and
> http://www.sqlite.org/capi3ref.html#sqlite3_result_blob
> 
> To make it work in more than a superficial manner, you probably will
> need a good understanding of how structures are internally represented
> in C++ or C.  You pass sqlite a pointer to the struct and tell it how
> long it is (using sizeof()).  When you get the blob back, you then
> treat the data as an instance of your structure by casting it.

I'm not sure this is always the best way to go. Any databases produced like 
this will not be portable between architectures. In theory, they may not
be portable between compilers, but in practice you're probably Ok there.

Also, SQLite makes no guarantees as to the alignment of returned blobs. 
This could cause a random crash somewhere down the line. You could get
around this by making a copy of the blob to memory obtained from malloc().

If at all possible, recreating the same structure as a tuple type is 
almost certainly better. Although much more difficult to automate.

CREATE TABLE intDouble (x INTEGER, y INTEGER);


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to