Skip to content

Commit

Permalink
Sync frontend example app
Browse files Browse the repository at this point in the history
  • Loading branch information
Swanseo0 committed Sep 1, 2023
1 parent 0166515 commit 4f69ae8
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 36 deletions.
102 changes: 102 additions & 0 deletions packages/sqflite/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
include: package:flutter_lints/flutter.yaml

# Until there are meta linter rules, each desired lint must be explicitly enabled.
# See: https://github.com/dart-lang/linter/issues/288
#
# For a list of lints, see: http://dart-lang.github.io/linter/lints/
# See the configuration guide for more
# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer
#
# NOTE: Please keep this file in sync with
# https://github.com/flutter/flutter/blob/master/analysis_options.yaml

analyzer:
language:
strict-casts: true
strict-inference: true

errors:
# treat missing required parameters as a warning (not a hint)
missing_required_param: warning
# treat missing returns as a warning (not a hint)
missing_return: warning
# allow having TODOs in the code
todo: ignore
# Ignore errors like
# 'super_goes_last' is a deprecated lint rule and should not be used • included_file_warning
included_file_warning: ignore

linter:
rules:
- always_declare_return_types
- avoid_dynamic_calls
- avoid_empty_else
- avoid_relative_lib_imports
- avoid_shadowing_type_parameters
- avoid_slow_async_io
- avoid_types_as_parameter_names
- await_only_futures
- camel_case_extensions
- camel_case_types
- cancel_subscriptions
- curly_braces_in_flow_control_structures
- directives_ordering
- empty_catches
- hash_and_equals
- collection_methods_unrelated_type
- no_adjacent_strings_in_list
- no_duplicate_case_values
- non_constant_identifier_names
- omit_local_variable_types
- package_api_docs
- package_prefixed_library_names
- prefer_generic_function_type_aliases
- prefer_is_empty
- prefer_is_not_empty
- prefer_iterable_whereType
- prefer_single_quotes
- prefer_typing_uninitialized_variables
- sort_child_properties_last
- test_types_in_equals
- throw_in_finally
- unawaited_futures
- unnecessary_null_aware_assignments
- unnecessary_statements
- unrelated_type_equality_checks
- unsafe_html
- valid_regexps

- constant_identifier_names
- control_flow_in_finally
- empty_statements
- implementation_imports
- overridden_fields
- package_names
- prefer_const_constructors
- prefer_initializing_formals
- prefer_void_to_null
#
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_return_types_on_setters
- empty_constructor_bodies
- library_names
- library_prefixes
- prefer_adjacent_string_concatenation
- prefer_collection_literals
- prefer_contains
- slash_for_doc_comments
- type_init_formals
- unnecessary_const
- unnecessary_new
- unnecessary_null_in_if_null_operators
- use_rethrow_when_possible
# === doc rules ===
- public_member_api_docs
#
# - prefer_final_locals
- sort_constructors_first
- sort_unnamed_constructors_first

43 changes: 25 additions & 18 deletions packages/sqflite/example/lib/exp_test_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class ExpTestPage extends TestPage {
});

