# PooledConnection

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

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  interface PooledConnection
  ```
Known direct subclasses [TransactionScope](https://developer.android.com/reference/kotlin/androidx/room3/TransactionScope), [Transactor](https://developer.android.com/reference/kotlin/androidx/room3/Transactor)

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

*** ** * ** ***

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

## Summary

| ### Public functions |
|---|---|---|
| `suspend R` | `<R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/room3/PooledConnection#usePrepared(kotlin.String,kotlin.coroutines.SuspendFunction1)(sql: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, block: suspend (https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteStatement) -> R)` Prepares a new SQL statement and use it within the code `https://developer.android.com/reference/kotlin/androidx/room3/PooledConnection#usePrepared(kotlin.String,kotlin.coroutines.SuspendFunction1)`. | Cmn |

| ### Extension functions |
|---|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/PooledConnection.https://developer.android.com/reference/kotlin/androidx/room3/PooledConnection#(androidx.room3.PooledConnection).executeSQL(kotlin.String)(sql: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Executes a single SQL statement that returns no values. | Cmn |

## Public functions

### usePrepared

Cmn

```
suspend fun <R : Any?> usePrepared(sql: String, block: suspend (SQLiteStatement) -> R): R
```

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

Using the given `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteStatement` after `https://developer.android.com/reference/kotlin/androidx/room3/PooledConnection#usePrepared(kotlin.String,kotlin.coroutines.SuspendFunction1)` completes is prohibited. The statement will also be coroutine confined, attempting to use it from another coroutine 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/kotlin/androidx/room3/PooledConnection#usePrepared(kotlin.String,kotlin.coroutines.SuspendFunction1)`.

| Parameters |
|---|---|
| `sql: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The SQL statement to prepare |
| `block: suspend (https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteStatement) -> R` | The code to use the statement |

## Extension functions

### PooledConnection.executeSQL

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

```
suspend fun PooledConnection.executeSQL(sql: String): Unit
```

Executes a single SQL statement that returns no values.