tekartik / sqflite

SQLite flutter plugin
BSD 2-Clause "Simplified" License
2.88k stars 527 forks source link

Macos - SqfliteFfiException(sqlite_error: 14, , open_failed: SqliteException(14): while opening the database, bad parameter or other API misuse, bad parameter or other API misuse (code 21)}) #1114

Closed pradeepjunglee closed 5 months ago

pradeepjunglee commented 5 months ago
SqfliteFfiException(sqlite_error: 14, , open_failed: SqliteException(14): while opening the database, bad parameter or other API misuse, bad parameter or other API misuse (code 21)}) DatabaseException(open_failed: SqliteException(14): while opening the database, bad parameter or other API misuse, bad parameter or other API misuse (code 21))
2024-06-18T10:41:39.370125: --------->>>>>>>
2024-06-18T10:41:39.370127: #0 responseToResultOrThrow (package
/src/method_call.dart:123)
#1 SqfliteIsolate.handle (package
/src/isolate.dart:33)
<asynchronous suspension>
#2 _isolateHandle (package
/src/database_factory_ffi_io.dart:94)
<asynchronous suspension>
#3 ffiMethodCallhandleInIsolate (package
/src/database_factory_ffi_io.dart:49)
<asynchronous suspension>
#4 _SqfliteDatabaseFactoryImpl.invokeMethod (package
/src/mixin/factory.dart:22)
<asynchronous suspension>
#5 SqfliteDatabaseMixin.openDatabase (package
/src/database_mixin.dart:821)
<asynchronous suspension>
#6 SqfliteDatabaseMixin.doOpen (package
/src/database_mixin.dart:935)
<asynchronous suspension>
#7 SqfliteDatabaseOpenHelper.openDatabase (package
/src/database.dart:46)
<asynchronous suspension>
#8 SqfliteDatabaseFactoryMixin.openDatabase.<anonymous closure> (package
/src/factory_mixin.dart:112)
<asynchronous suspension>
#9 ReentrantLock.synchronized.<anonymous closure> (package
/src/reentrant_lock.dart:37)
<asynchronous suspension>
#10 BasicLock.synchronized (package
/src/basic_lock.dart:33)
<asynchronous suspension>

flutter doctor -v

[!] Flutter (Channel [user-branch], 3.13.0, on macOS 14.5 23F79 darwin-arm64, locale en-IN)
    ! Flutter version 3.13.0 on channel [user-branch] at /Users/pradeep.arjunan/Documents/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
    • Framework revision efbf63d9c6 (10 months ago), 2023-08-15 21:05:06 -0500
    • Engine revision 1ac611c64e
    • Dart version 3.1.0
    • DevTools version 2.25.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/pradeep.arjunan/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 15.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C65
    ✗ Unable to get list of installed Simulator runtimes.
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.5 23F79 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 126.0.6478.57

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.
alextekartik commented 5 months ago

Hard to help without seeing some code.

Please check and ensure that:

Solutions:

pradeepjunglee commented 5 months ago

Hi @alextekartik, thank you for the swift reply. The path_provider helped resolve the issue. I've included the code snippet below in case anyone else encounters this problem:

import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart' as sqflite;
import 'package:path/path.dart' as path;

Future<AppDatabase> build() async {
  final Directory documentsDirectory = await getApplicationDocumentsDirectory();
  await documentsDirectory.create(recursive: true);

  final dbPath = name != null
      ? Platform.isMacOS
          ? path.join(documentsDirectory.path, name)
          : await sqfliteDatabaseFactory.getDatabasePath(name!)
      : ':memory:';
  final database = _$AppDatabase();
  database.database = await database.open(
    dbPath,
    _migrations,
    _callback,
  );
  return database;
}