Skip to content

feature request: execute multiple statments in one call #122

@stevenctl

Description

@stevenctl

All methods in this package only support executing a single statement. While obviously
you can work around this by manually splitting out SQL or a potentially sketchy .split(';'),
those are inconvieint and error-prone.

I'd like to do something like:

final migration = await File("./assets/ddl/$fname").readAsString();
await db.execute(script); // only supports 1 statement!

Currently:

  • execute calls select under the hood
  • and executeBatch does prepare then statement.execute().

We need something that uses prepareMultiple.

For web: https://github.com/simolus3/sqlite3.dart/blob/v2/lib/src/worker.dart#L345

API Options

1. New method with no parameters

Future<void> executeMultiple(String sql)
// or
Future<void> executeRaw(String sql)

Why didn't I include a List<List<Object?>> parameterSets or even a flat List<Object?>?

It's pretty ambigious how that should be handled with multiple statements:

  • Do we apply every parameter set to every statement?
  • Do we apply parameterSets[n] to statements[n]?
  • If parameterSets.length != statements.length, is that an error?

IIUC adding optional parameters is not a breaking change, so that could be added later.

2. Modify executeBatch behavior

Current implementation uses .prepare, could switch to .prepareMultiple and execute statements sequentially (stop on first error).

Breaking change risk: Users unknowingly passing multiple statements who rely on only the first executing.

Could make explicit:

Future<void> executeBatch(
  String sql,
  List<List<Object?>> parameterSets, {
  bool allowMultipleStatements = true,
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions