Android Open Source - LearningAndroid2edYamba2 Db Helper






From Project

Back to project page LearningAndroid2edYamba2.

License

The source code is released under:

Apache License

If you think the Android project LearningAndroid2edYamba2 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 com.marakana.android.yamba;
/*w w w .j  av  a  2s .  c o m*/
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DbHelper extends SQLiteOpenHelper {
  private static final String TAG = DbHelper.class.getSimpleName();

  public DbHelper(Context context) {
    super(context, StatusContract.DB_NAME, null, StatusContract.DB_VERSION);
  }

  // Called only once first time we create the database
  @Override
  public void onCreate(SQLiteDatabase db) {
    String sql = String
        .format("create table %s (%s int primary key, %s text, %s text, %s int)",
            StatusContract.TABLE, StatusContract.Column.ID,
            StatusContract.Column.USER,
            StatusContract.Column.MESSAGE,
            StatusContract.Column.CREATED_AT);
    Log.d(TAG, "onCreate with SQL: "+sql);
    db.execSQL(sql);
  }

  // Gets called whenever existing version != new version, i.e. schema changed
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // Typically you do ALTER TABLE ...
    db.execSQL("drop table if exists " + StatusContract.TABLE);
    onCreate(db);
  }

}




Java Source Code List

com.marakana.android.yamba.BootReceiver.java
com.marakana.android.yamba.DbHelper.java
com.marakana.android.yamba.DetailsActivity.java
com.marakana.android.yamba.DetailsFragment.java
com.marakana.android.yamba.FreshnessView.java
com.marakana.android.yamba.MainActivity.java
com.marakana.android.yamba.NotificationReceiver.java
com.marakana.android.yamba.RefreshService.java
com.marakana.android.yamba.SettingsActivity.java
com.marakana.android.yamba.SettingsFragment.java
com.marakana.android.yamba.StatusActivity.java
com.marakana.android.yamba.StatusContract.java
com.marakana.android.yamba.StatusFragment.java
com.marakana.android.yamba.StatusProvider.java
com.marakana.android.yamba.SubActivity.java
com.marakana.android.yamba.TimelineFragment.java
com.marakana.android.yamba.YambaWidget.java