/* * Copyright (C) 2015 Iasc CHEN * * 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. */ package me.iasc.microduino.bluevoice.db; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class DataBaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "md.db"; private static final int DATABASE_VERSION = 1; public static final String VOICE_CMD_TABLE = "voicecmd"; // Voice Command public static final String C_ID = "id"; public static final String C_CODE = "code"; public static final String C_VOICE = "voice"; public static final String C_NAME = "name"; public static final String CREATE_VOICE_CMD_TABLE = "create table if not exists " + VOICE_CMD_TABLE + " (" + C_ID + " INTEGER PRIMARY KEY asc AUTOINCREMENT, " + C_CODE + " text UNIQUE, " + C_VOICE + " text UNIQUE, " + C_NAME + " text)"; private static DataBaseHelper instance; public static synchronized DataBaseHelper getHelper(Context context) { if (instance == null) instance = new DataBaseHelper(context); return instance; } private DataBaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); if (!db.isReadOnly()) { // Enable foreign key constraints db.execSQL("PRAGMA foreign_keys=ON;"); } } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_VOICE_CMD_TABLE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }