Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Switch to using a factory method like SentrySupportSQLiteOpenHelper
  • Loading branch information
angusholder committed Jan 6, 2026
commit 149441f882e9b59fc9814ab078d9d36c5fbae62c
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,21 @@ import io.sentry.ScopesAdapter
*
* Usage - wrap this around your current [SQLiteDriver]:
* ```
* val driver = SentrySQLiteDriver(AndroidSQLiteDriver())
* val driver = SentrySQLiteDriver.create(AndroidSQLiteDriver())
* ```
*
* If you use Room you can wrap the default [AndroidSQLiteDriver]:
* ```
* val database = Room.databaseBuilder(context, MyDatabase::class.java, "dbName")
* .setDriver(SentrySQLiteDriver(AndroidSQLiteDriver()))
* .setDriver(SentrySQLiteDriver.create(AndroidSQLiteDriver()))
* ...
* .build()
* ```
*/
public class SentrySQLiteDriver internal constructor(
private val scopes: IScopes,
private val delegate: SQLiteDriver,
private val scopes: IScopes = ScopesAdapter.getInstance(),
) : SQLiteDriver {
/**
* @param delegate The [SQLiteDriver] instance to delegate calls to.
*/
public constructor(delegate: SQLiteDriver) : this(ScopesAdapter.getInstance(), delegate)

override fun open(fileName: String): SQLiteConnection {
val sqliteSpanManager = SQLiteSpanManager(
scopes,
Expand All @@ -44,6 +39,20 @@ public class SentrySQLiteDriver internal constructor(
val connection = delegate.open(fileName)
return SentrySQLiteConnection(connection, sqliteSpanManager)
}

public companion object {
/**
* @param delegate The [SQLiteDriver] instance to delegate calls to.
*/
@JvmStatic
public fun create(delegate: SQLiteDriver): SQLiteDriver {
if (delegate is SentrySQLiteDriver) {
return delegate
} else {
return SentrySQLiteDriver(delegate)
}
}
}
}

internal class SentrySQLiteConnection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SentrySQLiteDriverTest {
sentryTracer = SentryTracer(TransactionContext("name", "op"), scopes)
whenever(scopes.span).thenReturn(sentryTracer)

return SentrySQLiteDriver(scopes, mockDriver)
return SentrySQLiteDriver(mockDriver, scopes)
}
}

Expand Down