private VersionCode readSqliteVersionLocked(ISQLiteDatabase db) { try { String versionString = db.simpleQueryForString("select sqlite_version()", null); return VersionCode.parse(versionString); } catch (RuntimeException e) { onError("Failed to read sqlite version", e); throw e; } }
/** * Create a new {@link Index} in the database * * @param indexName name for the Index * @param table the table to create the index on * @param unique true if the index is a unique index on the specified columns * @param properties the columns to create the index on * @return true if the statement executed without error, false otherwise */ protected boolean tryCreateIndex(String indexName, Table table, boolean unique, Property<?>... properties) { if (properties == null || properties.length == 0) { onError(String.format("Cannot create index %s: no properties specified", indexName), null); return false; } StringBuilder sql = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY); sql.append("CREATE "); if (unique) { sql.append("UNIQUE "); } sql.append("INDEX IF NOT EXISTS ").append(indexName).append(" ON ").append(table.getExpression()) .append("("); for (Property<?> p : properties) { sql.append(p.getName()).append(","); } sql.deleteCharAt(sql.length() - 1); sql.append(")"); return tryExecSql(sql.toString()); }
/** * Execute a raw SQL statement * * @param sql the statement to execute * @return true if the statement executed without an error * @see ISQLiteDatabase#execSQL(String) */ public boolean tryExecSql(String sql) { acquireNonExclusiveLock(); try { getDatabase().execSQL(sql); return true; } catch (RuntimeException e) { onError("Failed to execute statement: " + sql, e); return false; } finally { releaseNonExclusiveLock(); } }
/** * Execute a raw SQL statement with optional arguments. The sql string may contain '?' placeholders for the * arguments. * * @param sql the statement to execute * @param bindArgs the arguments to bind to the statement * @return true if the statement executed without an error * @see ISQLiteDatabase#execSQL(String, Object[]) */ public boolean tryExecSql(String sql, Object[] bindArgs) { acquireNonExclusiveLock(); try { getDatabase().execSQL(sql, bindArgs); return true; } catch (RuntimeException e) { onError("Failed to execute statement: " + sql, e); return false; } finally { releaseNonExclusiveLock(); } }
private VersionCode readSqliteVersionLocked(ISQLiteDatabase db) { try { String versionString = db.simpleQueryForString("select sqlite_version()", null); return VersionCode.parse(versionString); } catch (RuntimeException e) { onError("Failed to read sqlite version", e); throw e; } }
/** * Create a new {@link Index} in the database * * @param indexName name for the Index * @param table the table to create the index on * @param unique true if the index is a unique index on the specified columns * @param properties the columns to create the index on * @return true if the statement executed without error, false otherwise */ protected boolean tryCreateIndex(String indexName, Table table, boolean unique, Property<?>... properties) { if (properties == null || properties.length == 0) { onError(String.format("Cannot create index %s: no properties specified", indexName), null); return false; } StringBuilder sql = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY); sql.append("CREATE "); if (unique) { sql.append("UNIQUE "); } sql.append("INDEX IF NOT EXISTS ").append(indexName).append(" ON ").append(table.getExpression()) .append("("); for (Property<?> p : properties) { sql.append(p.getName()).append(","); } sql.deleteCharAt(sql.length() - 1); sql.append(")"); return tryExecSql(sql.toString()); }
/** * Execute a raw SQL statement * * @param sql the statement to execute * @return true if the statement executed without an error * @see ISQLiteDatabase#execSQL(String) */ public boolean tryExecSql(String sql) { acquireNonExclusiveLock(); try { getDatabase().execSQL(sql); return true; } catch (RuntimeException e) { onError("Failed to execute statement: " + sql, e); return false; } finally { releaseNonExclusiveLock(); } }
/** * Execute a raw SQL statement with optional arguments. The sql string may contain '?' placeholders for the * arguments. * * @param sql the statement to execute * @param bindArgs the arguments to bind to the statement * @return true if the statement executed without an error * @see ISQLiteDatabase#execSQL(String, Object[]) */ public boolean tryExecSql(String sql, Object[] bindArgs) { acquireNonExclusiveLock(); try { getDatabase().execSQL(sql, bindArgs); return true; } catch (RuntimeException e) { onError("Failed to execute statement: " + sql, e); return false; } finally { releaseNonExclusiveLock(); } }