- Common ways to obtain SQLiteException
private void myMethod () {SQLiteException s =
String str;new SQLiteException(str)
new android.database.sqlite.SQLiteException("unknown type: " + value.type)
- Smart code suggestions by Codota
}
String executeForString(final long connectionPtr, final long statementPtr) { return executeStatementOperation(connectionPtr, statementPtr, "execute for string", new StatementOperation<String>() { @Override public String call(final SQLiteStatement statement) throws Exception { if (!statement.step()) { throw new SQLiteException(SQLiteConstants.SQLITE_DONE, "No rows returned from query"); } return statement.columnString(0); } }); }
public static void addFlaggedCountColumn(SQLiteDatabase db) { try { db.execSQL("ALTER TABLE folders ADD flagged_count INTEGER default 0"); } catch (SQLiteException e) { if (!e.getMessage().startsWith("duplicate column name: flagged_count")) { throw e; } } } }
public static void addDeletedColumn(SQLiteDatabase db) { try { db.execSQL("ALTER TABLE messages ADD deleted INTEGER default 0"); } catch (SQLiteException e) { if (!e.toString().startsWith("duplicate column name: deleted")) { throw e; } } } }
synchronized void ensureDatabase() { if (mDb != null && mDb.isOpen()) { return; } // Sometimes retrieving the database fails. We do 2 retries: first without database deletion // and then with deletion. for (int tries = 0; tries < 2; tries++) { try { if (tries > 0) { //delete db and recreate deleteDB(); } mDb = getWritableDatabase(); break; } catch (SQLiteException e) { e.printStackTrace(); } // Wait before retrying. try { Thread.sleep(SLEEP_TIME_MS); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } } if(mDb == null){ return; } createTableIfNotExists(mDb); mDb.setMaximumSize(mMaximumDatabaseSize); }
private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE); long result = DatabaseUtils.longForQuery(checkDB,"SELECT count() FROM sqlite_master WHERE type='table' AND name='table_name'",null); if(result == 0) checkDB = null; }catch(SQLiteException e){ Log.e("", e.getLocalizedMessage()+e.getMessage()+e.getCause()+ Arrays.toString(e.getStackTrace())); } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; }
protected Long updateByCore(final ContentValues entity, final SQLiteDatabase dbCon) { try { final Long id = entity.getAsLong(getPrimaryKeyColumnName()); String whereArgs[] = {id.toString()}; debug("updateByCore %s %s", getTableName(), entity); dbCon.update(getTableName(), entity, "_id = ?", whereArgs); return id; } catch (SQLiteException e2) { error("SQLiteException %s: %s", e2.getMessage(), e2.toString()); return -1L; } }
public SQLiteDatabase openDB(File file) { if (file == null || !file.exists()) { return null; } try { return SQLiteDatabase.openDatabase(file.getAbsolutePath(), null, SQLiteDatabase.OPEN_READWRITE); } catch (SQLiteException e) { e.printStackTrace(); return null; } }
long executeForLong(final long connectionPtr, final long statementPtr) { return executeStatementOperation(connectionPtr, statementPtr, "execute for long", new StatementOperation<Long>() { @Override public Long call(final SQLiteStatement statement) throws Exception { if (!statement.step()) { throw new SQLiteException(SQLiteConstants.SQLITE_DONE, "No rows returned from query"); } return statement.columnLong(0); } }); }
public static void addMessagesThreadingColumns(SQLiteDatabase db) { try { db.execSQL("ALTER TABLE messages ADD thread_root INTEGER"); db.execSQL("ALTER TABLE messages ADD thread_parent INTEGER"); db.execSQL("ALTER TABLE messages ADD normalized_subject_hash INTEGER"); db.execSQL("ALTER TABLE messages ADD empty INTEGER"); } catch (SQLiteException e) { if (!e.getMessage().startsWith("duplicate column name:")) { throw e; } } } }
@Override protected Void doInBackground(Void... voids) { try { shortcutList = AppUtils.getShortcuts(); } catch (SecurityException e) { e.printStackTrace(); } catch (SQLiteException e) { e.printStackTrace(); shortcutList = new ArrayList<ShortcutInfo>(); } return null; }
public static void addPreviewColumn(SQLiteDatabase db) { try { db.execSQL("ALTER TABLE messages ADD preview TEXT"); } catch (SQLiteException e) { if (!e.toString().startsWith("duplicate column name: preview")) { throw e; } } } }
private static Number nativeGetNumber(long windowPtr, int row, int column) { Value value = WINDOW_DATA.get(windowPtr).value(row, column); switch (value.type) { case Cursor.FIELD_TYPE_NULL: case SQLiteConstants.SQLITE_NULL: return 0; case Cursor.FIELD_TYPE_INTEGER: case Cursor.FIELD_TYPE_FLOAT: return (Number) value.value; case Cursor.FIELD_TYPE_STRING: { try { return Double.parseDouble((String) value.value); } catch (NumberFormatException e) { return 0; } } case Cursor.FIELD_TYPE_BLOB: throw new android.database.sqlite.SQLiteException("could not convert "+value); default: throw new android.database.sqlite.SQLiteException("unknown type: "+value.type); } }
public static void db41FoldersAddClassColumns(SQLiteDatabase db) { try { db.execSQL("ALTER TABLE folders ADD integrate INTEGER"); db.execSQL("ALTER TABLE folders ADD top_group INTEGER"); db.execSQL("ALTER TABLE folders ADD poll_class TEXT"); db.execSQL("ALTER TABLE folders ADD push_class TEXT"); db.execSQL("ALTER TABLE folders ADD display_class TEXT"); } catch (SQLiteException e) { if (!e.getMessage().startsWith("duplicate column name:")) { throw e; } } }
/** * 检查数据库是否存在 * @return */ public boolean checkDataBase() { SQLiteDatabase checkDB = null; String dbPath = DB_PATH + DB_NAME; try { checkDB = SQLiteDatabase.openDatabase(dbPath,null,SQLiteDatabase.OPEN_READONLY); } catch (SQLiteException e) { e.printStackTrace(); } finally { if (checkDB != null) { checkDB.close(); } } return checkDB!=null ? true : false; }
@ChromeDevtoolsMethod public JsonRpcResult getDatabaseTableNames(JsonRpcPeer peer, JSONObject params) throws JsonRpcException { GetDatabaseTableNamesRequest request = mObjectMapper.convertValue(params, GetDatabaseTableNamesRequest.class); String databaseId = request.databaseId; DatabaseDescriptorHolder holder = mPeerListener.getDatabaseDescriptorHolder(databaseId); try { GetDatabaseTableNamesResponse response = new GetDatabaseTableNamesResponse(); response.tableNames = holder.driver.getTableNames(holder.descriptor); return response; } catch (SQLiteException e) { throw new JsonRpcException( new JsonRpcError( JsonRpcError.ErrorCode.INVALID_REQUEST, e.toString(), null /* data */)); } }
@Implementation(minSdk = LOLLIPOP) protected static String nativeGetString(long windowPtr, int row, int column) { Value val = WINDOW_DATA.get(windowPtr).value(row, column); if (val.type == Cursor.FIELD_TYPE_BLOB) { throw new android.database.sqlite.SQLiteException("Getting string when column is blob. Row " + row + ", col " + column); } Object value = val.value; return value == null ? null : String.valueOf(value); }
public static void changeThreadingIndexes(SQLiteDatabase db) { try { db.execSQL("DROP INDEX IF EXISTS msg_empty"); db.execSQL("CREATE INDEX IF NOT EXISTS msg_empty ON messages (empty)"); db.execSQL("DROP INDEX IF EXISTS msg_thread_root"); db.execSQL("CREATE INDEX IF NOT EXISTS msg_thread_root ON messages (thread_root)"); db.execSQL("DROP INDEX IF EXISTS msg_thread_parent"); db.execSQL("CREATE INDEX IF NOT EXISTS msg_thread_parent ON messages (thread_parent)"); } catch (SQLiteException e) { if (!e.getMessage().startsWith("duplicate column name:")) { throw e; } } } }
e.printStackTrace(); db.execSQL("create index 'related_idx_pword' on related (pword)"); }catch (SQLiteException e){ e.printStackTrace(); db.execSQL("create index 'related_idx_cword' on related (cword)"); }catch (SQLiteException e){ e.printStackTrace();
Log.e(TAG, "Error reading from catalog: " + e.toString());
@Implementation(minSdk = LOLLIPOP) protected static byte[] nativeGetBlob(long windowPtr, int row, int column) { Value value = WINDOW_DATA.get(windowPtr).value(row, column); switch (value.type) { case Cursor.FIELD_TYPE_NULL: return null; case Cursor.FIELD_TYPE_BLOB: // This matches Android's behavior, which does not match the SQLite spec byte[] blob = (byte[])value.value; return blob == null ? new byte[]{} : blob; case Cursor.FIELD_TYPE_STRING: return ((String)value.value).getBytes(UTF_8); default: throw new android.database.sqlite.SQLiteException("Getting blob when column is non-blob. Row " + row + ", col " + column); } }