package jp.gihyo.mitoma.android.lesson2301sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class FriendsOpenHelper extends SQLiteOpenHelper {
    private static final String DB_NAME = "friends.db";
    private static final int DB_VERSION = 2;
    public FriendsOpenHelper(Context context) {

        super(context, DB_NAME, null, DB_VERSION);
    }

    public void onCreate(SQLiteDatabase db) {
        // 初回作成時に呼ばれる
        String sql = "CREATE TABLE friends (" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT," +
                " name TEXT, tel TEXT,memo TEXT)";
        db.execSQL(sql);
        // AUTOINCREMENTの初期値設定
        db.execSQL("INSERT INTO sqlite_sequence (" +
                   "name, seq) VALUES ('friends', 26000)");
    }
    public void onUpgrade(
            SQLiteDatabase db, int oldVersion, int newVersion) {
        // バージョン変更時の処理
        String sql = "DROP TABLE IF EXISTS friends";
        db.execSQL(sql);
        onCreate(db);
    }
}
