Back to project page GuildViewerApp2.
The source code is released under:
Apache License
If you think the Android project GuildViewerApp2 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.skywomantechnology.app.guildviewer.data; //from www. ja v a 2 s . c o m /* * Guild Viewer is an Android app that allows users to view news feeds and news feed details * on a mobile device and while not logged into the game servers. * * Copyright 2014 Sky Woman Technology LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import com.skywomantechnology.app.guildviewer.Constants; import com.skywomantechnology.app.guildviewer.data.GuildViewerContract.GuildEntry; import com.skywomantechnology.app.guildviewer.data.GuildViewerContract.ItemEntry; import com.skywomantechnology.app.guildviewer.data.GuildViewerContract.MemberEntry; import com.skywomantechnology.app.guildviewer.data.GuildViewerContract.NewsEntry; /** * This is a helper for the SQLite database used to store local information */ public class GuildViewerDbHelper extends SQLiteOpenHelper { public GuildViewerDbHelper(Context context) { super(context, Constants.DATABASE_NAME, null, Constants.DATABASE_VERSION); } /** * create the database tables when creating a new database * * @param sqLiteDatabase database we are working with */ @Override public void onCreate(SQLiteDatabase sqLiteDatabase) { final String SQL_CREATE_NEWS_TABLE = "CREATE TABLE " + NewsEntry.TABLE_NAME + " (" + NewsEntry._ID + " INTEGER PRIMARY KEY," + NewsEntry.COLUMN_TYPE + " TEXT NOT NULL, " + NewsEntry.COLUMN_TIMESTAMP + " REAL NOT NULL, " + NewsEntry.COLUMN_GUILD + " TEXT NOT NULL COLLATE NOCASE, " + NewsEntry.COLUMN_REGION + " TEXT NOT NULL COLLATE NOCASE, " + NewsEntry.COLUMN_REALM + " TEXT NOT NULL COLLATE NOCASE, " + NewsEntry.COLUMN_CHARACTER + " TEXT, " + NewsEntry.COLUMN_CHARACTER_ICON + " TEXT, " + NewsEntry.COLUMN_ITEM_ID + " TEXT, " + NewsEntry.COLUMN_ITEM_NAME + " TEXT, " + NewsEntry.COLUMN_ITEM_ICON + " TEXT, " + NewsEntry.COLUMN_ITEM_DESCRIPTION + " TEXT, " + NewsEntry.COLUMN_ACHIEVEMENT_TITLE + " TEXT, " + NewsEntry.COLUMN_ACHIEVEMENT_DESCRIPTION + " TEXT, " + NewsEntry.COLUMN_ACHIEVEMENT_ICON + " TEXT " + " );"; sqLiteDatabase.execSQL(SQL_CREATE_NEWS_TABLE); final String SQL_CREATE_NEWS_ITEM_TABLE = "CREATE TABLE " + ItemEntry.TABLE_NAME + " (" + ItemEntry._ID + " INTEGER PRIMARY KEY," + ItemEntry.COLUMN_ITEM_ID + " TEXT UNIQUE NOT NULL, " + ItemEntry.COLUMN_NAME + " TEXT NOT NULL, " + ItemEntry.COLUMN_DESCRIPTION + " TEXT, " + ItemEntry.COLUMN_ICON + " TEXT, " + "UNIQUE (" + ItemEntry.COLUMN_ITEM_ID +") ON CONFLICT REPLACE"+ " );"; sqLiteDatabase.execSQL(SQL_CREATE_NEWS_ITEM_TABLE); final String SQL_CREATE_GUILD_TABLE = "CREATE TABLE " + GuildEntry.TABLE_NAME + " (" + GuildEntry._ID + " INTEGER PRIMARY KEY," + GuildEntry.COLUMN_NAME + " TEXT NOT NULL, " + GuildEntry.COLUMN_REGION + " TEXT NOT NULL COLLATE NOCASE, " + GuildEntry.COLUMN_REALM + " TEXT NOT NULL COLLATE NOCASE, " + GuildEntry.COLUMN_LAST_MODIFIED + " REAL NOT NULL, " + GuildEntry.COLUMN_BATTLEGROUP + " TEXT, " + GuildEntry.COLUMN_LEVEL + " INTEGER, " + GuildEntry.COLUMN_SIDE + " TEXT, " + GuildEntry.COLUMN_POINTS + " INTEGER " + " );"; sqLiteDatabase.execSQL(SQL_CREATE_GUILD_TABLE); final String SQL_CREATE_MEMBERS_TABLE = "CREATE TABLE " + MemberEntry.TABLE_NAME + " (" + MemberEntry._ID + " INTEGER PRIMARY KEY," + MemberEntry.COLUMN_NAME + " TEXT UNIQUE NOT NULL, " + MemberEntry.COLUMN_GUILD_ID + " INTEGER NOT NULL, " + MemberEntry.COLUMN_LEVEL + " INTEGER, " + MemberEntry.COLUMN_GENDER + " TEXT, " + MemberEntry.COLUMN_RACE + " TEXT, " + MemberEntry.COLUMN_CLASS + " TEXT, " + MemberEntry.COLUMN_SIDE + " TEXT, " + MemberEntry.COLUMN_RANK + " INTEGER, " + MemberEntry.COLUMN_POINTS + " INTEGER, " + MemberEntry.COLUMN_THUMBNAIL + " TEXT, " + "UNIQUE (" + MemberEntry.COLUMN_NAME + ") ON CONFLICT REPLACE" + " );"; sqLiteDatabase.execSQL(SQL_CREATE_MEMBERS_TABLE); } /** * delete the old tables and create new ones if upgrading the database to a new version * * @param sqLiteDatabase database we are working with * @param oldVersion previous version number * @param newVersion new version number for comparison */ @Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) { // This database is only a cache for online data, so its upgrade policy is // to simply to discard the data and start over sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + NewsEntry.TABLE_NAME); sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + ItemEntry.TABLE_NAME); sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + GuildEntry.TABLE_NAME); sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + MemberEntry.TABLE_NAME); onCreate(sqLiteDatabase); } }