# PooledConnection

Artifact: [androidx.room:room-runtime](https://developer.android.com/jetpack/androidx/releases/room) [View Source](https://cs.android.com/search?q=file:androidx/room/Transactor.kt+class:androidx.room.PooledConnection) Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

*** ** * ** ***


```
public interface PooledConnection
```

<br />

Known direct subclasses [TransactionScope](https://developer.android.com/reference/androidx/room/TransactionScope), [Transactor](https://developer.android.com/reference/androidx/room/Transactor)

|---|---|
| `https://developer.android.com/reference/androidx/room/TransactionScope` | A `https://developer.android.com/reference/androidx/room/PooledConnection` with an active transaction capable of performing nested transactions. |
| `https://developer.android.com/reference/androidx/room/Transactor` | A `https://developer.android.com/reference/androidx/room/PooledConnection` that can perform transactions. |

*** ** * ** ***

A wrapper of `https://developer.android.com/reference/androidx/sqlite/SQLiteConnection` that belongs to a connection pool and is safe to use in a coroutine.

## Summary

| ### Public methods |
|---|---|
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull R` | `<R extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/room/PooledConnection#usePrepared(kotlin.String,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html sql, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/SQLiteStatement, @https://developer.android.com/reference/androidx/annotation/NonNull R> block )` Prepares a new SQL statement and use it within the code `https://developer.android.com/reference/androidx/room/PooledConnection#usePrepared(kotlin.String,kotlin.Function1)`. |

| ### Extension functions |
|---|---|
| `default final void` | `https://developer.android.com/reference/androidx/room/TransactorKt.https://developer.android.com/reference/androidx/room/PooledConnection#(androidx.room.PooledConnection).execSQL(kotlin.String)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/PooledConnection receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html sql )` Executes a single SQL statement that returns no values. |

## Public methods

### usePrepared

```
abstract @NonNull R <R extends Object> usePrepared(
    @NonNull String sql,
    @NonNull Function1<@NonNull SQLiteStatement, @NonNull R> block
)
```

Prepares a new SQL statement and use it within the code `https://developer.android.com/reference/androidx/room/PooledConnection#usePrepared(kotlin.String,kotlin.Function1)`.

Using the given `https://developer.android.com/reference/androidx/sqlite/SQLiteStatement` after `https://developer.android.com/reference/androidx/room/PooledConnection#usePrepared(kotlin.String,kotlin.Function1)` completes is prohibited. The statement will also be thread confined, attempting to use it from another thread is an error.

Using a statement locks the connection it belongs to, therefore try not to do long-running computations within the `https://developer.android.com/reference/androidx/room/PooledConnection#usePrepared(kotlin.String,kotlin.Function1)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html sql` | The SQL statement to prepare |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/SQLiteStatement, @https://developer.android.com/reference/androidx/annotation/NonNull R> block` | The code to use the statement |

## Extension functions

### TransactorKt.execSQL

Artifact: [androidx.room:room-runtime](https://developer.android.com/jetpack/androidx/releases/room) [View Source](https://cs.android.com/search?q=file:androidx/room/Transactor.kt+function:execSQL)

```
default final void TransactorKt.execSQL(
    @NonNull PooledConnection receiver,
    @NonNull String sql
)
```

Executes a single SQL statement that returns no values.