3 import android.content.Context;
\r
4 import android.database.SQLException;
\r
5 import android.database.sqlite.SQLiteDatabase;
\r
6 import android.database.sqlite.SQLiteOpenHelper;
\r
8 import com.jm.PatternList;
\r
9 import com.jm.utility.Debug;
\r
10 import com.jm.utility.JmException;
\r
12 public class DatabaseHelper extends SQLiteOpenHelper {
\r
13 public final static int ENGLISH_ID = 1;
\r
14 public final static int JAPANEASE_ID = 2;
\r
15 private static int langId = -1;
\r
17 private static DatabaseHelper instance = null;
\r
19 public static DatabaseHelper getInstance() {
\r
23 public static void init(Context context) throws JmException {
\r
24 if (instance != null){
\r
27 DatabaseHelper helper = new DatabaseHelper(context);
\r
28 SQLiteDatabase db = helper.getWritableDatabase();
\r
31 count = Dao.getInstance().count(type);
\r
32 Dao.getInstance().start(db);
\r
33 PatternList p = new PatternList();
\r
40 public DatabaseHelper(Context context) {
\r
41 //super(context, "JuggleMaster.db", null, 1);
\r
42 super(context, "JuggleMaster.db", null, 2);
\r
49 public void onCreate(SQLiteDatabase db) {
\r
50 db.beginTransaction();
\r
52 Dao.getInstance().init(db);
\r
53 db.setTransactionSuccessful();
\r
54 } catch (SQLException e) {
\r
55 Debug.d(this, null, e);
\r
58 db.endTransaction();
\r
63 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
\r
65 if (oldVersion == 1 && newVersion == 2) {
\r
66 db.execSQL("ALTER TABLE pattern ADD COLUMN lang integer;");
\r
67 // 既存のデータは、日本語のデータに変換
\r
68 db.execSQL("UPDATE pattern set LANG = " + JAPANEASE_ID + " WHERE TYPE <> 6;");
\r
69 // ただし、マイパターンは、システムの言語に
\r
70 db.execSQL("UPDATE pattern set LANG = " + langId + " WHERE TYPE = 6;");
\r
71 db.execSQL("create index langindex on pattern(lang);");
\r
73 } catch (Exception e) {
\r
74 e.printStackTrace(); // TODO
\r
78 public void setLangId(Context context){
\r
80 String id = context.getString(com.jm.R.string.lang);
\r
82 langId = Integer.valueOf(id).intValue();
\r
84 catch (Exception e){
\r
85 langId = ENGLISH_ID;
\r
90 public int getLangId(){
\r