dart-sdk/samples/ffi/sqlite
Lasse R.H. Nielsen 9e76983782 Reland "Add more interface and final modifiers to dart:core."
This is another reland of 4f8333e80e.
Third time is the charm.

CoreLibraryReviewExempt: Reland of accepted CL.
Change-Id: I4ea8326af91c168b044d252162571d3fe697e4b0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289826
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2023-03-30 20:34:09 +00:00
..
docs [samples/ffi] Update sqlite-tutorial 2023-02-21 21:23:43 +00:00
example [vm/ffi] Migrate package:ffi Utf8 and Utf16 uses 2021-02-11 13:13:32 +00:00
lib Reland "Add more interface and final modifiers to dart:core." 2023-03-30 20:34:09 +00:00
test fix ffi sample diagnostics 2023-03-30 19:19:21 +00:00
.gitignore Revert "[samples/ffi] Generate sqlite3 bindings with package:ffigen" 2020-08-11 19:38:18 +00:00
pubspec.yaml [samples/ffi] Update sqlite sample 2022-06-07 12:11:39 +00:00
README.md [samples/ffi] Update sqlite sample 2022-06-07 12:11:39 +00:00

Sample code dart:ffi

This is an illustrative sample for how to use dart:ffi.

Prerequirement

For Windows, Linux, and MacOS, you should make sure, sqlite dev lib installed on your system.

Windows user can download dll from https://www.sqlite.org/download.html

If you do not have any sqlite3.dll or so file, you may found error message:

Unhandled exception:
Invalid argument(s): Failed to load dynamic library (126)
#0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:13:55)
#1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)

Building and Running this Sample

Building and running this sample is done through pub. Running dart run example/main should produce the following output.

$ dart run example/main
1 Chocolade chip cookie Chocolade cookie foo
2 Ginger cookie null 42
3 Cinnamon roll null null
1 Chocolade chip cookie Chocolade cookie foo
2 Ginger cookie null 42
expected exception on accessing result data after close: The result has already been closed.
expected this query to fail: no such column: non_existing_column (Code 1: SQL logic error)

Tutorial

A tutorial walking through the code is available in docs/sqlite-tutorial.md. For information on how to use this package within a Flutter app, see docs/android.md. (Note: iOS is not yet supported).