Skip to content

Microsoft.Data.Sqlite: Add LoadExtension() to SqliteConnection#14789

Merged
bricelam merged 1 commit intodotnet:masterfrom
bricelam:ext
Feb 28, 2019
Merged

Microsoft.Data.Sqlite: Add LoadExtension() to SqliteConnection#14789
bricelam merged 1 commit intodotnet:masterfrom
bricelam:ext

Conversation

@bricelam
Copy link
Copy Markdown
Contributor

@bricelam bricelam commented Feb 22, 2019

This also updates EFCore.Sqlite to use the new method.

There is a breaking change in SpatialiteLoader. The methods used to take a DbConnection (I guess 'cause we could) but now take a SqliteConnection.

You no longer need to call SqliteConnection.EnableExtensions() before using SpatialiteLoader since the new LoadExtension method will bypass the connection setting. This greatly improves usability and makes EnableExtensions only apply to the load_extension SQL function. Given this, EnableExtensions should probably have been a connection string keyword.

In fact, SpatialiteLoader isn't really needed anymore since calling UseNetTopologySuite now loads the extension for open external connections. Maybe we should make it internal. (See #14821)

LoadExtension has some unusual behavior when the connection is closed. Any exceptions will be delayed until the connection is opened, and there is no way to remove an extension you tried to load, so you'll have to create a new connection object to get back in a good state.

Resolves #13826

I'll review these changes in a design meeting to make sure we're OK with them all.

@bricelam bricelam changed the title Microsoft.Data.Sqlite: Add LoadExtension() to SqliteConnection WIP: Microsoft.Data.Sqlite: Add LoadExtension() to SqliteConnection Feb 22, 2019
Comment thread src/EFCore.Sqlite.Core/Infrastructure/SpatialiteLoader.cs
@bricelam bricelam changed the title WIP: Microsoft.Data.Sqlite: Add LoadExtension() to SqliteConnection Microsoft.Data.Sqlite: Add LoadExtension() to SqliteConnection Feb 25, 2019
This also updates EFCore.Sqlite to use the new method.

There is a breaking change in SpatialiteLoader. The methods used to take a DbConnection (I guess 'cause we could) but now take a SqliteConnection.

You no longer need to call SqliteConnection.EnableExtensions() before using SpatialiteLoader since the new LoadExtension method will bypass the connection setting. This greatly improves usability and makes EnableExtensions only apply to the load_extension SQL function. Given this, EnableExtensions should probably have been a connection string keyword.

In fact, SpatialiteLoader isn't really needed anymore since calling UseNetTopologySuite now loads the extension for open external connections. Maybe we should make it internal.

LoadExtension has some unusual behavior when the connection is closed. Any exceptions will be delayed until the connection is opened, and there is no way to remove an extension you tried to load, so you'll have to create a new connection object to get back in a good state.

Resolves #13826
/// <param name="connection"> The connection. </param>
/// <returns> true if the extension was loaded; otherwise, false. </returns>
public static bool TryLoad([NotNull] DbConnection connection)
public static bool TryLoad([NotNull] SqliteConnection connection)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not an extension method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Most people shouldn't use it. (None now that we do it for externally opened connections.)

@bricelam bricelam merged commit 82cf4a4 into dotnet:master Feb 28, 2019
@bricelam bricelam deleted the ext branch February 28, 2019 18:52
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.

Microsoft.Data.Sqlite: Persist functions, PRAGMAs, etc. between close and re-open

2 participants