Shailesh Birari wrote:
> Thank you for the input. THis is what I tried, 
> char*data = "THIS \\\"IS 'BLAH"
> This is a blob data of 40 bytes that I wanted to store, so all bytes
> after BLAH are all '\0'. 

No, data is a pointer to a literal character string of length 15.

> So I created a insert query like this, by converting the blob in
> hexadecimal format,
> 
> Insert into table values
> (X'54484953205c2249532027424c41480000000000000');  -> 0 are 40 times.
> 
> in the sqlite shell, select * from table, shows me the data as it is in
> X'hex' format. 
> 
> X'54484953205c2249532027424c41480000000000000000000000000000000000000000
> 0000000000'
> 
> And when I try to retrieve it using sqlite3_column_blob, and try to
> print that blob I see the same X'hex' string instead of "THIS \\\"IS
> 'BLAH". 

You encoded the data as hex characters before you inserted it, why are 
you surprised to get the data back encoded as hex characters?

If you want to get the data back as text you can cast the result of your 
query, but then you will run into your original problem of access to 
data after the first zero character.

   select cast(blob_field as text) from table;

> Why is this behaviour? We give input in hex format for sqlite to
> understand that this is a blob and not a text and it shoudl make the
> appropriate conversion to store it internally. I know sqlite treats blob
> and text the same, but is there no way that I can get the binary data as
> I have? Do I again need to convert the hex string into my binary blob
> buffer?
> 

You would really be much better off using bound parameters and the C API 
functions to store and retrieve blob data.

HTH
Dennis Cote
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to