private ByteBuffer buffer(int len) throws IOException, SQLiteException { DirectBuffer buffer = getBuffer(); ByteBuffer data = buffer.data(); if (data.remaining() < len) { DirectBuffer newBuffer = null; try { newBuffer = myController.allocateBuffer(buffer.getCapacity() + len); } catch (IOException e) { dispose(); throw e; } ByteBuffer newData = newBuffer.data(); data.flip(); newData.put(data); myController.freeBuffer(buffer); data = newData; myBuffer = newBuffer; assert data.remaining() >= len : data.capacity(); } return data; }
/** * Disposes this instance, making it unusable and freeing the resources. If the array table is cached, * then it is unbound from values (emptied) and returned to the cache. If the array table is not cached, * it is deleted from the database. * <p/> * This method is partially thread-safe. When called not from the confining thread, the exception will not be * thrown, but the method will do nothing. * <p/> * Calling <code>dispose()</code> second time has no effect. * <p/> * Calling {@link #bind} after instance has been disposed would result in exception. */ public void dispose() { if (myHandle == null) return; SQLiteController controller = myController; try { controller.validate(); } catch (SQLiteException e) { Internal.recoverableError(this, "invalid dispose: " + e, true); return; } Internal.logFine(this, "disposing"); controller.dispose(this); myHandle = null; myController = SQLiteController.getDisposed(myController); myDisposed = true; }
/** * Repositions BLOB to another row in the table. It should be quickier that closing the blob and opening another one. * * @param rowid row id to move to - it must exist and contain data * @throws SQLiteException if SQLite returns an error, or if the call violates the contract of this class * @see <a href="http://www.sqlite.org/c3ref/blob_reopen.html">sqlite3_blob_reopen</a> */ public void reopen(long rowid) throws SQLiteException { myController.validate(); if (Internal.isFineLogging()) Internal.logFine(this, "reopen[" + rowid + "]"); int rc = _SQLiteSwigged.sqlite3_blob_reopen(handle(), rowid); myController.throwResult(rc, "reopen", this); }
/** * Dispose this backup instance and, if <code>disposeDestination</code> is true, dispose the connection to * the destination database as well. * <p/> * You might want to pass <code>false</code> to this method to subsequently call {@link #getDestinationConnection()} * and perform any actions on the fresh backup of the database, then dispose it yourself. * * @param disposeDestination if true, connection to the destination database will be disposed */ public void dispose(boolean disposeDestination) { try { mySourceController.validate(); myDestinationController.validate(); } catch (SQLiteException e) { Internal.recoverableError(this, "invalid dispose: " + e, true); return; } Internal.logFine(this, "disposing"); SWIGTYPE_p_sqlite3_backup handle = myHandle; if (handle != null) { _SQLiteSwigged.sqlite3_backup_finish(handle); myHandle = null; mySourceController = SQLiteController.getDisposed(mySourceController); myDestinationController = SQLiteController.getDisposed(myDestinationController); } if (disposeDestination) { myDestination.dispose(); } }
/** * Disposes this blob and frees allocated resources. * <p> * After blob is disposed, it is no longer usable and holds no references to connection * or sqlite db. */ public void dispose() { if (myHandle == null) return; try { myController.validate(); } catch (SQLiteException e) { Internal.recoverableError(this, "invalid dispose: " + e, true); return; } Internal.logFine(this, "disposing"); myController.dispose(this); // clear may be called from dispose() too clear(); }
myController.validate(); SWIGTYPE_p_sqlite3_stmt handle = handle(); checkColumn(column, handle, true); if (Internal.isFineLogging()) Internal.logFine(this, "columnStream(" + column + ")"); _SQLiteManual sqlite = myController.getSQLiteManual(); ByteBuffer buffer = sqlite.wrapper_column_buffer(handle, column); myController.throwResult(sqlite.getLastReturnCode(), "columnStream", this); if (buffer == null) return null;
/** * Returns the total number of pages in the source database. * * @return total number of pages to back up * @throws SQLiteException if called from a different thread or if source or destination connection are disposed * @see <a href="http://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish">SQLite Online Backup API</a> */ public int getPageCount() throws SQLiteException { mySourceController.validate(); myDestinationController.validate(); SWIGTYPE_p_sqlite3_backup handle = handle(); return _SQLiteSwigged.sqlite3_backup_pagecount(handle); }
myController.validate(); if (buffer == null || length <= 0 || offset < 0 || offset + length > buffer.length) { assert false; ProgressHandler ph = prepareStep(); try { _SQLiteManual manual = myController.getSQLiteManual(); SQLiteProfiler profiler = myProfiler; long from = profiler == null ? 0 : System.nanoTime();
myController.validate(); if (Internal.isFineLogging()) Internal.logFine(this, "bindStream(" + index + "," + bufferSize + ")"); try { DirectBuffer buffer = myController.allocateBuffer(bufferSize); BindStream out = new BindStream(index, buffer); List<BindStream> list = myBindStreams;
/** * Clear all data, disposing the blob. May be called by SQLiteConnection on close. */ void clear() { myHandle = null; myController = SQLiteController.getDisposed(myController); Internal.logFine(this, "cleared"); }
public void dispose() { DirectBuffer buffer = myBuffer; if (buffer != null) { myBuffer = null; myController.freeBuffer(buffer); } List<BindStream> list = myBindStreams; if (list != null) { list.remove(this); } } }
private ProgressHandler prepareStep() throws SQLiteException { clearBindStreams(true); clearColumnStreams(); ProgressHandler ph = myController.getProgressHandler(); ph.reset(); synchronized (this) { if (myCancelled) throw new SQLiteInterruptedException(); myProgressHandler = ph; } return ph; }
private void stepResult(int rc, String methodName) throws SQLiteException { if (!myStepped) { // if this is a first step, the statement may have been recompiled and column count changed myColumnCount = -1; } myStepped = true; if (rc == SQLITE_ROW) { if (Internal.isFineLogging()) Internal.logFine(this, methodName + " ROW"); myHasRow = true; } else if (rc == SQLITE_DONE) { if (Internal.isFineLogging()) Internal.logFine(this, methodName + " DONE"); myHasRow = false; } else { myController.throwResult(rc, methodName + "()", this); } }
/** * Gets a column value after step has returned a row of the result set. * <p/> * Call this method to retrieve data of type BLOB after {@link #step()} has returned true. * * @param column the index of the column, starting with 0 * @return a byte array with the value, or null if the value is NULL * @throws SQLiteException if SQLite returns an error, or if the call violates the contract of this class * @see <a href="http://www.sqlite.org/c3ref/column_blob.html">sqlite3_column_blob</a> */ public byte[] columnBlob(int column) throws SQLiteException { myController.validate(); SWIGTYPE_p_sqlite3_stmt handle = handle(); checkColumn(column, handle, true); if (Internal.isFineLogging()) Internal.logFine(this, "columnBytes(" + column + ")"); _SQLiteManual sqlite = myController.getSQLiteManual(); byte[] r = sqlite.sqlite3_column_blob(handle, column); myController.throwResult(sqlite.getLastReturnCode(), "columnBytes", this); if (Internal.isFineLogging()) Internal.logFine(this, "columnBytes(" + column + ")=[" + (r == null ? "null" : r.length) + "]"); return r; }
/** * Returns the number of pages still to be backed up. * * @return number of remaining pages * @throws SQLiteException if called from a different thread or if source or destination connection are disposed */ public int getRemaining() throws SQLiteException { mySourceController.validate(); myDestinationController.validate(); SWIGTYPE_p_sqlite3_backup handle = handle(); return _SQLiteSwigged.sqlite3_backup_remaining(handle); }
/** * Disposes this statement and frees allocated resources. If the statement's handle is cached, * it is returned to the connection's cache and can be reused by later calls to <code>prepare</code> * <p/> * Calling this method on an already disposed instance has no effect. * <p/> * After SQLiteStatement instance is disposed, it is no longer usable and holds no references to its originating * connection or SQLite database. */ public void dispose() { if (myHandle == null) return; try { myController.validate(); } catch (SQLiteException e) { Internal.recoverableError(this, "invalid dispose: " + e, true); return; } Internal.logFine(this, "disposing"); myController.dispose(this); // clear may be called from dispose() too clear(); }
myController.validate(); if (buffer == null || length <= 0 || offset < 0 || offset + length > buffer.length) { assert false; ProgressHandler ph = prepareStep(); try { _SQLiteManual manual = myController.getSQLiteManual(); SQLiteProfiler profiler = myProfiler; long from = profiler == null ? 0 : System.nanoTime();
/** * Constructs DISPOSED singleton */ private SQLiteStatement() { myController = SQLiteController.getDisposed(null); myHandle = null; mySqlParts = new SQLParts().fix(); myProfiler = null; }
public void close() throws IOException { try { myController.validate(); DirectBuffer buffer = myBuffer; if (buffer == null) return; if (Internal.isFineLogging()) Internal.logFine(SQLiteStatement.this, "BindStream.close:bind([" + buffer.data().capacity() + "])"); int rc = _SQLiteManual.wrapper_bind_buffer(handle(), myIndex, buffer); dispose(); myController.throwResult(rc, "bind(buffer)", SQLiteStatement.this); } catch (SQLiteException e) { throw new IOException("cannot write: " + e); } }
/** * Gets a column value after step has returned a row of the result set. * <p/> * Call this method to retrieve data of type String after {@link #step()} has returned true. * * @param column the index of the column, starting with 0 * @return a String value or null if database value is NULL * @throws SQLiteException if SQLite returns an error, or if the call violates the contract of this class * @see <a href="http://www.sqlite.org/c3ref/column_blob.html">sqlite3_column_text16</a> */ public String columnString(int column) throws SQLiteException { myController.validate(); SWIGTYPE_p_sqlite3_stmt handle = handle(); checkColumn(column, handle, true); if (Internal.isFineLogging()) Internal.logFine(this, "columnString(" + column + ")"); _SQLiteManual sqlite = myController.getSQLiteManual(); String result = sqlite.sqlite3_column_text(handle, column); myController.throwResult(sqlite.getLastReturnCode(), "columnString()", this); if (Internal.isFineLogging()) { if (result == null) { Internal.logFine(this, "columnString(" + column + ") is null"); } else if (result.length() <= 20) { Internal.logFine(this, "columnString(" + column + ")=" + result); } else { Internal.logFine(this, "columnString(" + column + ")=" + result.substring(0, 20) + "...."); } } return result; }