public void onOpen(SQLiteDatabase db) { super.onOpen(db); /* * if (!db.isReadOnly()) { // Enable foreign key constraints * db.execSQL("PRAGMA foreign_keys=ON;"); } */ }
@Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); if (!db.isReadOnly()) { db.execSQL("PRAGMA foreign_keys=ON;"); } }
@Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); // int version = db.getVersion(); // if (BuildConfig.DEBUG) Log.d(LOGCAT, "opening db version: " + version); }
@Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); if (!db.isReadOnly()) { setForeignKeyConstraintsEnabled(db); } mOpenHelperCallbacks.onOpen(mContext, db); }
@Override public void onOpen(SQLiteDatabase db) { // TODO Auto-generated method stub super.onOpen(db); if (!db.isReadOnly()) { // Enable foreign key constraints db.execSQL("PRAGMA foreign_keys=ON;"); } }
@Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); if (!db.isReadOnly()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { db.setForeignKeyConstraintsEnabled(true); } else { db.execSQL("PRAGMA foreign_keys=ON"); } } }
@Override public void onOpen(SQLiteDatabase db) { // TODO Auto-generated method stub super.onOpen(db); db.execSQL(CREATE_TABLE_LIST_OF_SURVEY); db.execSQL(CREATE_TABLE_SURVEY_QUESTION); db.execSQL(CREATE_TABLE_SURVEY_ANSWER); db.execSQL(CREATE_TABLE_FIELD_TABLE); db.execSQL(CREATE_TABLE_QUESTIONNAIRE_FIELD_ASSOCIATION); // db.execSQL(CREATE_QUERY1); }
@Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); // Activation of SQLiteConstraints // db.execSQL("PRAGMA foreign_keys = ON;"); }
@Override public void onOpen(SQLiteDatabase db) { // TODO Auto-generated method stub super.onOpen(db); }
private SQLiteDatabase getDatabaseLocked(boolean writable) { if (mDatabase != null) { if (!mDatabase.isOpen()) { // Darn! The user closed the database by calling mDatabase.close(). mDatabase = null; } else if (!writable || !mDatabase.isReadOnly()) { // The database is already open for business. return mDatabase; } } if (mIsInitializing) { throw new IllegalStateException("getDatabase called recursively"); } SQLiteDatabase db = mDatabase; try { mIsInitializing = true; if (db != null) { if (writable && db.isReadOnly()) { db.reopenReadWrite(); } } else if (mName == null) { db = SQLiteDatabase.create(null); } else { try { if (DEBUG_STRICT_READONLY && !writable) { final String path = mContext.getDatabasePath(mName).getPath(); db = SQLiteDatabase.openDatabase( path, mFactory, SQLiteDatabase.OPEN_READONLY, mErrorHandler); } else { db = mContext.openOrCreateDatabase( mName, mEnableWriteAheadLogging ? Context.MODE_ENABLE_WRITE_AHEAD_LOGGING : 0, mFactory, mErrorHandler); } } catch (SQLiteException ex) { if (writable) { throw ex; } Log.e(TAG, "Couldn't open " + mName + " for writing (will try read-only):", ex); final String path = mContext.getDatabasePath(mName).getPath(); db = SQLiteDatabase.openDatabase( path, mFactory, SQLiteDatabase.OPEN_READONLY, mErrorHandler); } } onConfigure(db); final int version = db.getVersion(); if (version != mNewVersion) { if (db.isReadOnly()) { throw new SQLiteException( "Can't upgrade read-only database from version " + db.getVersion() + " to " + mNewVersion + ": " + mName); } db.beginTransaction(); try { if (version == 0) { onCreate(db); } else { if (version > mNewVersion) { onDowngrade(db, version, mNewVersion); } else { onUpgrade(db, version, mNewVersion); } } db.setVersion(mNewVersion); db.setTransactionSuccessful(); } finally { db.endTransaction(); } } onOpen(db); if (db.isReadOnly()) { Log.w(TAG, "Opened " + mName + " in read-only mode"); } mDatabase = db; return db; } finally { mIsInitializing = false; if (db != null && db != mDatabase) { db.close(); } } }
public void onOpen(SQLiteDatabase sQLiteDatabase) { super.onOpen(sQLiteDatabase); Logger.d(Logger.DATABASE_TAG, "enabling foreign keys"); sQLiteDatabase.execSQL("PRAGMA foreign_keys = true"); }
@Override public void onOpen(SQLiteDatabase db) { logger.d("moguimdb onOpen DB"); super.onOpen(db); // TODO 每次成功打开数据库后首先被执行 }
@Override public void onOpen(SQLiteDatabase db) { // TODO 每次成功打开数据库后首先被执行 super.onOpen(db); }
@Override public void onOpen(SQLiteDatabase db) { // データベースが開かれたときに実行される // これの実装は任意 super.onOpen(db); }
/*Execute this code when the database file is accessed Fires when Activity uses getReadableDatabase or getWriteableDatabase*/ @Override public synchronized void onOpen(SQLiteDatabase db) { super.onOpen(db); }
// 当打开数据库时的回调函数 public void onOpen(SQLiteDatabase db) { super.onOpen(db); Log.i(DB_NAME, "onOpen"); }
@Override public void onOpen(final SQLiteDatabase db) { super.onOpen(db); new AsyncTask<Void, Void, Void>() { private SQLiteStatement getInsertStatementForTable(String table) { if ("state".equals(table)) return db.compileStatement( "INSERT INTO state (state_id, state_abbrev, state_name) VALUES (?, ?, ?)"); else if ("county".equals(table)) return db.compileStatement( "INSERT INTO county (state_id, county_id, county_name) VALUES (?, ?, ?)"); else if ("zone".equals(table)) return db.compileStatement( "INSERT INTO zone (state_id, zone_id, zone_name) VALUES (?, ?, ?)"); else if ("county_zone".equals(table)) return db.compileStatement( "INSERT INTO county_zone (county_state_id, county_id, zone_state_id, zone_id) VALUES (?, ?, ?, ?)"); else if ("database_version".equals(table)) return db.compileStatement( "INSERT INTO database_version (database_version_id, schema_version, last_update_time) VALUES (?, ?, ?)"); else return null; } private SQLiteStatement getUpdateStatementForTable(String table) { if ("state".equals(table)) return db.compileStatement( "UPDATE state SET state_abbrev = ?2, state_name = ?3 WHERE state_id = ?1"); else if ("county".equals(table)) return db.compileStatement( "UPDATE county SET county_name = ?3 WHERE state_id = ?1 AND county_id = ?2"); else if ("zone".equals(table)) return db.compileStatement( "UPDATE zone SET zone_name = ?3 WHERE state_id = ?1 AND zone_id = ?2"); // else if ("county_zone".equals(table)) // return db.compileStatement("UPDATE county_zone SET (county_state_id, county_id, // zone_state_id, zone_id) VALUES (?, ?, ?, ?)"); else if ("database_version".equals(table)) return db.compileStatement( "UPDATE database_version SET schema_version = ?2, last_update_time = ?3 WHERE database_version_id = ?1"); else return null; } private SQLiteStatement getDeleteStatementForTable(String table) { if ("state".equals(table)) return db.compileStatement("DELETE FROM state WHERE state_id = ?"); else if ("county".equals(table)) return db.compileStatement("DELETE FROM county WHERE state_id = ? and county_id = ?"); else if ("zone".equals(table)) return db.compileStatement("DELETE FROM zone WHERE state_id = ? AND zone_id = ?"); else if ("county_zone".equals(table)) return db.compileStatement( "DELETE FROM county_zone WHERE county_state_id = ? AND county_id = ? AND zone_state_id = ? AND zone_id = ?"); else if ("database_version".equals(table)) return db.compileStatement("DELETE FROM database_version WHERE database_version_id = ?"); else return null; } @Override protected Void doInBackground(Void... voids) { HttpURLConnection conn = null; try { String versionArg = ""; Cursor cursor = db.rawQuery("SELECT last_update_time FROM database_version", null); try { if (cursor.moveToFirst()) versionArg = String.format(Locale.US, "&since=%s", Uri.encode(cursor.getString(0))); } finally { cursor.close(); cursor = null; } String urlprefix = "https://captest-1180.appspot.com"; if (BuildConfig.FLAVOR.equals("local")) urlprefix = "http://10.0.2.2:8080"; conn = (HttpURLConnection) new URL( String.format( Locale.US, "%s/data.cgi?schema=%d%s", urlprefix, db.getVersion(), versionArg)) .openConnection(); int status = conn.getResponseCode(); if (status != 200) { if (status == 301 || status == 302) { conn.getInputStream().close(); conn.disconnect(); conn = (HttpURLConnection) new URL(conn.getHeaderField("Location")).openConnection(); status = conn.getResponseCode(); } if (status != 200) { conn.getErrorStream().close(); throw new IOException("Get failed with status code " + status); } } JsonParser parser = new JacksonFactory() .createJsonParser(conn.getInputStream(), Charset.forName("UTF-8")); try { Deque<StreamState> stateDeque = new ArrayDeque<StreamState>(); String table = null; int index = 0; SQLiteStatement stmt = null; db.beginTransaction(); try { do { JsonToken token = parser.nextToken(); switch (token) { case START_OBJECT: if (stateDeque.isEmpty()) stateDeque.push(StreamState.START); break; case END_OBJECT: switch (stateDeque.peek()) { case START: stateDeque.pop(); break; case TABLE: stateDeque.pop(); table = null; break; case ADD: case CHANGE: case REMOVE: if (stmt != null) stmt.close(); stmt = null; stateDeque.pop(); break; } break; case FIELD_NAME: switch (stateDeque.peek()) { case START: table = parser.getCurrentName(); stateDeque.push(StreamState.TABLE); break; case TABLE: if ("added".equals(parser.getCurrentName())) { stmt = getInsertStatementForTable(table); stateDeque.push(StreamState.ADD); } else if ("changed".equals(parser.getCurrentName())) { stmt = getUpdateStatementForTable(table); stateDeque.push(StreamState.CHANGE); } else if ("removed".equals(parser.getCurrentName())) { stmt = getDeleteStatementForTable(table); stateDeque.push(StreamState.REMOVE); } break; } break; case START_ARRAY: switch (stateDeque.peek()) { case ADD: case CHANGE: case REMOVE: stateDeque.push(StreamState.ROW_ARRAY); break; case ROW_ARRAY: stateDeque.push(StreamState.ROW); index = 0; break; } break; case END_ARRAY: switch (stateDeque.peek()) { case ROW: if (stmt != null) stmt.execute(); case ROW_ARRAY: stateDeque.pop(); break; } if (!stateDeque.isEmpty()) { switch (stateDeque.peek()) { case ADD: case CHANGE: case REMOVE: if (stmt != null) stmt.close(); stmt = null; stateDeque.pop(); break; } } break; case VALUE_STRING: switch (stateDeque.peek()) { case ROW: if (stmt != null) stmt.bindString(++index, parser.getText()); break; } break; case VALUE_NUMBER_INT: switch (stateDeque.peek()) { case ROW: if (stmt != null) stmt.bindLong(++index, parser.getLongValue()); break; } break; case VALUE_NUMBER_FLOAT: switch (stateDeque.peek()) { case ROW: if (stmt != null) stmt.bindDouble(++index, parser.getDoubleValue()); break; } break; case VALUE_NULL: switch (stateDeque.peek()) { case ROW: if (stmt != null) stmt.bindNull(++index); break; } break; case VALUE_TRUE: switch (stateDeque.peek()) { case ROW: if (stmt != null) stmt.bindLong(++index, 1); break; } break; case VALUE_FALSE: switch (stateDeque.peek()) { case ROW: if (stmt != null) stmt.bindLong(++index, 0); break; } break; } } while (!stateDeque.isEmpty()); db.setTransactionSuccessful(); } finally { parser.close(); } } finally { db.endTransaction(); } } catch (MalformedURLException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { if (conn != null) conn.disconnect(); db.releaseReference(); } return null; } }.execute(); db.acquireReference(); }
@Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); }
@Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); db.execSQL( "CREATE TABLE IF NOT EXISTS googleeventlist (_id INTEGER PRIMARY KEY ASC , id TEXT)"); }