Bug 18807 - Support storing JavaScript objects as BLOB
Summary: Support storing JavaScript objects as BLOB
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Major
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-29 22:52 PDT by Jayant Sai
Modified: 2023-08-24 03:53 PDT (History)
6 users (show)

See Also:


Attachments
Test page (1.64 KB, text/html)
2008-04-29 22:54 PDT, Jayant Sai
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jayant Sai 2008-04-29 22:52:20 PDT
According to http://www.sqlite.org/datatype3.html, 'BLOB. The value is a blob of data, stored exactly as it was input.'. Currently in WebKit & Safari, the implementation seems to convert the JavaScript object to a string "[object Object]". It would be great if it were possible to store JavaScript objects and JSON objects within the database as BLOB and as objects and not as string representations.

Currently, only a string de/serialization would work, but that can be expensive, especially when trying to run Safari on iPhone which has very limited JavaScript execution time.
Comment 1 Jayant Sai 2008-04-29 22:54:26 PDT
Created attachment 20897 [details]
Test page

A simple test page showing storing an object literal as BLOB. Currently the alert displays the type of data after SELECT as string.
Comment 2 Alexey Proskuryakov 2008-05-05 12:02:36 PDT
SQLite documentation is only tangentially related to HTML5 storage, because there are at least two other type systems to consider - first, there is JavaScript, and then, there is DOM. And anyway, BLOB is not magic - it's just a special kind of string suitable for storing large amounts of data.

Yet, it does seem a little weird that a function is stringified like "[object Object]" in this test case - e.g. alert(selectData) successfully shows its source, and one could expect the same here.
Comment 3 Jayant Sai 2008-05-07 16:23:50 PDT
Thank you for clarifying about the SQLite & HTML5 storage differences.

Do you have any recommendations on how I should store the object, without converting it to a String. In my current app, this conversion takes too long. Or is this a bug which will need to be fixed in WebKit?

thanks
Jayant

(In reply to comment #2)
> SQLite documentation is only tangentially related to HTML5 storage, because
> there are at least two other type systems to consider - first, there is
> JavaScript, and then, there is DOM. And anyway, BLOB is not magic - it's just a
> special kind of string suitable for storing large amounts of data.
> 
> Yet, it does seem a little weird that a function is stringified like "[object
> Object]" in this test case - e.g. alert(selectData) successfully shows its
> source, and one could expect the same here.
> 

Comment 4 Alexey Proskuryakov 2008-05-11 03:37:05 PDT
I don't think there is any way to store an object without turning it into a string. You may want to join WHATWG <http://www.whatwg.org/> and describe your use case in an e-mail to its list for people working on the specification to consider it.

Brady, what do you think? Does our implicit stringification appear broken, as I wondered in comment 2?
Comment 5 Oliver Hunt 2009-07-07 22:51:15 PDT
JSON.stringify would appear to accomplish what is being requested here
Comment 6 Oliver Hunt 2011-06-24 12:07:49 PDT
(In reply to comment #5)
> JSON.stringify would appear to accomplish what is being requested here

As an addendum, our postMesage serialisation is a flat binary storage system that supports  avariety of dom objects and allows cyclic graphs, maybe that would be superior?
Comment 7 Anne van Kesteren 2023-08-24 03:53:37 PDT
This should be standardized first as suggested above. But also, as suggested above, there's ample alternatives available.