Android Open Source - MinerStatus Db Open Helper






From Project

Back to project page MinerStatus.

License

The source code is released under:

Apache License

If you think the Android project MinerStatus listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package me.davidgreene.minerstatus.util;
//from w ww.  j a  va2s. c  o m
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbOpenHelper extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 5;
    private static final String DATABASE_NAME = "minerstatus.db";

    public DbOpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
      db.execSQL("CREATE TABLE miners (miner TEXT PRIMARY KEY, pool TEXT, errors INTEGER)");
      db.execSQL("CREATE TABLE config (key TEXT PRIMARY KEY, value TEXT)");
      db.execSQL("INSERT INTO config (key, value) VALUES ('theme', 'dark')");
      db.execSQL("INSERT INTO config (key, value) VALUES ('show.mtgox', 'true')");
      db.execSQL("CREATE TABLE miner_data (miner TEXT, date_long INTEGER, json TEXT)");
    }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    if (oldVersion == 2){
      db.execSQL("ALTER TABLE miners RENAME TO miners_old");
      db.execSQL("CREATE TABLE miners (miner TEXT PRIMARY KEY, pool TEXT, errors INTEGER)");
      db.execSQL("CREATE TABLE config (key TEXT PRIMARY KEY, value TEXT)");
      ContentValues configValues = new ContentValues();
      configValues.put("key", "theme");
      configValues.put("value", "dark");
      db.insert("config", "", configValues);
      Cursor cursor = db.rawQuery("SELECT miner, pool FROM miners_old", new String[]{});
      while(cursor.moveToNext()){
        ContentValues values = new ContentValues();
        values.put("miner", cursor.getString(0));
        values.put("pool", cursor.getString(1));
        values.put("errors", new Integer(0));
        db.insert("miners", "", values);
      }
      cursor.close();
      db.execSQL("DROP TABLE IF EXISTS miners_old");
      oldVersion = 3;
    }
    if(oldVersion == 3){
      db.execSQL("INSERT INTO config (key, value) VALUES ('show.mtgox', 'true')");
      oldVersion = 4;
    }
    if (oldVersion == 4){
      db.execSQL("CREATE TABLE miner_data (miner TEXT, date_long INTEGER, json TEXT)");
      oldVersion = 5;
    }
  }
}




Java Source Code List

me.davidgreene.minerstatus.AbstractMinerStatusActivity.java
me.davidgreene.minerstatus.AddMinerActivity.java
me.davidgreene.minerstatus.MainMinerActivity.java
me.davidgreene.minerstatus.MinerStatusApp.java
me.davidgreene.minerstatus.OptionsActivity.java
me.davidgreene.minerstatus.ViewMinerActivity.java
me.davidgreene.minerstatus.beans.BitpoolPool.java
me.davidgreene.minerstatus.beans.BitpoolStatus.java
me.davidgreene.minerstatus.beans.BitpoolUser.java
me.davidgreene.minerstatus.beans.BtcMine.java
me.davidgreene.minerstatus.beans.BtcguildPool.java
me.davidgreene.minerstatus.beans.BtcguildStatus.java
me.davidgreene.minerstatus.beans.BtcguildUser.java
me.davidgreene.minerstatus.beans.BtcguildWorker.java
me.davidgreene.minerstatus.beans.DeepbitStatus.java
me.davidgreene.minerstatus.beans.MtGox.java
me.davidgreene.minerstatus.beans.Result.java
me.davidgreene.minerstatus.beans.SlushStatus.java
me.davidgreene.minerstatus.beans.Status.java
me.davidgreene.minerstatus.beans.Ticker.java
me.davidgreene.minerstatus.beans.WorkerStatus.java
me.davidgreene.minerstatus.beans.Worker.java
me.davidgreene.minerstatus.service.ConfigServiceImpl.java
me.davidgreene.minerstatus.service.ConfigService.java
me.davidgreene.minerstatus.service.MinerServiceImpl.java
me.davidgreene.minerstatus.service.MinerService.java
me.davidgreene.minerstatus.service.ThemeServiceImpl.java
me.davidgreene.minerstatus.service.ThemeService.java
me.davidgreene.minerstatus.theme.DarkTheme.java
me.davidgreene.minerstatus.theme.LightTheme.java
me.davidgreene.minerstatus.theme.ThemeFactory.java
me.davidgreene.minerstatus.theme.Theme.java
me.davidgreene.minerstatus.util.AsynchMinerUpdateThread.java
me.davidgreene.minerstatus.util.DbOpenHelper.java
me.davidgreene.minerstatus.util.MinerStatusConstants.java
me.davidgreene.minerstatus.util.StatusObjectFactory.java