# 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)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

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

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/TransactionScope` | A `https://developer.android.com/reference/kotlin/androidx/room/PooledConnection` with an active transaction capable of performing nested transactions. |
| `https://developer.android.com/reference/kotlin/androidx/room/Transactor` | A `https://developer.android.com/reference/kotlin/androidx/room/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/room/PooledConnection#usePrepared(kotlin.String,kotlin.Function1)(sql: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, block: (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/room/PooledConnection#usePrepared(kotlin.String,kotlin.Function1)`. | Cmn |

| ### Extension functions |
|---|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/room/PooledConnection.https://developer.android.com/reference/kotlin/androidx/room/PooledConnection#(androidx.room.PooledConnection).execSQL(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: (SQLiteStatement) -> R): R
```

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

Using the given `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteStatement` after `https://developer.android.com/reference/kotlin/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/kotlin/androidx/room/PooledConnection#usePrepared(kotlin.String,kotlin.Function1)`.

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

## Extension functions

### PooledConnection.execSQL

Cmn 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)

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

Executes a single SQL statement that returns no values.