test('Dart2 query', () async {
// await Sqflite.devSetDebugModeOn(true);
final path = await initDeleteDb('exp_dart2_query.db');
final db = await openDatabase(path);

Expand Down Expand Up @@ -337,6 +338,7 @@ class ExpTestPage extends TestPage {
});

test('Issue#64', () async {
// await Sqflite.devSetDebugModeOn(true);
final path = await initDeleteDb('issue_64.db');

// delete existing if any
Expand Down Expand Up @@ -378,6 +380,8 @@ class ExpTestPage extends TestPage {
});

test('sql dump file', () async {
// await Sqflite.devSetDebugModeOn(true);

// try to import an sql dump file (not working)
final path = await initDeleteDb('sql_file.db');
final db = await openDatabase(path);
Expand All @@ -395,9 +399,10 @@ INSERT INTO test (value) VALUES (10);
// {'value': 10}
// ];
final result = await db.rawQuery('SELECT * FROM $table');
print(json.encode(result));

// However (at least on Android)
// result is empty, only the first statement is executed
print(json.encode(result));
expect(result, isEmpty);
} finally {
await db.close();
Expand Down Expand Up @@ -476,9 +481,9 @@ CREATE TABLE test (
final db2Path = await initDeleteDb('attach2.db');

// Create some data on db1 and close it
final db1 = await databaseFactory.openDatabase(db1Path);
var db1 = await databaseFactory.openDatabase(db1Path);
try {
final batch = db1.batch();
var batch = db1.batch();
batch.execute('CREATE TABLE table1 (col1 INTEGER)');
batch.insert('table1', {'col1': 1234});
await batch.commit();
Expand All @@ -488,10 +493,10 @@ CREATE TABLE test (

// Open a new db2 database, attach db1 and query it

final db2 = await databaseFactory.openDatabase(db2Path);
var db2 = await databaseFactory.openDatabase(db2Path);
try {
await db2.execute('ATTACH DATABASE \'$db1Path\' AS db1');
final rows = await db2.query('db1.table1');
var rows = await db2.query('db1.table1');
expect(rows, [
{'col1': 1234}
]);
Expand All @@ -501,7 +506,7 @@ CREATE TABLE test (
});

/// fts4
final fts4Supports = supportsCompatMode;
var fts4Supports = supportsCompatMode;
if (fts4Supports) {
test('Issue#206', () async {
//await Sqflite.devSetDebugModeOn(true);
Expand Down Expand Up @@ -569,16 +574,17 @@ CREATE TABLE test (
});

Future<void> testBigBlog(int size) async {
// await Sqflite.devSetDebugModeOn(true);
final path = await initDeleteDb('big_blob.db');
final db = await openDatabase(path, version: 1,
var db = await openDatabase(path, version: 1,
onCreate: (Database db, int version) async {
await db
.execute('CREATE TABLE Test (id INTEGER PRIMARY KEY, value BLOB)');
});
try {
final blob =
var blob =
Uint8List.fromList(List.generate(size, (index) => index % 256));
final id = await db.insert('Test', {'value': blob});
var id = await db.insert('Test', {'value': blob});

/// Get the value field from a given id
Future<Uint8List> getValue(int id) async {
Expand All @@ -598,15 +604,16 @@ CREATE TABLE test (
});

Future<void> testBigText(int size) async {
// await Sqflite.devSetDebugModeOn(true);
final path = await initDeleteDb('big_text.db');
final db = await openDatabase(path, version: 1,
var db = await openDatabase(path, version: 1,
onCreate: (Database db, int version) async {
await db
.execute('CREATE TABLE Test (id INTEGER PRIMARY KEY, value TEXT)');
});
try {
final text = List.generate(size, (index) => 'A').join();
final id = await db.insert('Test', {'value': text});
var text = List.generate(size, (index) => 'A').join();
var id = await db.insert('Test', {'value': text});

/// Get the value field from a given id
Future<String> getValue(int id) async {
Expand All @@ -624,7 +631,7 @@ CREATE TABLE test (
test('big text 800 Ko', () async {
await testBigText(800000);
});

/*
test('big blob 1500 Ko (fails on Android sqlite)', () async {
await testBigBlog(1500000);
});
Expand All @@ -634,7 +641,7 @@ CREATE TABLE test (
test('big blob 15 Mo (fails on Android sqlite)', () async {
await testBigBlog(15000000);
});

*/
/*
test('Isolate', () async {
// This test does not work yet
Expand Down Expand Up @@ -692,10 +699,10 @@ CREATE TABLE test (
});
*/
test('missing parameter', () async {
final db = await openDatabase(inMemoryDatabasePath);
var db = await openDatabase(inMemoryDatabasePath);
await db.execute(
'CREATE TABLE IF NOT EXISTS foo (id int primary key, name text)');
final missingParameterShouldFail = !supportsCompatMode;
var missingParameterShouldFail = !supportsCompatMode;
try {
await db.rawQuery('SELECT * FROM foo WHERE id=?');
} catch (e) {
Expand All @@ -707,7 +714,7 @@ CREATE TABLE test (
// Pragma has to use rawQuery...why, on sqflite Android
test('wal', () async {
// await Sqflite.devSetDebugModeOn(true);
final db = await openDatabase(inMemoryDatabasePath);
var db = await openDatabase(inMemoryDatabasePath);
try {
await db.execute('PRAGMA journal_mode=WAL');
} catch (e) {
Expand All @@ -717,7 +724,7 @@ CREATE TABLE test (
await db.execute('CREATE TABLE test (id INTEGER)');
await db.insert('test', <String, Object?>{'id': 1});
try {
final resultSet = await db.rawQuery('SELECT id FROM test');
var resultSet = await db.rawQuery('SELECT id FROM test');
expect(resultSet, [
{'id': 1},
]);
Expand Down
16 changes: 8 additions & 8 deletions packages/sqflite/example/lib/manual_test_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class _ManualTestPageState extends State<ManualTestPage> {

Future<void> _addAndQuery({int? msDelay, bool? noSynchronized}) async {
// await databaseFactory.debugSetLogLevel(sqfliteLogLevelVerbose);
final db = await _openDatabase();
var db = await _openDatabase();

// ignore: invalid_use_of_visible_for_testing_member
db.internalsDoNotUseSynchronized = noSynchronized ?? false;
Expand All @@ -71,7 +71,7 @@ class _ManualTestPageState extends State<ManualTestPage> {
'CREATE TABLE IF NOT EXISTS Task(id INTEGER PRIMARY KEY, name TEXT)');
await txn.execute('INSERT INTO Task(name) VALUES (?)',
['task ${DateTime.now().toIso8601String()}']);
final count =
var count =
firstIntValue(await txn.query('Task', columns: [sqlCountColumn]));
unawaited(showToast('$count task(s)'));
if (msDelay != null) {
Expand All @@ -89,7 +89,7 @@ class _ManualTestPageState extends State<ManualTestPage> {

final results = await db.rawQuery('select sqlite_version()');
print('select sqlite_version(): $results');
final version = results.first.values.first;
var version = results.first.values.first;
print('sqlite version: $version');
await db.close();
if (mounted) {
Expand All @@ -99,7 +99,7 @@ class _ManualTestPageState extends State<ManualTestPage> {
}
}, summary: 'select sqlite_version()'),
SqfMenuItem('Factory information', () async {
final info = databaseFactory.toString();
var info = databaseFactory.toString();
print('sqlite database factory: $info');
unawaited(showToast(info));
}, summary: 'toString()'),
Expand Down Expand Up @@ -169,23 +169,23 @@ class _ManualTestPageState extends State<ManualTestPage> {

Future<void> testBigBlog(int size) async {
// await Sqflite.devSetDebugModeOn(true);
final db = await openDatabase(inMemoryDatabasePath, version: 1,
var db = await openDatabase(inMemoryDatabasePath, version: 1,
onCreate: (Database db, int version) async {
await db
.execute('CREATE TABLE Test (id INTEGER PRIMARY KEY, value BLOB)');
});
try {
final blob =
var blob =
Uint8List.fromList(List.generate(size, (index) => index % 256));
final id = await db.insert('Test', {'value': blob});
var id = await db.insert('Test', {'value': blob});

/// Get the value field from a given id
Future<Uint8List> getValue(int id) async {
return ((await db.query('Test', where: 'id = $id')).first)['value']
as Uint8List;
}

final ok = (await getValue(id)).length == blob.length;
var ok = (await getValue(id)).length == blob.length;
if (mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('$size: $ok')));
Expand Down
9 changes: 5 additions & 4 deletions packages/sqflite/example/lib/open_test_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:sqflite/src/database_mixin.dart' // ignore: implementation_impor
import 'package:sqflite/src/factory_mixin.dart' // ignore: implementation_imports
show
SqfliteDatabaseFactoryMixin;
import 'package:sqflite_tizen_example/utils.dart';
import 'package:synchronized/synchronized.dart';

import 'src/common_import.dart';
Expand Down Expand Up @@ -910,22 +911,22 @@ class OpenTestPage extends TestPage {
await db.close();
});
test('Read/write bytes', () async {
final path = await initDeleteDb('database_read_bytes.db');
final writtenPath = await initDeleteDb('database_written_bytes.db');
var path = await initDeleteDb('database_read_bytes.db');
var writtenPath = await initDeleteDb('database_written_bytes.db');
var db = await factory.openDatabase(path,
options: OpenDatabaseOptions(
version: 1,
onCreate: (db, version) async {
await db.execute(
'CREATE TABLE Test(id INTEGER PRIMARY KEY, value TEXT)');
}));
const textValue = 'value_to_read';
var textValue = 'value_to_read';
await db.insert('Test', {'id': 1, 'value': textValue});
expect(await db.query('Test'), [
{'id': 1, 'value': textValue}
]);
await db.close();
final bytes = await factory.readDatabaseBytes(path);
var bytes = await factory.readDatabaseBytes(path);
//expect(bytes.length, 8192);
expect(bytes.sublist(0, 4), [
83,
Expand Down
Loading

0 comments on commit 4f69ae8

Please sign in to comment.