pragmaStatements method

  1. @override
List<String> pragmaStatements(
  1. SqliteOpenOptions options
)
override

Pragma statements to run on newly opened connections to configure them.

On native platforms, these configure WAL mode for instance. This can also be useed to configure an encryption key if SQLite3MultipleCiphers is used.

Implementation

@override
List<String> pragmaStatements(SqliteOpenOptions options) {
  List<String> statements = [];

  if (sqliteOptions.lockTimeout != null) {
    // May be replaced by a Dart-level retry mechanism in the future
    statements.add(
        'PRAGMA busy_timeout = ${sqliteOptions.lockTimeout!.inMilliseconds}');
  }

  if (options.primaryConnection && sqliteOptions.journalMode != null) {
    // Persisted - only needed on the primary connection
    statements
        .add('PRAGMA journal_mode = ${sqliteOptions.journalMode!.name}');
  }
  if (!options.readOnly && sqliteOptions.journalSizeLimit != null) {
    // Needed on every writable connection
    statements.add(
        'PRAGMA journal_size_limit = ${sqliteOptions.journalSizeLimit!}');
  }
  if (sqliteOptions.synchronous != null) {
    // Needed on every connection
    statements.add('PRAGMA synchronous = ${sqliteOptions.synchronous!.name}');
  }
  return statements;
}