Tcl and BLOB data

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Tcl and BLOB data

jgodfrey
Hi All,

I have an interesting Tcl / SQLite BLOB issue going on that I hope you can help with...

I have binary data stored in a Tcl variable that I'm stuffing into SQLite BLOB field.  The resulting data in the BLOB field is corrupted.  After much experimentation, and help from the folks on comp.lang.tcl, it seems that the issue is related to whether or not the Tcl variable in question contains a string representation at the time it's inserted into the BLOB field.

If it does contain a string representation, the inserted data is incorrect.  If it does not contain a string representation, the inserted data is correct.  Not wanting to get into a "Tcl Internals" discussion here, my question is this:

Is there a way I can "force" SQLite to insert my data as a BLOB, even if the containing variable has a string representation?  I tried to CAST the data to a BLOB during the insert, but the results were the same.

I have several potential solutions from the Tcl side, but wanted to explore the possibilities from this side also.

Thanks for any input.

Jeff Godfrey
Reply | Threaded
Open this post in threaded view
|

Re: Tcl and BLOB data

D. Richard Hipp
"Jeff Godfrey" <[hidden email]> wrote:
>
> Is there a way I can "force" SQLite to insert my data as a BLOB, even if the containing variable has a string representation?  I tried to CAST the data to a BLOB during the insert, but the results were the same.
>

If you get the patch I just checked in

  http://www.sqlite.org/cvstrac/chngview?cn=4092

and if you use a "@" character instead of "$" in front of the
variable name, and the variable has a bytearray representation,
then the variable will be bound as a BLOB even if the variable
also has a text representation.

--
D. Richard Hipp <[hidden email]>


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Tcl and BLOB data

jgodfrey
Interesting.  That sounds like exactly what I need.  I'm curious, did
the patch somehow arise from my query, or is the timing of the query
and the patch just coincidental?

Also, how soon would you expect this patch to make it into an
"official build"?  I've never built SQLite from the sources before,
and don't really have the time to work through the details right now.

Thank you.

Jeff Godfrey

----- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, June 19, 2007 12:17 PM
Subject: Re: [sqlite] Tcl and BLOB data


"Jeff Godfrey" <[hidden email]> wrote:
>
> Is there a way I can "force" SQLite to insert my data as a BLOB,
> even if the containing variable has a string representation?  I
> tried to CAST the data to a BLOB during the insert, but the results
> were the same.
>

If you get the patch I just checked in

  http://www.sqlite.org/cvstrac/chngview?cn=4092

and if you use a "@" character instead of "$" in front of the
variable name, and the variable has a bytearray representation,
then the variable will be bound as a BLOB even if the variable
also has a text representation.

--
D. Richard Hipp <[hidden email]>


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Tcl and BLOB data

D. Richard Hipp
"Jeff Godfrey" <[hidden email]> wrote:
> Interesting.  That sounds like exactly what I need.  I'm curious, did
> the patch somehow arise from my query, or is the timing of the query
> and the patch just coincidental?
>
> Also, how soon would you expect this patch to make it into an
> "official build"?  I've never built SQLite from the sources before,
> and don't really have the time to work through the details right now.
>

I did this change at your request, because it seemed like a good
enhancement.  The next "official build" will be 3.4.1.  Point
releases normally come every 1 to 2 months, and we just had 3.4.0,
so do not look for 3.4.1 until the end of July, realistically.

How can we help you to do your own build?  It really is not that
hard.  What operating system are you using?

--
D. Richard Hipp <[hidden email]>


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Tcl and BLOB data

jgodfrey

----- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, June 19, 2007 3:43 PM
Subject: Re: [sqlite] Tcl and BLOB data

> I did this change at your request, because it seemed like
> a good enhancement.

Thanks.  I agree, it sounds like a good enhancement.  Though, I don't
really understand why, when my data has a binary representation and
I'm trying to place it in a BLOB field, the string representation is
used instead (assuming it exists).  It seems that the fact I'm pushing
the data into a BLOB field should force the selection of the binary
representation.  That said, I'm sure I'm over-simplifying the
situation.

> How can we help you to do your own build?  It really is not that
> hard.  What operating system are you using?

Hmmm... Maybe point me to some docs.  I seem to remember seeing some
on the Wiki before.  In reality, I *have* tried to build the package
before (quite some time ago), and don't think I had any luck.  I
running on WinXP, though I have mingw, msys, and tcl installations.
I'll give it another try if there's some current documentation
available...

Thank you.

Jeff


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Tcl and BLOB data

D. Richard Hipp
"Jeff Godfrey" <[hidden email]> wrote:
>
> I don't really understand why, when my data has a binary
> representation and I'm trying to place it in a BLOB field,
> the string representation is used instead (assuming it exists).
>

I wrote up a terse explanation on the Tclers wiki.  See

   http://wiki.tcl.tk/19627


--
D. Richard Hipp <[hidden email]>


-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Tcl and BLOB data

jgodfrey
Very informative.  Thank you.

Jeff


----- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, June 19, 2007 8:59 PM
Subject: Re: [sqlite] Tcl and BLOB data


"Jeff Godfrey" <[hidden email]> wrote:
>
> I don't really understand why, when my data has a binary
> representation and I'm trying to place it in a BLOB field,
> the string representation is used instead (assuming it exists).
>

I wrote up a terse explanation on the Tclers wiki.  See

   http://wiki.tcl.tk/19627



-----------------------------------------------------------------------------
To unsubscribe, send email to [hidden email]
-----------------------------------------------------------------------------