dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.27k stars 5.89k forks source link

Sqlite load extension documentation could be more detailed #28429

Open WowItsDoge opened 2 years ago

WowItsDoge commented 2 years ago

Help us make content visible

Loading of Sqlite extensions is documented on this site: https://docs.microsoft.com/en-us/dotnet/standard/data/sqlite/extensions

An example of the extension loading process is described in this file: https://github.com/dotnet/docs/blob/main/samples/snippets/standard/data/sqlite/ExtensionsSample/Program.cs

But what is unclear is, what Nuget Packages are needed, that the extensions could be found?

The extension I would like to use is Spellfix1. It would be cool, if it could be described, if it is contained in a Nuget packages, or if the manual extension compilation is needed. https://stackoverflow.com/questions/71244785/sqlite-with-spellfix1-extension-used-with-entity-framework-core-crash-on-second

Describe the new article


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

bricelam commented 2 years ago

The best way to get SQLite extensions is to install them using the OS package manager. For example, APT on Debian-based Linux distros or Homebrew on macOS.

We decided to create a NuGet package to distribute SpatiaLite on Windows since things like Chocolatey, Scoop, and winget aren't widely used and AFAIK don't have any packages for SpatiaLite. As you can see by the sample, there are a lot of hoops we have to jump through to actually get the correct version of mod_spatialite.dll to be on the Path before trying to get SQLite to load it.

My recommendation is to find a simpler solution that works just for your application. For example, if you know your app will only ever run on Windows x64, then just include that DLL in your project and set Copy to Output Directory. If your app is intended to be cross-platform, then things start to get more complicated.

WowItsDoge commented 2 years ago

Thank you for your answer! My app targets only Windows, so I guess copying the DLL to the output directory is enough.

First I thought the MSDN documentation for Sqlite could be more detailed, but as you described, it is a more complex subject than previously assumed, especially for users which are targeting multiple OS.

WowItsDoge commented 2 years ago

First I downloaded the Sqlite Amalgamation from this url: https://www.sqlite.org/2022/sqlite-amalgamation-3380000.zip Then downloaded the source folder from this url: https://www.sqlite.org/2022/sqlite-src-3380000.zip

After unziping both folders, I have copied the files sqlite3.h, sqlite3.c and sqlite3ext.h from the first folder to sqlite-src-3380000/ext/misc from the second folder. Then I have run with Cygwin64 the following command: gcc -I -g -shared spellfix.c -o spellfix.dll The spellfix.dll could be created, but it seams rather small with 88 kb. When I tried to load it, the following error is displayed: Microsoft.Data.Sqlite.SqliteException: "SQLite Error 1: ' Module not found. It makes no difference, if a relative or absolute Dll filepath was used.

var connection = new SqliteConnection("Data Source=LoadModuleTest.sqlite;");
connection.Open();
connection.EnableExtensions(true);
connection.LoadExtension(@"spellfix.dll");
connection.Close();

Have you any ideas, what am I missing?