Android Open Source - sqlite my S Q Lite Helper






From Project

Back to project page sqlite.

License

The source code is released under:

GNU General Public License

If you think the Android project sqlite 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 edu.cs4730.sqlitedemo;
//from  w  w  w  . j  av  a  2 s .  co  m
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/* 
 * basic class to create/update the database we are using.
 * This is used in our database class. The table name and column
 * names are defined here as Constants, so they can be used else where easily.
 */

public class mySQLiteHelper extends SQLiteOpenHelper {

  public static final String KEY_NAME = "Name";
  public static final String KEY_SCORE = "Score";
  public static final String KEY_ROWID = "_id";   //required field for the cursorAdapter
  private static final String TAG = "DBAdapter";

  private static final String DATABASE_NAME = "myScore.db";
  public static final String DATABASE_TABLE = "HighScore";
  private static final int DATABASE_VERSION = 1;
  
   // Database creation sql statement
  private static final String DATABASE_CREATE =
          "CREATE TABLE HighScore ("+
      KEY_ROWID + " integer PRIMARY KEY autoincrement," +  //this line is required for the cursorAdapter.
      KEY_NAME+" TEXT, "+
      KEY_SCORE+" INTEGER );";
  
  mySQLiteHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }

  @Override
  public void onCreate(SQLiteDatabase db) { 
   //NOTE only called when the database is initial created!
    db.execSQL(DATABASE_CREATE);
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {   
    //Called when the database version changes, Remember the constant from above.
    Log.w(TAG, "Upgrading database from version " + oldVersion 
        + " to "
        + newVersion + ", which will destroy all old data");
    db.execSQL("DROP TABLE IF EXISTS "+DATABASE_TABLE);
    onCreate(db);
  }

}




Java Source Code List

edu.cs4730.lvcursordemo.CntDbAdapter.java
edu.cs4730.lvcursordemo.CntDbAdapter.java
edu.cs4730.lvcursordemo.Country.java
edu.cs4730.lvcursordemo.Country.java
edu.cs4730.lvcursordemo.CustomCursorAdapter.java
edu.cs4730.lvcursordemo.CustomCursorAdapter.java
edu.cs4730.lvcursordemo.ExpListview_Fragment.java
edu.cs4730.lvcursordemo.ExpListview_Fragment.java
edu.cs4730.lvcursordemo.MainActivity.java
edu.cs4730.lvcursordemo.MainActivity.java
edu.cs4730.lvcursordemo.custom_Fragment.java
edu.cs4730.lvcursordemo.custom_Fragment.java
edu.cs4730.lvcursordemo.simple_Fragment.java
edu.cs4730.lvcursordemo.simple_Fragment.java
edu.cs4730.sqlitedemo2.MainActivity.java
edu.cs4730.sqlitedemo2.MainActivity.java
edu.cs4730.sqlitedemo2.loaderDemoFrag.java
edu.cs4730.sqlitedemo2.loaderDemoFrag.java
edu.cs4730.sqlitedemo2.sqlitedemo2Frag.java
edu.cs4730.sqlitedemo2.sqlitedemo2Frag.java
edu.cs4730.sqlitedemo.CursorAdapter_Fragment.java
edu.cs4730.sqlitedemo.CursorAdapter_Fragment.java
edu.cs4730.sqlitedemo.MainActivity.java
edu.cs4730.sqlitedemo.MainActivity.java
edu.cs4730.sqlitedemo.ScoreDatabase.java
edu.cs4730.sqlitedemo.ScoreDatabase.java
edu.cs4730.sqlitedemo.SqliteDemo_Fragment.java
edu.cs4730.sqlitedemo.SqliteDemo_Fragment.java
edu.cs4730.sqlitedemo.myDBContentProvider.java
edu.cs4730.sqlitedemo.myDBContentProvider.java
edu.cs4730.sqlitedemo.mySQLiteHelper.java
edu.cs4730.sqlitedemo.mySQLiteHelper.java