开发者

what is html5 localstorage db scope?

1.what is the scope of the db?

2.when it's destroyed?

3.how to check if the db exist?

var db = window.openDatabase("Database", "1.0", "MyApp", 900000);

db.transaction(populateDB, errorCB, successCB);
function populateDB(t开发者_开发技巧x) {
     tx.executeSql('DROP TABLE IF EXISTS PRICE2');
     tx.executeSql('CREATE TABLE IF NOT EXISTS PRICE2 (id ,P2_ID,P2_1,P2_2,P2_3,P2_Title,P2_Type,P2_ToType,P2_Up,P2_UpType,PP2_PriceTo,PP2_PriceUp,image)');

     var theResults = vData.results;
      for(var i=1 ; i < theResults.length ; i++){
          tx.executeSql('INSERT INTO PRICE2 (id ,P2_ID,P2_1,P2_2,P2_3,P2_Title,P2_Type,P2_ToType,P2_Up,P2_UpType,PP2_PriceTo,PP2_PriceUp,image) VALUES (' + theResults[i].ID + ', "' + theResults[i].P2_ID + '", "' + theResults[i].P2_1 + '", "' + theResults[i].P2_2 +'", "' + theResults[i].P2_3 +'", "' + theResults[i].P2_Title +'", "' + theResults[i].P2_Type +'", "' + theResults[i].P2_ToType +'", "' + theResults[i].P2_Up +'", "' + theResults[i].P2_UpType +'", "' + theResults[i].PP2_PriceTo +'", "' + theResults[i].PP2_PriceUp +'", "' + theResults[i].image +'")');
      }
}

// Transaction error callback
//
function errorCB(tx, err) {
    alert("Error processing SQL: "+err);
}


i have worked with websql. Here are the answers..

Q - what is the scope of the db?

A - i assume from 'scope' you mean where is the db accessible. For your extension if you create the db in background.html, it will only be accessible in background.html. You can the use other techniques to access your db from other pages of the ext/app like message passing API and chrome.extension.getBackgroundPage (recomended).

Q - when it's destroyed?

A - It will be destroyed on app/ext uninstall/reinstall. NOTE: updating the ext/app will not have any effect on the db.

Q - how to check if the db exist?

A - from what i know, there is no need to 'check'. just call the window.openDatabase if the db does not exist, it will create it and if it does exist, it will skip the creating part and add the value to db var.

EDIT: I also found it frustrating to not be able to find answers to such basic questions. i ended up asking people at IRC when twitter/google groups/forums/html5rocks.com comments failed... :P i find IRC to be the last and almost always a successful resort for quick, on-the-spot answers and not having to wait for an answer in a forum site :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