dart_sqlite3 0.3.0

dart_sqlite3 #

It is from Dart SDK v2.8.0-dev6.0 ( https://github.com/dart-lang/sdk/tree/master/samples/ffi/sqlite ).

Prerequirement #

For Linux, you should make sure, sqlite dev lib installed on your system. For example, there are packages for ubuntu.

% sudo apt-get install sqlite3 libsqlite3-dev

For Mac, user can install with brew.

% brew install sqlite3 

For 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)

Example #

This is a sample dart program for SQLite3.

import "package:dart_sqlite3/dart_sqlite3.dart";

void main() {
  Database d = Database("test.db");
  d.execute("drop table if exists stocks;");
  d.execute("""
      create table stocks (
        date text not null,
        trans text not null,
        symbol text not null,
        qty integer,
        price real
      );""");
  d.execute("""
      insert into stocks (date, trans, symbol, qty, price)
      values
        ('2006-01-05','BUY','RHAT',100,35.14),
        ('2006-01-05','SELL','IBM',1000,45)
      ;""");
  Result result = d.query("select * from stocks where symbol = 'IBM';");
  for (Row r in result) {
    String date = r.readColumn("date");
    String trans = r.readColumn("trans");
    String symbol = r.readColumn("symbol");
    int qty = r.readColumnAsInt("qty");
    double price = r.readColumnAsDouble("price");
    print("$date $trans $symbol $qty $price");
  }

  //d.execute("drop table stocks;");
  d.close();
}

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).

Authors #

Daco Harkes dacoharkes@google.com

Samir Jindel sjindel@google.com

Benjamin Jung bsjung@google.com

License #

Copyright 2012, the Dart project authors.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

example/main.dart

import "package:dart_sqlite3/dart_sqlite3.dart";

void main() {
  Database d = Database("test.db");
  d.execute("drop table if exists stocks;");
  d.execute("""
      create table stocks (
        date text not null,
        trans text not null,
        symbol text not null,
        qty integer,
        price real
      );""");
  d.execute("""
      insert into stocks (date, trans, symbol, qty, price)
      values
        ('2006-01-05','BUY','RHAT',100,35.14),
        ('2006-01-05','SELL','IBM',1000,45)
      ;""");
  Result result = d.query("select * from stocks where symbol = 'IBM';");
  for (Row r in result) {
    String date = r.readColumn("date");
    String trans = r.readColumn("trans");
    String symbol = r.readColumn("symbol");
    int qty = r.readColumnAsInt("qty");
    double price = r.readColumnAsDouble("price");
    print("$date $trans $symbol $qty $price");
  }

  //d.execute("drop table stocks;");
  d.close();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dart_sqlite3: ^0.3.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_sqlite3/dart_sqlite3.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
45
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Jul 8, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package not compatible with runtime flutter-web on web

Because:

  • package:dart_sqlite3/dart_sqlite3.dart that imports:
  • package:dart_sqlite3/src/database.dart that imports:
  • package:dart_sqlite3/src/bindings/types.dart that imports:
  • dart:ffi

Package not compatible with runtime js

Because:

  • package:dart_sqlite3/dart_sqlite3.dart that imports:
  • package:dart_sqlite3/src/database.dart that imports:
  • package:dart_sqlite3/src/bindings/types.dart that imports:
  • dart:ffi

Health suggestions

Fix lib/src/database.dart. (-4.41 points)

Analysis of lib/src/database.dart reported 9 hints, including:

line 127 col 18: The value of the field '_database' isn't used.

line 129 col 28: The value of the field '_statement' isn't used.

line 130 col 26: The value of the field '_columnIndices' isn't used.

line 132 col 7: The value of the field '_currentRow' isn't used.

line 132 col 7: Don't explicitly initialize variables to null.

Fix lib/src/ffi/dylib_utils.dart. (-0.50 points)

Analysis of lib/src/ffi/dylib_utils.dart reported 1 hint:

line 11 col 5: DO use curly braces for all flow control structures.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
ffi ^0.1.3 0.1.3
Dev dependencies
test ^1.5.3