44. SYNOPSIS
55 Get SQLite .NET driver
66. DESCRIPTION
7- Download and extract the SQLite .NET driver from NuGet.
7+ Download and extract the SQLite .NET driver and SQLite precompiled binaries.
8+ The SQLite version is automatically detected from the download page.
89. PARAMETER Version
910 System.String
10- The version of the SQLite .NET driver to download.
11+ The version of the System.Data. SQLite NuGet package to download. (require version 2.0.0 or higher)
1112. INPUTS
1213 None
1314. OUTPUTS
@@ -18,18 +19,41 @@ function Get-SQLite {
1819 param (
1920 [string ]$Version = ' 2.0.2'
2021 )
21- # Install SQLite
2222 try {
23- Write-Host " Downloading System.Data.SQLite $Version ... " - ForegroundColor DarkYellow
24- $sqlitePkgPath = " $env: TEMP \sqlite.zip"
23+ $sqliteNetPath = " $ env: TEMP \sqlite.net.zip "
24+ $sqliteDllPath = " $env: TEMP \sqlite.dll .zip"
2525 $sqliteTempPath = " $env: TEMP \sqlite"
2626 $sqlitePath = " $PSScriptRoot \..\supporting\sqlite"
27- Invoke-WebRequest - Uri " https://globalcdn.nuget.org/packages/system.data.sqlite.$version .nupkg" - OutFile $sqlitePkgPath
28- Write-Host " Extracting System.Data.SQLite $Version ... " - ForegroundColor DarkYellow - NoNewline
29- Expand-Archive - Path $sqlitePkgPath - DestinationPath $sqliteTempPath - Force
30- New-Item - Path $sqlitePath - ItemType Directory - Force | Out-Null
27+
28+ $arch = switch (Get-DefaultArchitecture ) {
29+ ' 32bit' { ' x86' }
30+ ' 64bit' { ' x64' }
31+ ' arm64' { ' arm64' }
32+ default { Write-Warning " Unknown architecture, using x64 as fallback" ; ' x64' }
33+ }
34+
35+ Write-Host " Downloading System.Data.SQLite $Version ..." - ForegroundColor DarkYellow
36+ Invoke-WebRequest - Uri " https://globalcdn.nuget.org/packages/system.data.sqlite.$Version .nupkg" - OutFile $sqliteNetPath
37+
38+ $downloadPage = Invoke-WebRequest - Uri ' https://sqlite.org/download.html' - UseBasicParsing
39+ if ($downloadPage.Content -match ' (?s)<!-- Download product data.*?(PRODUCT,.+?)-->' ) {
40+ $productData = $Matches [1 ] | ConvertFrom-Csv
41+ } else {
42+ throw " Failed to parse SQLite download page product data"
43+ }
44+ $matchRow = $productData | Where-Object { $_ .' RELATIVE-URL' -match " sqlite-dll-win-$arch -" }
45+ if (-not $matchRow ) {
46+ throw " SQLite DLL for architecture $arch not found"
47+ }
48+ Write-Host " Downloading SQLite DLL $ ( $matchRow.VERSION ) ..." - ForegroundColor DarkYellow
49+ Invoke-WebRequest - Uri " https://sqlite.org/$ ( $matchRow .' RELATIVE-URL' ) " - OutFile $sqliteDllPath
50+
51+ Write-Host " Extracting libraries... " - ForegroundColor DarkYellow - NoNewline
52+ $sqliteNetPath , $sqliteDllPath | Expand-Archive - DestinationPath $sqliteTempPath - Force
53+ $null = New-Item - Path " $sqlitePath \$arch " - ItemType Directory - Force
3154 Move-Item - Path " $sqliteTempPath \lib\netstandard2.0\System.Data.SQLite.dll" - Destination $sqlitePath - Force
32- Remove-Item - Path $sqlitePkgPath , $sqliteTempPath - Recurse - Force
55+ Move-Item - Path " $sqliteTempPath \sqlite3.dll" - Destination " $sqlitePath \$arch \e_sqlite3.dll" - Force
56+ Remove-Item - Path $sqliteNetPath , $sqliteDllPath , $sqliteTempPath - Recurse - Force
3357 Write-Host ' Done.' - ForegroundColor DarkYellow
3458 return $true
3559 } catch {
0 commit comments