You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug in localStorage when editing table.data directly #774
I created a database with alasql and applied my desired testing data with it by mydb.tables.mytable.data perfectly. However, something strange exists when I try to store it with localStorage
providing the javascript here :
alasql('CREATE localStorage DATABASE IF NOT EXISTS lsdb');alasql('ATTACH localStorage DATABASE lsdb AS db');vardb=alasql.Database('db');db.exec('CREATE TABLE IF NOT EXISTS db_01 (foo STRING)');db.tables.db_01.data=[{foo: "text_foo"}];document.getElementById('output').innerHTML+=JSON.stringify(db.tables.db_01.data)+'<br/>';document.getElementById('output').innerHTML+=localStorage.getItem('lsdb.db_01')+'<br/>';document.getElementById('output').innerHTML+=JSON.stringify(db.exec('SELECT * FROM db_01'))+'<br/>';document.getElementById('output').innerHTML+=JSON.stringify(db.tables.db_01.data)+'<br/>';
Attached is a full HTML page to reproduce the problem, but with a extension .txt since github don't support HTML uploading alasql_localStorage_bug.txt
EDIT: PS: currently I can only do things properly by creating a normal DATABASE and then save it to localStorage by JSON.stringify(db.tables.db_01.data)
I have checked out codes in 92localstorage and found that the problem may be caused by the fact that the localStorage engine try to put and get data directly into and from localStorage, hence the traditional way to access all data in the table cannot be used. May be we have to keep tracking the data array by using the javascriptproxy but it is not yet widely supported, or try to provide a setData(data) and getData(data) for all tables, and specify its destination array for tables using localStorage to the localStorage entries directly, like below:
functionsetData(ItemKey,columns,data,identities){try{varobj=JSON.parse(localStorage.getItem(ItemKey));obj.columns=columns||obj.columns;obj.data=data||obj.data;obj.identities=identities||obj.identities;localStorage.setItem(ItemKey,JSON.stringify(obj));}catch(err){returnfalse;}returntrue;}functiongetData(ItemKey){returnJSON.parse(localStorage.getItem(ItemKey));}// access tables[table].data by getData(ItemKey).data
What do you think? I don't know much about alasql so I am not going to touch the underlying codes in it, but I really hope these sample codes can help you in solving this bug out.
try to provide a setData(data) and getData(data) for all tables, and specify its destination array for tables using localStorage to the localStorage entries directly
I like the idea of setData but dont really feel confident about the getData that basically replaces "select * from XXXX" - inputs?
Activity
mathiasrw commentedon Oct 24, 2016
Thanks for taking the time to identify this...
michaellee8 commentedon Nov 2, 2016
Any following action on this issue?
michaellee8 commentedon Nov 2, 2016
I have checked out codes in 92localstorage and found that the problem may be caused by the fact that the
localStorageengine try to put and get data directly into and fromlocalStorage, hence the traditional way to access all data in the table cannot be used. May be we have to keep tracking thedataarray by using thejavascriptproxybut it is not yet widely supported, or try to provide asetData(data)andgetData(data)for all tables, and specify its destination array for tables usinglocalStorageto thelocalStorageentries directly, like below:What do you think? I don't know much about
alasqlso I am not going to touch the underlying codes in it, but I really hope these sample codes can help you in solving this bug out.mathiasrw commentedon Nov 3, 2016
This is awesome - thanks ! I will digg down into this next time I get some time :)
michaellee8 commentedon Nov 7, 2016
Well, sir, may I get your solved code then? I just found the last commit on
developbranch is 12 days ago, did you push it?mathiasrw commentedon Nov 8, 2016
Nope - its not working yet...
I like the idea of
setDatabut dont really feel confident about thegetDatathat basically replaces "select * from XXXX" - inputs?