android - Alarm and Alarm Template table in clock app -


i little confused approach , , don't understand purpose of this. discovering default desk clock app android 4.4 have noticed weird. in clockdatabasehelper class there several tables created in database.

   // database , table names     static final string database_name = "alarms.db";     static final string old_alarms_table_name = "alarms";     static final string alarms_table_name = "alarm_templates";     static final string instances_table_name = "alarm_instances";     static final string cities_table_name = "selected_cities"; 

so first string clear. second string why named old_alarms , real name of table alarms. why has such name ? , real puprose of this. next , third string has value "alarm_templates" ... why ? word "templates" represents ? why have such name ? instance table current state of alarm ...but still not clear me why can't write directly alarm table. please explain goal of doing stuff ?

 @override     public void onupgrade(sqlitedatabase db, int oldversion, int currentversion) {         logutils.v("upgrading alarms database version "                 + oldversion + " " + currentversion);          if (oldversion <= version_6) {             // these not used in db_version_6, can drop them.             db.execsql("drop table if exists " + instances_table_name + ";");             db.execsql("drop table if exists " + cities_table_name + ";");              // create new alarms table , copy on data             createalarmstable(db);             createinstancetable(db);             createcitiestable(db);              logutils.i("copying old alarms new table");             string[] old_table_columns = {                     "_id",                     "hour",                     "minutes",                     "daysofweek",                     "enabled",                     "vibrate",                     "message",                     "alert",             };             cursor cursor = db.query(old_alarms_table_name, old_table_columns,                     null, null, null, null, null);             calendar currenttime = calendar.getinstance();             while (cursor.movetonext()) {                 alarm alarm = new alarm();                 alarm.id = cursor.getlong(0);                 alarm.hour = cursor.getint(1);                 alarm.minutes = cursor.getint(2);                 alarm.daysofweek = new daysofweek(cursor.getint(3));                 alarm.enabled = cursor.getint(4) == 1;                 alarm.vibrate = cursor.getint(5) == 1;                 alarm.label = cursor.getstring(6);                  string alertstring = cursor.getstring(7);                 if ("silent".equals(alertstring)) {                     alarm.alert = alarm.no_ringtone_uri;                 } else {                     alarm.alert = textutils.isempty(alertstring) ? null : uri.parse(alertstring);                 }                  // save new version of alarm , create alarminstance                 db.insert(alarms_table_name, null, alarm.createcontentvalues(alarm));                 if (alarm.enabled) {                     alarminstance newinstance = alarm.createinstanceafter(currenttime);                     db.insert(instances_table_name, null,                             alarminstance.createcontentvalues(newinstance));                 }             }             cursor.close();              logutils.i("dropping old alarm table");             db.execsql("drop table if exists " + old_alarms_table_name + ";");         }     } 

and here method old_alarms_table_name used - onupgrade copy old table new , never wrote her. please explain happens here.

edit

thanks cl. , during writing post got it.

this updating old database table here code old app

private static class databasehelper extends sqliteopenhelper {     private static final string database_name = "alarms.db";     private static final int database_version = 5;      public databasehelper(context context) {         super(context, database_name, null, database_version);     }      @override     public void oncreate(sqlitedatabase db) {         db.execsql("create table alarms (" +                    "_id integer primary key," +                    "hour integer, " +                    "minutes integer, " +                    "daysofweek integer, " +                    "alarmtime integer, " +                    "enabled integer, " +                    "vibrate integer, " +                    "message text, " +                    "alert text);");          // insert default alarms         string insertme = "insert alarms " +                 "(hour, minutes, daysofweek, alarmtime, enabled, vibrate, message, alert) " +                 "values ";         db.execsql(insertme + "(7, 0, 127, 0, 0, 1, '', '');");         db.execsql(insertme + "(8, 30, 31, 0, 0, 1, '', '');");         db.execsql(insertme + "(9, 00, 0, 0, 0, 1, '', '');");     } 

so here name hardcoded in insert statement. think bad approac , firstly variable of constant values not constant variables. , here sql openhelper nested static class. don't know , maybe wrong .


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -