package com.ysvideo.zhibo.app.db;
|
|
import android.content.Context;
|
import android.database.Cursor;
|
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteOpenHelper;
|
import android.util.Log;
|
|
public class MySQLiteOpenHelper extends SQLiteOpenHelper {
|
|
private static final String TAG = "MySQLiteOpenHelper";
|
|
/**
|
* 数据库名称
|
*/
|
private static final String DATABASE_NAME = "zhibo.db";
|
|
/**
|
* 数据库版本
|
*/
|
private static int DATABASE_VERSION = 3;
|
|
public MySQLiteOpenHelper(Context context) {
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
Log.i(TAG, "MySQLiteOpenHelper");
|
}
|
|
@Override
|
public void onCreate(SQLiteDatabase db) {
|
Log.i(TAG, "onCreate");
|
WatchHistoryTable.createTables(db);
|
}
|
|
//原来的数据库表重命名
|
public static final String TEMP_SQL_CREATE_TABLE_SUBSCRIBE = "alter table " + WatchHistoryTable.TABLE_NAME + " rename to temp_" + WatchHistoryTable.TABLE_NAME;
|
public static final String TEMP_SQL_ADD_LINE = "ALTER TABLE " + WatchHistoryTable.TABLE_NAME + " ADD column " + WatchHistoryTable.VIDEO_RESOURCE_ID + " TEXT";
|
|
public static final String INSERT_SUBSCRIBE = "select insert into " + WatchHistoryTable.TABLE_NAME + " from temp_" + WatchHistoryTable.TABLE_NAME;
|
public static final String DROP_TEMP_SUBSCRIBE = "drop table if exists temp_" + WatchHistoryTable.TABLE_NAME;
|
public static final String DROP_TEMP_SUBSCRIBE1 = "drop table if exists " + WatchHistoryTable.TABLE_NAME;
|
|
@Override
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
Log.i("mResult", "onUpgrade");
|
for (int i = oldVersion; i <= newVersion; i++) {
|
switch (i) {
|
case 2: {
|
Log.i(TAG, "onUpgrade创建新表" + newVersion);
|
// MessageTable.createTables(db);
|
}
|
break;
|
case 3: {
|
Log.i("mResult", "onUpgrade" + newVersion);
|
db.execSQL("alter table " + WatchHistoryTable.TABLE_NAME + " add column " + WatchHistoryTable.VIDEO_RESOURCE + " TEXT");
|
db.execSQL("alter table " + WatchHistoryTable.TABLE_NAME + " add column " + WatchHistoryTable.VIDEO_RESOURCE_ID + " TEXT");
|
Cursor cursor = db.query(WatchHistoryTable.TABLE_NAME, null,
|
WatchHistoryTable.VIDEO_ID + " = ? ",
|
new String[]{"1090602"}, null, null, null);
|
Log.i("mResult", "表的列数有:" + cursor.getColumnCount());
|
}
|
break;
|
case 4: {
|
|
}
|
break;
|
default:
|
break;
|
}
|
}
|
}
|
|
|
}
|