Skip to content

Conversation

@stevenctl
Copy link

@stevenctl stevenctl commented Dec 6, 2025

fixes #122

This PR adds a new method that allows executing all statements in a given string. More context is in the issue.

// bikeshedding on the name is very welcome!
Future<void> executeMultiple(String sql, [List<Object?> paramters = const []]) async

Based on feedback, I've updated the PR to just use execute which doesn't require any changes to the core sqlite3 package. However, I still believe this functionality needs a new API. It is valid to expect a ResultSet from the vanilla execute. I don't think there is a way to modify that signature to add settings here. The only way to avoid adding an API here

Also, using execute means that it is valid after all to pass parameters. Using params.isEmpty/isNotEmpty is probably not a good way to decide whether the user can expect a result back (it's perfectly valid to expect a result from INSERT INTO mytable (something) RETURNING id.

This is implemented using prepareMultiple from the sqlite3 package.

For web support, an additional PR (simolus3/sqlite3.dart#337) was required in that repo/package. For now I left a dependency override that should be removed before merging.

[List<Object?> parameters = const []]) async {
return task.timeSync(
'execute',
() => db.select(sql, parameters),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to sqlite3_web, maybe an approach could be to make this call db.execute() instead and then return an empty result set. That would allow using the existing method to run multiple statements.

(To be honest, I don't really understand why execute returns a ResultSet instead of void)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe to support RETURNING?

INSERT INTO users (name, email) 
VALUES ('Alice', '[email protected]')
RETURNING id, name;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#122 (comment)

added more detail here...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I updated this PR to use execute and updated the description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: execute multiple statments in one call

2 participants