# SQLiteConnection

Artifact: [androidx.sqlite:sqlite](https://developer.android.com/jetpack/androidx/releases/sqlite) [View Source](https://cs.android.com/search?q=file:androidx/sqlite/SQLiteConnection.+class:androidx.sqlite.SQLiteConnection) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.5.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  interface SQLiteConnection : AutoCloseable
  ```
Known direct subclasses [SupportSQLiteConnection](https://developer.android.com/reference/kotlin/androidx/sqlite/driver/SupportSQLiteConnection)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/sqlite/driver/SupportSQLiteConnection` | A `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection` implemented by `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteDatabase` and that uses the Android's SQLite through the `SupportSQLite` APIs. |

*** ** * ** ***

SQLite connection definition.

A connection to a database is a resource that must be released once it is no longer needed via its `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection#close()` function.

See also [Database Connection](https://www.sqlite.org/c3ref/sqlite3.html)

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection#close()()` Closes the database connection. | Cmn JS |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection#inTransaction()()` Returns true if the connection has an active transaction, false otherwise. | Cmn JS |
| `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteStatement` | `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection#prepare(kotlin.String)(sql: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Prepares a new SQL statement. | Cmn |
| `suspend https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteStatement` | `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection#prepare(kotlin.String)(sql: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Prepares a new SQL statement asynchronously. | JS |

| ### Extension functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection.https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection#(androidx.sqlite.SQLiteConnection).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 |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection.https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection#(androidx.sqlite.SQLiteConnection).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 JS |
| `suspend https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteStatement` | `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection.https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection#(androidx.sqlite.SQLiteConnection).prepare(kotlin.String)(sql: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Prepares a new SQL statement. | Cmn JS |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection.https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteConnection#(androidx.sqlite.SQLiteConnection).execSQL(kotlin.String)(sql: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Executes a single SQL statement that returns no values asynchronously. | JS |

## Public functions

### close

Cmn JS Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.5.0)

```
fun close(): Unit
```

Closes the database connection.

Once a connection is closed it should no longer be used. Calling this function on an already closed database connection is a no-op.

### inTransaction

Cmn JS Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.6.0)

```
fun inTransaction(): Boolean
```

Returns true if the connection has an active transaction, false otherwise.

### prepare

Cmn Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/sqlite#2.5.0)

```
fun prepare(sql: String): SQLiteStatement
```

Prepares a new SQL statement.

See also [Compiling a SQL statement](https://www.sqlite.org/c3ref/prepare.html)

| Parameters |
|---|---|
| `sql: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | the SQL statement to prepare |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteStatement` | the prepared statement. |

### prepare

JS

```
suspend fun prepare(sql: String): SQLiteStatement
```

Prepares a new SQL statement asynchronously.

See also [Compiling a SQL statement](https://www.sqlite.org/c3ref/prepare.html)

| Parameters |
|---|---|
| `sql: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | the SQL statement to prepare |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/sqlite/SQLiteStatement` | the prepared statement. |

## Extension functions

### SQLiteConnection.execSQL

Cmn Artifact: [androidx.sqlite:sqlite](https://developer.android.com/jetpack/androidx/releases/sqlite) [View Source](https://cs.android.com/search?q=file:androidx/sqlite/SQLite.nonWeb.kt+function:execSQL)

```
fun SQLiteConnection.execSQL(sql: String): Unit
```

Executes a single SQL statement that returns no values.

### SQLiteConnection.executeSQL

Cmn JS Artifact: [androidx.sqlite:sqlite-async](https://developer.android.com/jetpack/androidx/releases/sqlite) [View Source](https://cs.android.com/search?q=file:androidx/sqlite/async/SQLiteAsync.+function:executeSQL)

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

Executes a single SQL statement that returns no values.

On web targets this function is asynchronous while for non-web it is synchronous.

### SQLiteConnection.prepare

Cmn JS Artifact: [androidx.sqlite:sqlite-async](https://developer.android.com/jetpack/androidx/releases/sqlite) [View Source](https://cs.android.com/search?q=file:androidx/sqlite/async/SQLiteAsync.+function:prepare)

```
suspend fun SQLiteConnection.prepare(sql: String): SQLiteStatement
```

Prepares a new SQL statement.

On web targets this function is asynchronous while for non-web it is synchronous.

### SQLiteConnection.execSQL

JS Artifact: [androidx.sqlite:sqlite](https://developer.android.com/jetpack/androidx/releases/sqlite) [View Source](https://cs.android.com/search?q=file:androidx/sqlite/SQLite.nonWeb.kt+function:execSQL)

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

Executes a single SQL statement that returns no values asynchronously.