@Override public SQLiteStatement call() throws Exception { return connection.prepare(sql); } });
/** * Convenience method that prepares a cached statement for the given SQL. See {@link #prepare(SQLParts, boolean)} * for details. * * @param sql the SQL statement, not null * @return an instance of {@link SQLiteStatement} * @throws SQLiteException if SQLite returns an error, or if the call violates the contract of this class */ public SQLiteStatement prepare(SQLParts sql) throws SQLiteException { return prepare(sql, true); }
@Override public SQLiteStatement call() throws Exception { return connection.prepare(sql); } });
/** * Convenience method that prepares a cached statement for the given SQL. See {@link #prepare(SQLParts, boolean)} * for details. * * @param sql an SQL statement, not null * @return an instance of {@link SQLiteStatement} * @throws SQLiteException if SQLite returns an error, or if the call violates the contract of this class */ public SQLiteStatement prepare(String sql) throws SQLiteException { return prepare(sql, true); }
@Override public SQLiteStatement call() throws Exception { return connection.prepare(sql); } });
@Override public SQLiteStatement call() throws Exception { SQLiteConnection connection = getConnection(connectionPtr); return connection.prepare(sql); } });
/** * Convenience method that prepares a statement for the given String-based SQL. See {@link #prepare(SQLParts, boolean)} * for details. * * @param sql the SQL statement, not null * @param cached if true, the statement handle will be cached by the connection * @return an instance of {@link SQLiteStatement} * @throws SQLiteException if SQLite returns an error, or if the call violates the contract of this class */ public SQLiteStatement prepare(String sql, boolean cached) throws SQLiteException { return prepare(new SQLParts(sql), cached); }
@Override public SQLiteStatement call() throws Exception { SQLiteConnection connection = getConnection(connectionPtr); return connection.prepare(sql); } });
public Iterator<BoundingBox> getBoundingBoxIterator(int msLevel) throws SQLiteException, StreamCorruptedException { // TODO: try to use msn_rtree join instead (may be faster) SQLiteStatement stmt = connection.prepare( "SELECT bounding_box.* FROM bounding_box, spectrum WHERE spectrum.id = bounding_box.first_spectrum_id AND spectrum.ms_level= ?", false); stmt.bind(1, msLevel); return new BoundingBoxIterator( this._spectrumHeaderReader, this._dataEncodingReader, connection, stmt, msLevel ); }
public Iterator<BoundingBox> getBoundingBoxIterator(int msLevel) throws SQLiteException, StreamCorruptedException { // TODO: try to use msn_rtree join instead (may be faster) SQLiteStatement stmt = connection.prepare( "SELECT bounding_box.* FROM bounding_box, spectrum WHERE spectrum.id = bounding_box.first_spectrum_id AND spectrum.ms_level= ?", false); stmt.bind(1, msLevel); return new BoundingBoxIterator( this._spectrumHeaderReader, this._dataEncodingReader, connection, stmt, msLevel ); }
public SQLiteQuery(SQLiteConnection connection, String sqlQuery, boolean cacheStmt) throws SQLiteException { super(); this.queryString = sqlQuery; this.stmt = connection.prepare(sqlQuery, cacheStmt); HashMap<String, Integer> colIdxByColName = new HashMap<String, Integer>(); int nbCols = stmt.columnCount(); for (int colIdx = 0; colIdx < nbCols; colIdx++) { String colName = stmt.getColumnName(colIdx); colIdxByColName.put(colName, colIdx); } this.resultDesc = new SQLiteResultDescriptor(colIdxByColName); }
public SQLiteQuery(SQLiteConnection connection, String sqlQuery, boolean cacheStmt) throws SQLiteException { super(); this.queryString = sqlQuery; this.stmt = connection.prepare(sqlQuery, cacheStmt); HashMap<String, Integer> colIdxByColName = new HashMap<String, Integer>(); int nbCols = stmt.columnCount(); for (int colIdx = 0; colIdx < nbCols; colIdx++) { String colName = stmt.getColumnName(colIdx); colIdxByColName.put(colName, colIdx); } this.resultDesc = new SQLiteResultDescriptor(colIdxByColName); }
private void executeSQLStatement(String sql, Object[] values) throws SQLiteException{ SQLiteStatement stmt = getConnection().prepare(sql); stmt = SQLiteWrapperUtils.bindArguments(stmt, values); while (stmt.step()) { } } }
@Override public void execSQL(String sql, Object[] bindArgs) throws SQLException { Misc.checkNotNullOrEmpty(sql.trim(), "Input SQL"); SQLiteStatement stmt = null; try { stmt = this.getConnection().prepare(sql); stmt = SQLiteWrapperUtils.bindArguments(stmt, bindArgs); while (stmt.step()) { } } catch (SQLiteException e) { throw new SQLException(e); } finally { SQLiteWrapperUtils.disposeQuietly(stmt); } }
/** * Gets a DIA data RunSlice iterator * * @param minParentMz * @param maxParentMz * @return the RunSlice iterator * @throws SQLiteException * @throws StreamCorruptedException */ public Iterator<RunSlice> getLcMsnRunSliceIterator(double minParentMz, double maxParentMz) throws SQLiteException, StreamCorruptedException { // First pass to load the index final SQLiteStatement fakeStmt = this.connection.prepare("SELECT data FROM bounding_box", false); while (fakeStmt.step()) { } fakeStmt.dispose(); return new LcMsnRunSliceIterator(this, connection, minParentMz, maxParentMz); }
/** * Gets a DIA data RunSlice iterator * * @param minParentMz * @param maxParentMz * @return the RunSlice iterator * @throws SQLiteException * @throws StreamCorruptedException */ public Iterator<RunSlice> getLcMsnRunSliceIterator(double minParentMz, double maxParentMz) throws SQLiteException, StreamCorruptedException { // First pass to load the index final SQLiteStatement fakeStmt = this.connection.prepare("SELECT data FROM bounding_box", false); while (fakeStmt.step()) { } fakeStmt.dispose(); return new LcMsnRunSliceIterator(this, connection, minParentMz, maxParentMz); }
/** * Utility method to run the query on the db and return the value in the * first column of the first row. */ public static int intForQuery(SQLiteConnection conn, String query, Object[] bindArgs) throws SQLiteException { SQLiteStatement stmt = null; try { stmt = bindArguments(conn.prepare(query), bindArgs); if (stmt.step()) { return stmt.columnInt(0); } else { throw new IllegalStateException("query failed to return any result: " + query); } } finally { SQLiteWrapperUtils.disposeQuietly(stmt); } }
/** * Gets a RunSlice iterator. * * @return the RunSlice iterator */ public Observable<RunSlice> getLcMsRunSliceStream() { return Observable.create(subscriber -> { SQLiteJob<Void> sqliteJob = SQLiteObservableJob.buildSQLiteJob( subscriber, connection -> { // First pass to load the index final SQLiteStatement fakeStmt = connection.prepare("SELECT * FROM bounding_box", false); while (fakeStmt.step()) {} fakeStmt.dispose(); SQLiteObservableJob.observeIterator( subscriber, new LcMsRunSliceIterator(this, connection) ); return null; }); queue.execute(sqliteJob); }); }
SQLiteConnection db = new SQLiteConnection(new File("/tmp/database")); db.open(true); ... SQLiteStatement st = db.prepare("SELECT order_id FROM orders WHERE quantity >= ?"); try { st.bind(1, minimumQuantity); while (st.step()) { orders.add(st.columnLong(0)); } } finally { st.dispose(); } ... db.dispose();
/** * Gets the mz range. * * @param msLevel * the ms level * @return runSlice min mz and runSlice max mz * @throws SQLiteException * the sQ lite exception */ public static int[] getMzRange(int msLevel, SQLiteConnection connection) throws SQLiteException { final SQLiteStatement stmt = connection.prepare("SELECT min(begin_mz), max(end_mz) FROM run_slice WHERE ms_level=?"); stmt.bind(1, msLevel); stmt.step(); final int minMz = stmt.columnInt(0); final int maxMz = stmt.columnInt(1); stmt.dispose(); final int[] mzRange = { minMz, maxMz }; return mzRange; }