Skip to content

Commit 0407796

Browse files
authored
Merge pull request #290 from benthillerkus/use-winsqlite3
Try loading winsqlite3.dll on Windows
2 parents a42bf40 + 2436359 commit 0407796

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

.github/workflows/main.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ jobs:
137137
matrix:
138138
os: [ubuntu-latest, windows-latest, macos-latest]
139139
dart: [stable, dev]
140+
sqlite: [system, compiled]
140141

141-
name: Unit tests with Dart ${{ matrix.dart }} on ${{ matrix.os }}
142+
name: Unit tests with Dart ${{ matrix.dart }} on ${{ matrix.os }} with ${{ matrix.sqlite }} sqlite
142143
runs-on: ${{ matrix.os }}
143144

144145
steps:
@@ -148,34 +149,40 @@ jobs:
148149
sdk: ${{ matrix.dart }}
149150

150151
- name: Download compiled sqlite3
151-
if: runner.os == 'Linux' || runner.os == 'Windows' || runner.os == 'macOS'
152+
if: matrix.sqlite == 'compiled' && (runner.os == 'Linux' || runner.os == 'Windows' || runner.os == 'macOS')
152153
uses: actions/download-artifact@v4
153154
with:
154155
name: sqlite3-${{ runner.os }}
155156
path: sqlite/out
156157

157158
- name: Install compiled sqlite3 (Linux)
158-
if: runner.os == 'Linux'
159+
if: matrix.sqlite == 'compiled' && runner.os == 'Linux'
159160
run: |
160161
chmod a+x sqlite/out/sqlite3
161162
realpath sqlite/out >> $GITHUB_PATH
162163
echo "LD_LIBRARY_PATH=$(realpath sqlite/out)" >> $GITHUB_ENV
163164
echo "C_INCLUDE_PATH=$(realpath sqlite/out)" >> $GITHUB_ENV
165+
- name: Install system sqlite3 (Ubuntu)
166+
if: matrix.sqlite == 'system' && runner.os == 'Linux'
167+
run: sudo apt install sqlite3
164168
- name: Install compiled sqlite3 (macOS)
165-
if: runner.os == 'macOS'
169+
if: matrix.sqlite == 'compiled' && runner.os == 'macOS'
166170
run: |
167171
chmod a+x sqlite/out/sqlite3
168172
echo "$(pwd)/sqlite/out" >> $GITHUB_PATH
169173
echo "DYLD_LIBRARY_PATH=$(pwd)/sqlite/out" >> $GITHUB_ENV
170174
echo "CPATH=$(pwd)/sqlite/out" >> $GITHUB_ENV
171175
- uses: ilammy/msvc-dev-cmd@v1
172-
if: runner.os == 'Windows'
176+
if: matrix.sqlite == 'compiled' && runner.os == 'Windows'
173177
- name: Install compiled sqlite3 (Windows)
174-
if: runner.os == 'Windows'
178+
if: matrix.sqlite == 'compiled' && runner.os == 'Windows'
175179
run: |
176180
echo $env:path
177181
Resolve-Path -Path "sqlite/out" >> $env:GITHUB_PATH
178182
"INCLUDE=" + $env:INCLUDE + ";" + (Resolve-Path -Path "sqlite/out") >> $env:GITHUB_EN
183+
- name: Check if Winsqlite exists
184+
if: matrix.sqlite == 'system' && runner.os == 'Windows'
185+
run: Test-Path C:\Windows\System32\winsqlite3.dll
179186

180187
- uses: actions/cache@v4
181188
with:
@@ -188,11 +195,11 @@ jobs:
188195
- name: Test sqlite3 package
189196
run: |
190197
dart pub get
191-
dart test -P ci
198+
dart test --test-randomize-ordering-seed "random" -P ci
192199
working-directory: sqlite3/
193200

194201
- name: Test with SQLITE_OMIT_AUTOINIT
195-
if: runner.os == 'Linux'
202+
if: matrix.sqlite == 'compiled' && runner.os == 'Linux'
196203
run: |
197204
ls $LD_LIBRARY_PATH
198205
dart run tool/check_compile_time_option.dart OMIT_AUTOINIT
@@ -202,6 +209,7 @@ jobs:
202209
working-directory: sqlite3/
203210

204211
- name: Test sqlite3_test package
212+
if: matrix.sqlite != 'system' || runner.os != 'Windows'
205213
run: |
206214
dart pub get
207215
dart test
@@ -215,7 +223,7 @@ jobs:
215223
# If browsers behave differently on different platforms, surely that's not our fault...
216224
# So, only run browser tests on Linux to be faster.
217225
# todo: Something broke Dart web tests in Dart 2.18, it looks like this is related to finalizers
218-
if: runner.os == 'Linux'
226+
if: matrix.sqlite == 'compiled' && runner.os == 'Linux'
219227
working-directory: sqlite3/
220228

221229
# The integration tests for android are currently broken (the emulator doesn't want to

sqlite3/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ Here's how to use this library on the most popular platforms:
4040
- __macOS__: Contains a built-in version of sqlite that this package will use by default.
4141
Also, you can depend on `sqlite3_flutter_libs` if you want to include the latest
4242
sqlite3 version with your app.
43-
- __Windows__: Flutter users can depend on `sqlite3_flutter_libs` to ship the latest sqlite3
43+
- __Windows__: Contains a built-in version of sqlite (winsqlite3.dll) that this package will use by default.
44+
winsqlite is used by Windows OS components and as the backend of .NET database APIs,
45+
but is [otherwise undocumented](https://github.com/microsoft/win32metadata/issues/824#issuecomment-1067220882);
46+
so you may still want to provide a sqlite3 binary you control.
47+
Flutter users can depend on `sqlite3_flutter_libs` to ship the latest sqlite3
4448
version with their app.
45-
When not using Flutter, you need to manually include sqlite3 (see below).
49+
When not using Flutter, you can manually include sqlite3 (see below).
4650
- __Web__: See [web support](#wasm-web-support) below.
4751

4852
On Android, iOS and macOS, you can depend on the `sqlcipher_flutter_libs` package to use

sqlite3/lib/src/ffi/load_library.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,18 @@ DynamicLibrary _defaultOpen() {
8686
}
8787
return result;
8888
} else if (Platform.isWindows) {
89-
return DynamicLibrary.open('sqlite3.dll');
89+
try {
90+
// Compability with older versions of package:sqlite3 that did this
91+
return DynamicLibrary.open('sqlite3.dll');
92+
} on ArgumentError catch (_) {
93+
// Load the OS distribution of sqlite3 as a fallback
94+
// This is used as the backend for .NET based Database APIs
95+
// and several Windows apps & features,
96+
// but you may still want to bring your own copy of sqlite3
97+
// since it's undocumented functionality.
98+
// https://github.com/microsoft/win32metadata/issues/824#issuecomment-1067220882
99+
return DynamicLibrary.open('winsqlite3.dll');
100+
}
90101
}
91102

92103
throw UnsupportedError('Unsupported platform: ${Platform.operatingSystem}');

0 commit comments

Comments
 (0)