| | |
| | | import android.util.Pair; |
| | | |
| | | import com.basic.security.base.BaseApplication; |
| | | import com.basic.security.model.Log; |
| | | import com.basic.security.model.Setting; |
| | | import com.basic.security.utils.Constants; |
| | | |
| | |
| | | public static final Lock databaseExecSqlLock = new ReentrantLock(); |
| | | public static Map<String, SQLiteDatabase> databaseMap = new HashMap<>(); |
| | | public static Class[] tableClasses = new Class[] { |
| | | Setting.class |
| | | Setting.class, |
| | | Log.class |
| | | }; |
| | | public static SQLiteDatabase getDatabase() { |
| | | public static SQLiteDatabase getDatabase() {// |
| | | return getDatabase(Constants.databaseName); |
| | | } |
| | | |
| | | public static void intiTables() { |
| | | public static void intiTables() {// |
| | | for (Class tableClass : tableClasses) { |
| | | String table = tableClass.getSimpleName(); |
| | | Map<String, String> columns = new HashMap<>(); |
| | |
| | | |
| | | |
| | | DatabaseManager.execSQL("CREATE TABLE IF NOT EXISTS alarm (\"matchPersonListStr\" TEXT, property TEXT, \"alarmLargePicture\" TEXT,\"alarmPerson\" TEXT,\"alarmPicture\" TEXT,\"alarmVideo\" TEXT,\"alarmTime\" TEXT,\"alarmAddress\" TEXT,\"alarmType\" TEXT,\"id\" TEXT, \"createTime\" TEXT, \"closeAlarm\" TEXT, \"mute\" TEXT, PRIMARY KEY(id))"); |
| | | try { |
| | | DatabaseManager.execSQL("ALTER TABLE alarm ADD COLUMN imgKey text"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | DatabaseManager.execSQL("ALTER TABLE alarm ADD COLUMN indeviceid text"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | DatabaseManager.execSQL("ALTER TABLE alarm ADD COLUMN videoReqNum text"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | DatabaseManager.execSQL("ALTER TABLE alarm ADD COLUMN picDate text"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | DatabaseManager.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS idx_alarm ON alarm(id)"); |
| | | // DatabaseManager.execSQL("CREATE TABLE IF NOT EXISTS setting (\"id\" TEXT, \"name\" TEXT, PRIMARY KEY(id))"); |
| | | // DatabaseManager.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS idx_setting ON setting (id)"); |
| | | } |
| | | |
| | | public static SQLiteDatabase getDatabase(String databaseName) { |
| | | public static SQLiteDatabase getDatabase(String databaseName) {// |
| | | SQLiteDatabase database = databaseMap.get(databaseName); |
| | | try { |
| | | databaseLock.lock(); |
| | |
| | | } |
| | | } |
| | | |
| | | private static void initTableColumnNames() { |
| | | private static void initTableColumnNames() {// |
| | | SQLiteDatabase mDataBase = DatabaseManager.getDatabase(); |
| | | Cursor c = mDataBase.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null); |
| | | List<String> tableNameList = new ArrayList<>(); |