Back to project page android-data-persistence.
The source code is released under:
MIT License
If you think the Android project android-data-persistence listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.teamtreehouse.mememaker.database; //w ww . j a va2 s .co m import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.provider.BaseColumns; /** * Created by Evan Anger on 8/17/14. */ public class MemeSQLiteHelper extends SQLiteOpenHelper { private static final String DB_NAME = "memes.db"; private static final int DB_VERSION = 2; //Meme Table functionality public static final String MEMES_TABLE = "MEMES"; public static final String COLUMN_MEME_ASSET = "ASSET"; public static final String COLUMN_MEME_NAME = "NAME"; public static final String COLUMN_MEME_CREATE_DATE = "CREATE_DATE"; private static String CREATE_MEMES = "CREATE TABLE " + MEMES_TABLE + "(" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + COLUMN_MEME_ASSET +" TEXT," + COLUMN_MEME_NAME + " TEXT," + COLUMN_MEME_CREATE_DATE + " INTEGER)"; private static final String ALTER_ADD_CREATE_DATE = "ALTER TABLE " + MEMES_TABLE + " ADD COLUMN " + COLUMN_MEME_CREATE_DATE + " INTEGER"; //Meme Table Annotations functionality public static final String ANNOTATIONS_TABLE = "ANNOTATIONS"; public static final String COLUMN_ANNOTATION_COLOR = "COLOR"; public static final String COLUMN_ANNOTATION_X = "X"; public static final String COLUMN_ANNOTATION_Y = "Y"; public static final String COLUMN_ANNOTATION_TITLE = "TITLE"; public static final String COLUMN_FOREIGN_KEY_MEME = "MEME_ID"; private static final String CREATE_ANNOTATIONS = "CREATE TABLE " + ANNOTATIONS_TABLE + " (" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + COLUMN_ANNOTATION_X + " INTEGER, " + COLUMN_ANNOTATION_Y + " INTEGER, " + COLUMN_ANNOTATION_TITLE + " TEXT, " + COLUMN_ANNOTATION_COLOR + " TEXT, " + COLUMN_FOREIGN_KEY_MEME + " INTEGER, " + "FOREIGN KEY(" + COLUMN_FOREIGN_KEY_MEME + ") REFERENCES MEMES(_ID))"; public MemeSQLiteHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); } @Override public void onCreate(SQLiteDatabase sqLiteDatabase) { sqLiteDatabase.execSQL(CREATE_MEMES); sqLiteDatabase.execSQL(CREATE_ANNOTATIONS); } @Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) { switch (oldVersion) { case 1: sqLiteDatabase.execSQL(ALTER_ADD_CREATE_DATE); } } }