mercredi 27 avril 2016

Does my sqlite coding can be consider global?

Below is my sqlite coding at app.js file using ionic. So you would know what is on top of my coding. I just won't include it here. Look at my sqlite query, is it consider as global? i want to do some controller coding down there later outside from run.(function($ionicPlatform, $cordovaSQLite)..

So i need to create my db first and create table on it. It it correct or i'm doing it wrong?

p/s: i'm planning to create Todo Application and try to learn from Nic Raboy tutorial. However he's doing shipping an app with pre-populated database. So i am not going to follow him completely because i want to create my new DB.

      // Dont remove this line unless you know what you are doing. It stops the viewport
  // from snapping when text inputs are focused. Ionic handles this internally for
  // a much nicer keyboard experience.
  cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
  StatusBar.styleDefault();
}


if(window.cordova){

    db = $cordovaSQLite.openDB({name: "app.db"}); //device
}
else{

    db = window.openDatabase("app.db", '1', 'app', 1024 * 1024 * 100);

}
db.transaction(queryDB);

function queryDB(tx){

    tx.executeSql("CREATE TABLE IF NOT EXIST tblCategories(id integer primary key, category_name text)");
    tx.executeSql("CREATE TABLE IF NOT EXIST tblTodoLists(id integer primary key, category_id integer, todo_list_name text)");
    tx.executeSql("CREATE TABLE IF NOT EXIST tblTodoListsItems(id integer primary key, todo_list_id integer, todo_list_item_name text)");
    tx.executeSql("INSERT INTO tblCategories (category_name) VALUES (?)", ["Academic"]);
    tx.executeSql("INSERT INTO tblCategories (category_name) VALUES (?)", ["Subject"]);
    tx.executeSql("INSERT INTO tblCategories (category_name) VALUES (?)", ["Syllabus"]);

}

Aucun commentaire:

Enregistrer un commentaire