Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back the SQLitePCLRaw.provider.sqlite3 packages #325

Closed
bricelam opened this issue Jan 10, 2020 · 21 comments
Closed

Bring back the SQLitePCLRaw.provider.sqlite3 packages #325

bricelam opened this issue Jan 10, 2020 · 21 comments

Comments

@bricelam
Copy link
Contributor

Using the system version of SQLite is a bit ugly in 2.x:

class NativeLibraryAdapter : IGetFunctionPointer
{
    readonly IntPtr _library;

    public NativeLibraryAdapter(string name)
        => _library = NativeLibrary.Load(name);

    public IntPtr GetFunctionPointer(string name)
        => NativeLibrary.TryGetExport(_library, name, out var address)
            ? address
            : IntPtr.Zero;
}
SQLite3Provider_dynamic_cdecl
    .Setup("sqlite3", new NativeLibraryAdapter("sqlite3"));
SQLitePCL.raw.SetProvider(new SQLite3Provider_dynamic_cdecl());

It gets even harder on .NET Framework where NativeLibrary isn't available.

Newer versions of PROJ--used by the SpatiaLite extension--are only compatible with the system-installed version of SQLite. (see dotnet/efcore#16667) So having an easier way to use the system version would be nice.

@ericsink
Copy link
Owner

This wouldn't be hard to do, and probably makes sense.

At the beginning of my dev cycle for 2.0, one of my goals was to reduce the number of packages and providers. The sheer number of them causes a lot of confusion. I made some progress, but in general, this goal seems to be unreachable. There are so many edge cases. SQLitePCLRaw is almost entirely about edge cases.

@ericsink
Copy link
Owner

ericsink commented May 1, 2020

v2.0.3 has been pushed to nuget. It includes SQLitePCLRaw.provider.sqlite3.nupkg. Please let me know of any problems found with it.

@ericsink ericsink mentioned this issue May 1, 2020
@bricelam
Copy link
Contributor Author

bricelam commented May 1, 2020

Worth adding a bundle?

@ericsink
Copy link
Owner

ericsink commented May 1, 2020

:-)

If you think it's worth the trouble, I can do it. I default to no on such things because it seems like every additional package ID causes confusion.

@Gusi
Copy link

Gusi commented Jun 11, 2020

Hi,
I'm, stuck with a problem using this provider to load a custom sqlite3.dll. I can initialize the provider manually, but when trying to use a Microsoft.Data.Sqlite.SqliteConnection, the SqliteConnection static constructor forces a call to the SQLitePCL.Batteries_V2.Init method, and I can not find the SQLitePCL.batteries_v2.dll in the nuget package so the call fails,

Is this a bug or am I doing something wrong?

@ericsink
Copy link
Owner

@Gusi
Copy link

Gusi commented Jun 11, 2020

Try this:

https://www.nuget.org/packages/Microsoft.Data.Sqlite.Core/

I think it won't work. The Sqlite.Core package still calls batteries_v2

https://github.com/aspnet/Microsoft.Data.Sqlite/blob/master/src/Microsoft.Data.Sqlite.Core/Utilities/BundleInitializer.cs

The difference with normal Sqlite package is that it doesn't include the bundle, but the initialization call is still there.

@ericsink
Copy link
Owner

Oh my, you are correct -- sorry about that.

So @bricelam , yeah, I guess maybe it is worth adding a bundle...

@Gusi
Copy link

Gusi commented Jun 11, 2020

Thanks for your help!

I patched it by now creating a fake SQLitePCL.batteries_v2.dll library with and empty Init method so the Microsoft.Data.Sqlite doesn't complain. It works, but of course this is not a good solution.

@bricelam
Copy link
Contributor Author

You can manually set (and freeze if necessary) the provider before using SqliteConnection. It only tries to call Batteries_V2–it’s not an error if it can’t.

@bricelam
Copy link
Contributor Author

But yes, a bundle definitely improves the experience

@Gusi
Copy link

Gusi commented Jun 11, 2020

Thanks for the reply.
Indeed I'm setting the provider befores calling SqliteConnection, but haven't tried the Freeze feature. About the call to Batteries_V2 I've not checked if it's inside a try/catch block, so I will test it again.

Regards.

@ericsink ericsink mentioned this issue Aug 13, 2020
ericsink added a commit that referenced this issue Aug 17, 2020
ericsink added a commit that referenced this issue Aug 17, 2020
@ericsink
Copy link
Owner

@bricelam I've added bundle_sqlite3.

I'm not sure if there are any edge cases that matter to you which I might be forgetting about, but the bundle right now is pretty darn simple. It only targets netstandard2.0, and it always just does DllImport of "sqlite3" (as opposed to NativeLibrary.Load or any other dynamic approach).

It has a test app which runs against netcoreapp2.1, netcoreapp3.1, and net461, and on my machine, it passes all my usual tests against all 3 targets, with the 64 bit sqlite3.dll obtained from sqlite.org. I haven't tried anything like using Linux against whatever sqlite package is part of Ubuntu, for example.

None of this is up on nuget yet, but I'll probably be doing a 2.0.4-pre at some point soon for testing purposes.

Feedback welcome.

@bricelam
Copy link
Contributor Author

bricelam commented Aug 18, 2020

Nice, I'll run the Microsoft.Data.Sqlite and EF Core tests on it (like we do for winsqlite3 and e_sqlcipher) when the prerelease is available, so we can get coverage on Ubuntu and macOS.

@bricelam
Copy link
Contributor Author

I wonder if this package would benefit Unity on iOS. Using the system version of SQLite instead of statically linking your own sounds a lot simpler.

@ericsink
Copy link
Owner

OTOH, if this package helped the Unity on iOS case, then it seems that bundle_green would too.

@Gusi
Copy link

Gusi commented Sep 9, 2020

I can't see this package listed in the nuget package directory, but it is commented in the 2.0.4 release notes. Is it still in beta? Should I compile it myself or will it be available soon? Thx!

@ericsink
Copy link
Owner

ericsink commented Sep 9, 2020

@Gusi
Copy link

Gusi commented Sep 9, 2020

My fault, I was doing the wrong search. Thanks, everything working fine now!

@angelrishi
Copy link

Sir, built a custom SQlite. It is now lib/x86/libsqliteX.so in the Android.
The android is using SQLitePCLRaw.bundle_green. So, the custom built sqlite is completely ignored by Android.
Should we be using SQLitePCL.raw.SetProvider(new SQLite3Provider_dynamic_cdecl());
Would this work for both iOS and Android?

@ericsink
Copy link
Owner

@angelrishi This issue is closed. You need to open a new issue and post complete information about what trouble you are having.

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

No branches or pull requests

4 participants