Android Open Source - SOIAF_RPG Sql Open Helper






From Project

Back to project page SOIAF_RPG.

License

The source code is released under:

GNU General Public License

If you think the Android project SOIAF_RPG 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 de.mroehrl.RPG;
/*from  w  w w. ja va  2 s  .co m*/
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;

public class SqlOpenHelper extends SQLiteOpenHelper {
  
  private static final String DBNAME = "SOIAF_RPG";
  private static final int VERSION   = 1;
  
  public SqlOpenHelper(Context context) {
    super(context, DBNAME, null, VERSION);    
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
    createDatabase(db);
  }

  @Override
  public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
    // TODO Auto-generated method stub
  }
  
  public long insertDefaultCharacter(SQLiteDatabase db) {
    ContentValues values = new ContentValues();
    values.put(DBContract.CharacterEntry.NAME, "No Name");
    values.put(DBContract.CharacterEntry.MONEY, 2000);
    return db.insert(DBContract.CharacterEntry.TABLE_NAME, null, values);
  }
  
  private void createDatabase(SQLiteDatabase db) {
  //  db.execSQL(DBContract.SQL_DELETE_CHARACTER_TABLE);
    db.execSQL(DBContract.SQL_CREATE_CHARACTER_TABLE);
    insertDefaultCharacter(db);    
  }
  
  public final class DBContract {    
    // To prevent someone from accidentally instantiating the contract class,
      // give it an empty constructor.
      public DBContract() {}

      /* Inner class that defines the table contents */
      public abstract class CharacterEntry implements BaseColumns {
          public static final String TABLE_NAME = "Character";
          public static final String ID         = "characterid";
          public static final String NAME       = "name";
          public static final String MONEY      = "money";        
      }

      private static final String VARCHAR_TYPE = " VARCHAR(255)";
      private static final String INTEGER_TYPE = " INT";
      private static final String COMMA_SEP    = ",";
      
      public static final String SQL_CREATE_CHARACTER_TABLE =
          "CREATE TABLE " + CharacterEntry.TABLE_NAME + " (" +
          CharacterEntry.ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL" + COMMA_SEP +
          CharacterEntry.NAME + VARCHAR_TYPE + COMMA_SEP +
          CharacterEntry.MONEY + INTEGER_TYPE + 
          //COMMA_SEP +        
          " )";
      
      
      public static final String SQL_DELETE_CHARACTER_TABLE =
          "DROP TABLE IF EXISTS " + CharacterEntry.TABLE_NAME;
  }  
}




Java Source Code List

de.mroehrl.RPG.RPGCharacter.java
de.mroehrl.RPG.SqlOpenHelper.java
de.mroehrl.soiaf_rpg.CharacterActivity.java
de.mroehrl.soiaf_rpg.CharacterFragment.java
de.mroehrl.soiaf_rpg.CurrencyActivity.java
de.mroehrl.soiaf_rpg.CurrencyFragment.java
de.mroehrl.soiaf_rpg.ItemListActivity.java
de.mroehrl.soiaf_rpg.ItemListFragment.java
de.mroehrl.soiaf_rpg.content.SOIAFContent.java