Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring byte array in HTML5 sqlite database
    primarykey
    data
    text
    <p>I am working on an offline capable mobile web app and need to store large amounts of raw byte data in a HTML5 database. I want to store them as compact as possible, so a joined string is not an option. Here is a sample code that creates a db, table, inserts data and retrieves it again. </p> <p>Example:</p> <pre><code>var bytes=[97, 0, 6, 244, 98, 66, 76, 65, 131, 5, 7, 142, 81, 184, 112, 33]; openDatabase('_test_', 1.0, '_test-', 5000).transaction(function(tx) { tx.executeSql("DROP TABLE IF EXISTS MYTABLE", [], function(){ tx.executeSql("CREATE TABLE IF NOT EXISTS MYTABLE(content BLOB);",[],function(){ tx.executeSql("INSERT INTO MYTABLE values(?)", [bytes], function() { tx.executeSql("SELECT * FROM MYTABLE ", [], function(transaction, results) { console.log(results.rows.item(0)) }); },function(transaction, error){console.log(error)}) },function(transaction, error){console.log(error)}) }) }) </code></pre> <p>I am trying to store the array as is, which actually saves as a joined string :"97, 0, 6, 244, 98, 66, 76, 65, 131, 5, 7, 142, 81, 184, 112, 33". Not what I need since it will be way too large.</p> <p>I am converting the array into a string now:</p> <pre><code>openDatabase('_test_', 1.0, '_test-', 5000).transaction(function(tx) { tx.executeSql("DROP TABLE IF EXISTS MYTABLE", [], function(){ tx.executeSql("CREATE TABLE IF NOT EXISTS MYTABLE(content BLOB); ", [], function(){ tx.executeSql("INSERT INTO MYTABLE values(?)", [s], function() { tx.executeSql("SELECT * FROM MYTABLE ", [], function(transaction, results) { console.log(results.rows.item(0)) }); },function(transaction, error){console.log(error)}) },function(transaction, error){console.log(error)}) }) }) </code></pre> <p>What the DB now returns is simply "a".</p> <p>So my question is how do I serialize a javascript byte array in HTML5 database without resorting to a joined string? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload