On 7/1/07, Rich Rattanni <[EMAIL PROTECTED]> wrote:
On 7/1/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> "Rich Rattanni" <[EMAIL PROTECTED]> wrote:
> > All:
> > I am using SQlite to store several rows of binary data into a
> > database. In my code I have a several character arrays containing
> > data. I then do the following...
> >
> > 1.Begin Transaction
> > 2.For each blob...
> > 2a.sqlite3_prepare("Insert statement...")
> > 2b.call sqlite3_bind_blob(stmt, col#, dataPointer, sizeOfData,
SQLITE_TRANSIENT)
> > 2c.sqlite3_step()
> > 2d.end
> > 3.Free data pointers.
> > 4.Commit Transaction
> >
> > This code segfaults. Now If i move the free data pointers to outside
> > the commit, everything is fine. According to the API documentation,
> > "If the fifth argument has the value SQLITE_TRANSIENT, then SQLite
> > makes its own private copy of the data immediately, before the
> > sqlite3_bind_*() routine returns." I may be misinterperting the
> > documentation, or perhaps this is a bug in sqlite (course I am
> > assuming the former is true).
> >
> > Could anyone shed some light on my mystery? I am wondering if I need
> > to enable (when sqlite is compiled) support for SQLITE_TRANSIENT?
> >
>
> The documentation is correct - SQLITE_TRANSIENT causes SQLite
> to make a copy of the data before sqlite3_bind_blob() returns.
> You should be able to free the dataPointer prior to the sqlite3_step().
> No special compile-time optimizations are required.
>
> If you have a reproducible test case, we will look into the problem.
>
> --
> D. Richard Hipp <[EMAIL PROTECTED]>
>
>
> -----------------------------------------------------------------------------
> To unsubscribe, send email to [EMAIL PROTECTED]
> -----------------------------------------------------------------------------
>
>
Sir:
Thanks for the quick reply. I will try to work up a test case in
my spare time I had GDB running when this problem occured, and it
said the offending function was sqlite3pager_get(). I am not sure if
this helps in any way. Again thanks for your response.
--
Rich Rattanni
Sir:
I was trying to look through the SQLITE source code to see how the
sqlite3_bind_blob routine worked.
sqlite3_bind_blob passes the data pointer to bindText
bindText passes the data pointer to sqlite3VdbeMemSetStr
sqlite3VdbeMemSetStr then does...
...
pMem->z = (char *)z;
if( xDel==SQLITE_STATIC ){
pMem->flags = MEM_Static;
}else if( xDel==SQLITE_TRANSIENT ){
pMem->flags = MEM_Ephem;
}else{
pMem->flags = MEM_Dyn;
pMem->xDel = xDel;
}
...
I dont see anywhere where sqlite3 copies data to a private buffer, I
just see where sqlite3 saves a copy of the user pointer.
I see that sqlite3VdbeMemDynamicify memcpy's from the private data to
the vdbe object. Should the if ...else if ... else then look like
this?
if( xDel==SQLITE_STATIC ){
pMem->flags = MEM_Static;
}else if( xDel==SQLITE_TRANSIENT ){
pMem->flags = MEM_Ephem;
sqlite3VdbeMemDynamicify(pMem);
}else{
pMem->flags = MEM_Dyn;
pMem->xDel = xDel;
}
Just trying to help if I can... Am I looking at this right?
--
Rich Rattanni
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------