Android Open Source - taxitwin-app Db Helper






From Project

Back to project page taxitwin-app.

License

The source code is released under:

GNU General Public License

If you think the Android project taxitwin-app 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 kimle.michal.android.taxitwin.db;
//from w  ww  . j  a va 2s  . c  o  m
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper {

    public static final int DATABASE_VERSION = 18;
    public static final String DATABASE = "taxitwin.db";

    //taxitwin table
    private static final String TAXITWIN_TABLE_CREATE
            = "CREATE TABLE " + DbContract.DbEntry.TAXITWIN_TABLE + " ("
            + DbContract.DbEntry._ID + " INTEGER PRIMARY KEY, "
            + DbContract.DbEntry.TAXITWIN_START_POINT_ID_COLUMN + " INTEGER NOT NULL REFERENCES "
            + DbContract.DbEntry.POINT_TABLE + "("
            + DbContract.DbEntry._ID + "), "
            + DbContract.DbEntry.TAXITWIN_END_POINT_ID_COLUMN + " INTEGER NOT NULL REFERENCES "
            + DbContract.DbEntry.POINT_TABLE + "("
            + DbContract.DbEntry._ID + "), "
            + DbContract.DbEntry.TAXITWIN_NAME_COLUMN + " TEXT NOT NULL);";
    private static final String TAXITWIN_TABLE_DROP
            = "DROP TABLE IF EXISTS " + DbContract.DbEntry.TAXITWIN_TABLE + ";";
    private static final String TAXITWIN_TABLE_DELETE
            = "DELETE FROM " + DbContract.DbEntry.TAXITWIN_TABLE + ";";

    //point table
    private static final String POINT_TABLE_CREATE
            = "CREATE TABLE " + DbContract.DbEntry.POINT_TABLE + " ("
            + DbContract.DbEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + DbContract.DbEntry.POINT_LATITUDE_COLUMN + " REAL NOT NULL, "
            + DbContract.DbEntry.POINT_LONGITUDE_COLUMN + " REAL NOT NULL, "
            + DbContract.DbEntry.POINT_TEXTUAL_COLUMN + " TEXT NOT NULL);";
    private static final String POINT_TABLE_DROP
            = "DROP TABLE IF EXISTS " + DbContract.DbEntry.POINT_TABLE + ";";
    private static final String POINT_TABLE_DELETE
            = "DELETE FROM " + DbContract.DbEntry.POINT_TABLE + ";";

    //response table
    private static final String RESPONSE_TABLE_CREATE
            = "CREATE TABLE " + DbContract.DbEntry.RESPONSE_TABLE + " ("
            + DbContract.DbEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + DbContract.DbEntry.RESPONSE_TAXITWIN_ID_COLUMN + " INTEGER NOT NULL REFERENCES "
            + DbContract.DbEntry.TAXITWIN_TABLE + "("
            + DbContract.DbEntry._ID + ") ON DELETE CASCADE);";
    private static final String RESPONSE_TABLE_DROP
            = "DROP TABLE IF EXISTS " + DbContract.DbEntry.RESPONSE_TABLE + ";";
    private static final String RESPONSE_TABLE_DELETE
            = "DELETE FROM " + DbContract.DbEntry.RESPONSE_TABLE + ";";

    //offer table
    private static final String OFFER_TABLE_CREATE
            = "CREATE TABLE " + DbContract.DbEntry.OFFER_TABLE + " ("
            + DbContract.DbEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + DbContract.DbEntry.OFFER_TAXITWIN_ID_COLUMN + " INTEGER NOT NULL REFERENCES "
            + DbContract.DbEntry.TAXITWIN_TABLE + "("
            + DbContract.DbEntry._ID + ") ON DELETE CASCADE, "
            + DbContract.DbEntry.OFFER_PASSENGERS_TOTAL_COLUMN + " INTEGER NOT NULL, "
            + DbContract.DbEntry.OFFER_PASSENGERS_COLUMN + " INTEGER NOT NULL);";
    private static final String OFFER_TABLE_DROP
            = "DROP TABLE IF EXISTS " + DbContract.DbEntry.OFFER_TABLE + ";";
    private static final String OFFER_TABLE_DELETE
            = "DELETE FROM " + DbContract.DbEntry.OFFER_TABLE + ";";

    //ride table
    private static final String RIDE_TABLE_CREATE
            = "CREATE TABLE " + DbContract.DbEntry.RIDE_TABLE + " ("
            + DbContract.DbEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
            + DbContract.DbEntry.RIDE_OFFER_ID_COLUMN + " INTEGER NOT NULL REFERENCES "
            + DbContract.DbEntry.OFFER_TABLE + "("
            + DbContract.DbEntry._ID + ") ON DELETE CASCADE);";
    private static final String RIDE_TABLE_DROP
            = "DROP TABLE IF EXISTS " + DbContract.DbEntry.RIDE_TABLE + ";";
    private static final String RIDE_TABLE_DELETE
            = "DELETE FROM " + DbContract.DbEntry.RIDE_TABLE + ";";

    public DbHelper(Context context) {
        super(context, DATABASE, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(POINT_TABLE_CREATE);
        db.execSQL(TAXITWIN_TABLE_CREATE);
        db.execSQL(RESPONSE_TABLE_CREATE);
        db.execSQL(OFFER_TABLE_CREATE);
        db.execSQL(RIDE_TABLE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        dropTables(db);
        onCreate(db);
    }

    private void dropTables(SQLiteDatabase db) {
        db.execSQL(RIDE_TABLE_DROP);
        db.execSQL(OFFER_TABLE_DROP);
        db.execSQL(RESPONSE_TABLE_DROP);
        db.execSQL(TAXITWIN_TABLE_DROP);
        db.execSQL(POINT_TABLE_DROP);
    }

    public void deleteTables(SQLiteDatabase db) {
        db.execSQL(RIDE_TABLE_DELETE);
        db.execSQL(OFFER_TABLE_DELETE);
        db.execSQL(RESPONSE_TABLE_DELETE);
        db.execSQL(TAXITWIN_TABLE_DELETE);
        db.execSQL(POINT_TABLE_DELETE);
    }

    @Override
    public void onOpen(SQLiteDatabase db) {
        super.onOpen(db);
        if (!db.isReadOnly()) {
            // Enable foreign key constraints
            db.execSQL("PRAGMA foreign_keys=ON;");
        }
    }

    @Override
    public void onConfigure(SQLiteDatabase db) {
        super.onOpen(db);
        if (!db.isReadOnly()) {
            // Enable foreign key constraints
            db.execSQL("PRAGMA foreign_keys=ON;");
        }
    }
}




Java Source Code List

kimle.michal.android.taxitwin.activity.LauncherActivity.java
kimle.michal.android.taxitwin.activity.MainActivity.java
kimle.michal.android.taxitwin.activity.MyTaxiTwinActivity.java
kimle.michal.android.taxitwin.activity.OfferDetailActivity.java
kimle.michal.android.taxitwin.activity.ResponseDetailActivity.java
kimle.michal.android.taxitwin.activity.ResponsesActivity.java
kimle.michal.android.taxitwin.adapter.TaxiTwinPlacesAutoCompleteAdapter.java
kimle.michal.android.taxitwin.application.TaxiTwinApplication.java
kimle.michal.android.taxitwin.contentprovider.TaxiTwinContentProvider.java
kimle.michal.android.taxitwin.db.DbContract.java
kimle.michal.android.taxitwin.db.DbHelper.java
kimle.michal.android.taxitwin.dialog.alert.AddressAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.GPSAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.GooglePlayServicesAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.InternetAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.LeaveTaxiTwinAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.ServicesAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.TaxiTwinAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.alert.TaxiTwinNoLongerAlertDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.GooglePlayServicesErrorDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.OfferErrorDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.PlaceErrorDialogFragment.java
kimle.michal.android.taxitwin.dialog.error.ResponseErrorDialogFragment.java
kimle.michal.android.taxitwin.entity.Place.java
kimle.michal.android.taxitwin.enumerate.UserState.java
kimle.michal.android.taxitwin.fragment.TaxiTwinListFragment.java
kimle.michal.android.taxitwin.fragment.TaxiTwinMapFragment.java
kimle.michal.android.taxitwin.gcm.GcmBroadcastReceiver.java
kimle.michal.android.taxitwin.gcm.GcmConnector.java
kimle.michal.android.taxitwin.gcm.GcmHandler.java
kimle.michal.android.taxitwin.gcm.GcmIntentService.java
kimle.michal.android.taxitwin.popup.SettingsPopup.java
kimle.michal.android.taxitwin.services.ServicesManagement.java
kimle.michal.android.taxitwin.view.TaxiTwinAutoCompleteTextView.java