Skip to content

Commit df88c0e

Browse files
committed
[sqflite] json1 doc
1 parent 907dd79 commit df88c0e

File tree

1 file changed

+73
-24
lines changed

1 file changed

+73
-24
lines changed

sqflite/doc/troubleshooting.md

+73-24
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
If you ran into build/runtime issues, please try the following:
44

55
* Update flutter to the latest version (`flutter upgrade`)
6-
* Update sqflite dependencies to the latest version in your `pubspec.yaml`
7-
(`sqflite >= X.Y.Z`)
6+
* Update sqflite dependencies to the latest version in your `pubspec.yaml`
7+
(`sqflite >= X.Y.Z`)
88
* Update dependencies (`flutter packages upgrade`)
99
* try `flutter clean`
10-
* Try deleting the flutter cache folder (which will
11-
downloaded again automatically) from your flutter installation folder `$FLUTTER_TOP/bin/cache`
10+
* Try deleting the flutter cache folder (which will
11+
downloaded again automatically) from your flutter installation folder `$FLUTTER_TOP/bin/cache`
1212

1313
# Recommendations
1414

@@ -49,15 +49,18 @@ This error is typically a build/setup error after adding the dependency.
4949
- Try to clean your build folder `flutter clean`
5050
- On iOS, you can try to force a `pod install` / `pod update`
5151
- Follow the [using package flutter guide](https://flutter.dev/docs/development/packages-and-plugins/using-packages)
52-
- Search for [other bugs in flutter](https://github.com/flutter/flutter/search?q=MissingPluginException&type=Issues)
53-
like this, other people face the same issue with other plugins so it is likely not sqflite related
52+
- Search for [other bugs in flutter](https://github.com/flutter/flutter/search?q=MissingPluginException&type=Issues)
53+
like this, other people face the same issue with other plugins so it is likely not sqflite related
5454

5555
Advanced checks:
56-
- If you are using sqflite in a FCM Messaging context, you might need to [register the plugin earlier](https://github.com/tekartik/sqflite/issues/446).
57-
- if the project was generated a long time ago (2019), you might have to follow the [plugin migration guide](https://flutter.dev/docs/development/packages-and-plugins/plugin-api-migration)
56+
57+
- If you are using sqflite in a FCM Messaging context, you might need
58+
to [register the plugin earlier](https://github.com/tekartik/sqflite/issues/446).
59+
- if the project was generated a long time ago (2019), you might have to follow
60+
the [plugin migration guide](https://flutter.dev/docs/development/packages-and-plugins/plugin-api-migration)
5861
- Check the GeneratedPluginRegistrant file that flutter run should have generated in your project contains
5962
a line registering the plugin.
60-
63+
6164
Android:
6265
```java
6366
SqflitePlugin.registerWith(registry.registrarFor("com.tekartik.sqflite.SqflitePlugin"));
@@ -66,7 +69,7 @@ Advanced checks:
6669
```objective-c
6770
[SqflitePlugin registerWithRegistrar:[registry registrarForPlugin:@"SqflitePlugin"]];
6871
```
69-
- Check MainActivity.java (Android) contains a call to
72+
- Check MainActivity.java (Android) contains a call to
7073
GeneratedPluginRegistrant asking it to register itself. This call should be made from the app
7174
launch method (onCreate).
7275
```java
@@ -78,7 +81,7 @@ Advanced checks:
7881
}
7982
}
8083
```
81-
- Check AppDelegate.m (iOS) contains a call to
84+
- Check AppDelegate.m (iOS) contains a call to
8285
GeneratedPluginRegistrant asking it to register itself. This call should be made from the app
8386
launch method (application:didFinishLaunchingWithOptions:).
8487
```objective-c
@@ -87,32 +90,41 @@ Advanced checks:
8790
return [super application:application didFinishLaunchingWithOptions:launchOptions];
8891
}
8992
```
90-
- If it happens to Android release mode, make sure to [remove shrinkResources
91-
true and minifyEnabled true lines in build.gradle](https://github.com/tekartik/sqflite/issues/452#issuecomment-655602329) to solve the problem.
93+
- If it happens to Android release mode, make sure to [remove shrinkResources
94+
true and minifyEnabled true lines in build.gradle](https://github.com/tekartik/sqflite/issues/452#issuecomment-655602329)
95+
to solve the problem.
9296
93-
Before raising this issue, try adding another well established plugin (the simplest being
97+
Before raising this issue, try adding another well established plugin (the simplest being
9498
`path_provider` or `shared_preferences`) to see if you get the error here as well.
9599
96-
## Warning database has been locked for...
100+
## Warning database has been locked for...
97101
98102
If you get this output in debug mode:
99103
100-
> Warning database has been locked for 0:00:10.000000. Make sure you always use the transaction object for database operations during a transaction
104+
> Warning database has been locked for 0:00:10.000000. Make sure you always use the transaction object for database
105+
> operations during a transaction
101106
102107
One common mistake is to use the db object in a transaction:
103108
104109
```dart
105-
await db.transaction((txn) async {
106-
// DEADLOCK HERE
107-
await db.insert('my_table', {'name': 'my_name'});
110+
await
111+
db.transaction
112+
(
113+
(txn) async {
114+
// DEADLOCK HERE
115+
await db.insert('my_table', {'name': 'my_name'});
108116
});
109117
```
118+
110119
...instead of using the correct transaction object (below named `txn`):
111120

112121
```dart
113-
await db.transaction((txn) async {
114-
// Ok!
115-
await txn.insert('my_table', {'name': 'my_name'});
122+
await
123+
db.transaction
124+
(
125+
(txn) async {
126+
// Ok!
127+
await txn.insert('my_table', {'name': 'my_name'});
116128
});
117129
```
118130

@@ -121,7 +133,9 @@ await db.transaction((txn) async {
121133
A quick way to view SQL commands printed out is to call before opening any database
122134

123135
```dart
124-
await Sqflite.devSetDebugModeOn(true);
136+
await
137+
Sqflite.devSetDebugModeOn
138+
(true);
125139
```
126140

127141
This call is on purpose deprecated to force removing it once the SQL issues has been resolved.
@@ -230,7 +244,7 @@ post_install do |installer|
230244
end
231245
```
232246

233-
you need to have
247+
you need to have
234248
(11 is used here, but you might want to specify a higher platform):
235249

236250
```
@@ -266,6 +280,41 @@ target 'Runner' do
266280
end
267281
```
268282

283+
## Runtime exception
284+
285+
### Json1 extension
286+
287+
```
288+
DatabaseException: DatabaseException(no such function: JSON_OBJECT)
289+
```
290+
291+
I could not find the details of what each built-in version includes (for
292+
example the version os SQLite for each Android OS version
293+
here https://developer.android.com/reference/android/database/sqlite/package-summary)
294+
but I doubt any of them include the json1 extension.
295+
296+
json1 extension requires at least of SQLite 3.38.0 (2021-02-09) (https://www.sqlite.org/json1.html)
297+
298+
`sqflite` uses the SQLite available on the platform. It does not ship/bundle any additional SQLite library. You can get the
299+
version using `SELECT sqlite_version()`:
300+
301+
```dart
302+
print((await db.rawQuery('SELECT sqlite_version()')).first.values.first);
303+
```
304+
305+
which should give a version formatted like this:
306+
307+
```
308+
3.22.0
309+
```
310+
311+
Unfortunately the version of SQLite depends on the OS version.
312+
313+
You could get a more recent version using [`sqflite_common_ffi`](https://pub.dev/packages/sqflite_common_ffi).
314+
315+
You could then add [`sqlite3_flutter_libs`](https://pub.dev/packages/sqlite3_flutter_libs) for ios/android or include your own
316+
sqlite shared library for desktop or mobile (one for each platform).
317+
269318
## Error in Flutter web
270319

271320
Look at package [sqflite_common_ffi_web](https://pub.dev/packages/sqflite_common_ffi_web) for experimental Web support.

0 commit comments

Comments
 (0)