I am working on creating an app on monaca.
Here (http://docs.monaca.mobi/3.5/ja/sampleapp/tips/storage/ #creating-a-database-sqlite)
I understand how to create a DB with a sample source and save the value, but I am not sure how to create an app with DB.
I'd like to make something that stores the questions and answers in the DB and refers to them, but how should I make it?
I am thinking about Android & iOS.Thank you for your cooperation.
My way of doing this is to create a table when the app is first started and run the INSERT
statement to register the initial data.
Initial data can be written directly in the INSERT
statement or run the INSERT
statement from a file such as the json format.
The initial launch of the app is determined by the value of db.version
, and if it is empty, run db.changeVersion()
to rewrite it to 1.0
.
At that time, you create a table and register the initial data.
You can easily change tables and register additional data when you upgrade your app.
vardb=window.openDatabase("testdb", "", "testdb", 1024*1024);
// Is it your first boot?
if(db.version==""){
db.changeVersion(", "1.0",
function(){
// Table creation/initial data registration
}, function(err){
// Version change failed
}, function(){
// Version Change Successful
});
}
© 2024 OneMinuteCode. All rights reserved.