Lines Matching defs:statement

115     // Because SQLite statement execution can be reentrant, we keep track of how many
421 // Update prepared statement cache size.
448 // Returns true if the prepared statement cache contains the specified SQL.
470 * Prepares a statement for execution but does not bind its parameters or execute it.
473 * prior to execution of the statement. If the {@code outStatementInfo} argument
475 * with information about the statement.
477 * A prepared statement makes no reference to the arguments that may eventually
479 * such as SELECT or INSERT/UPDATE statements. If the statement is cacheable,
483 * provides a method to acquire a connection that already has a given SQL statement
484 * in its prepared statement cache so that it is ready for execution.
487 * @param sql The SQL statement to prepare.
489 * with information about the statement, or null if none.
500 final PreparedStatement statement = acquirePreparedStatement(sql);
503 outStatementInfo.numParameters = statement.mNumParameters;
504 outStatementInfo.readOnly = statement.mReadOnly;
507 mConnectionPtr, statement.mStatementPtr);
514 mConnectionPtr, statement.mStatementPtr, i);
519 releasePreparedStatement(statement);
530 * Executes a statement that does not return a result.
532 * @param sql The SQL statement to execute.
548 final PreparedStatement statement = acquirePreparedStatement(sql);
550 throwIfStatementForbidden(statement);
551 bindArguments(statement, bindArgs);
552 applyBlockGuardPolicy(statement);
555 nativeExecute(mConnectionPtr, statement.mStatementPtr);
560 releasePreparedStatement(statement);
571 * Executes a statement that returns a single <code>long</code> result.
573 * @param sql The SQL statement to execute.
591 final PreparedStatement statement = acquirePreparedStatement(sql);
593 throwIfStatementForbidden(statement);
594 bindArguments(statement, bindArgs);
595 applyBlockGuardPolicy(statement);
598 return nativeExecuteForLong(mConnectionPtr, statement.mStatementPtr);
603 releasePreparedStatement(statement);
614 * Executes a statement that returns a single {@link String} result.
616 * @param sql The SQL statement to execute.
634 final PreparedStatement statement = acquirePreparedStatement(sql);
636 throwIfStatementForbidden(statement);
637 bindArguments(statement, bindArgs);
638 applyBlockGuardPolicy(statement);
641 return nativeExecuteForString(mConnectionPtr, statement.mStatementPtr);
646 releasePreparedStatement(statement);
657 * Executes a statement that returns a single BLOB result as a
660 * @param sql The SQL statement to execute.
680 final PreparedStatement statement = acquirePreparedStatement(sql);
682 throwIfStatementForbidden(statement);
683 bindArguments(statement, bindArgs);
684 applyBlockGuardPolicy(statement);
688 mConnectionPtr, statement.mStatementPtr);
694 releasePreparedStatement(statement);
705 * Executes a statement that returns a count of the number of rows
708 * @param sql The SQL statement to execute.
727 final PreparedStatement statement = acquirePreparedStatement(sql);
729 throwIfStatementForbidden(statement);
730 bindArguments(statement, bindArgs);
731 applyBlockGuardPolicy(statement);
735 mConnectionPtr, statement.mStatementPtr);
741 releasePreparedStatement(statement);
754 * Executes a statement that returns the row id of the last row inserted
755 * by the statement. Use for INSERT SQL statements.
757 * @param sql The SQL statement to execute.
775 final PreparedStatement statement = acquirePreparedStatement(sql);
777 throwIfStatementForbidden(statement);
778 bindArguments(statement, bindArgs);
779 applyBlockGuardPolicy(statement);
783 mConnectionPtr, statement.mStatementPtr);
788 releasePreparedStatement(statement);
799 * Executes a statement and populates the specified {@link CursorWindow}
803 * @param sql The SQL statement to execute.
838 final PreparedStatement statement = acquirePreparedStatement(sql);
840 throwIfStatementForbidden(statement);
841 bindArguments(statement, bindArgs);
842 applyBlockGuardPolicy(statement);
846 mConnectionPtr, statement.mStatementPtr, window.mWindowPtr,
857 releasePreparedStatement(statement);
877 PreparedStatement statement = mPreparedStatementCache.get(sql);
879 if (statement != null) {
880 if (!statement.mInUse) {
881 return statement;
883 // The statement is already in the cache but is in use (this statement appears
885 // statement but do not cache it.
894 statement = obtainPreparedStatement(sql, statementPtr, numParameters, type, readOnly);
896 mPreparedStatementCache.put(sql, statement);
897 statement.mInCache = true;
900 // Finalize the statement if an exception occurred and we did not add
902 if (statement == null || !statement.mInCache) {
907 statement.mInUse = true;
908 return statement;
911 private void releasePreparedStatement(PreparedStatement statement) {
912 statement.mInUse = false;
913 if (statement.mInCache) {
915 nativeResetStatementAndClearBindings(mConnectionPtr, statement.mStatementPtr);
917 // The statement could not be reset due to an error. Remove it from the cache.
920 // recycle the statement.
922 Log.d(TAG, "Could not reset prepared statement due to an exception. "
924 + trimSqlForDisplay(statement.mSql), ex);
927 mPreparedStatementCache.remove(statement.mSql);
930 finalizePreparedStatement(statement);
934 private void finalizePreparedStatement(PreparedStatement statement) {
935 nativeFinalizeStatement(mConnectionPtr, statement.mStatementPtr);
936 recyclePreparedStatement(statement);
945 // Reset cancellation flag before executing the statement.
963 // Reset cancellation flag after executing the statement.
970 // This method may be called on a different thread than the executing statement.
972 // detachCancellationSignal, while a statement is executing. We can safely assume
979 private void bindArguments(PreparedStatement statement, Object[] bindArgs) {
981 if (count != statement.mNumParameters) {
983 "Expected " + statement.mNumParameters + " bind arguments but "
990 final long statementPtr = statement.mStatementPtr;
1023 private void throwIfStatementForbidden(PreparedStatement statement) {
1024 if (mOnlyAllowReadOnlyOperations && !statement.mReadOnly) {
1025 throw new SQLiteException("Cannot execute this statement because it "
1038 private void applyBlockGuardPolicy(PreparedStatement statement) {
1040 if (statement.mReadOnly) {
1164 // The prepared statement cache is thread-safe so we can access its statistics
1183 PreparedStatement statement = mPreparedStatementPool;
1184 if (statement != null) {
1185 mPreparedStatementPool = statement.mPoolNext;
1186 statement.mPoolNext = null;
1187 statement.mInCache = false;
1189 statement = new PreparedStatement();
1191 statement.mSql = sql;
1192 statement.mStatementPtr = statementPtr;
1193 statement.mNumParameters = numParameters;
1194 statement.mType = type;
1195 statement.mReadOnly = readOnly;
1196 return statement;
1199 private void recyclePreparedStatement(PreparedStatement statement) {
1200 statement.mSql = null;
1201 statement.mPoolNext = mPreparedStatementPool;
1202 mPreparedStatementPool = statement;
1210 * Holder type for a prepared statement.
1212 * Although this object holds a pointer to a native statement object, it
1214 * owns the statement object and will take care of freeing it when needed.
1216 * resource disposal because all native statement objects must be freed before
1223 // The SQL from which the statement was prepared.
1230 // The number of parameters that the prepared statement has.
1233 // The statement type.
1236 // True if the statement is read-only.
1239 // True if the statement is in the cache.
1242 // True if the statement is in use (currently executing).
1265 printer.println(" Prepared statement cache:");
1270 PreparedStatement statement = entry.getValue();
1271 if (statement.mInCache) { // might be false due to a race with entryRemoved
1274 + Long.toHexString(statement.mStatementPtr)
1275 + ", numParameters=" + statement.mNumParameters
1276 + ", type=" + statement.mType
1277 + ", readOnly=" + statement.mReadOnly