diff --git a/floor/test/integration/database.g.dart b/floor/test/integration/database.g.dart index 1d5b7378..26496dc9 100644 --- a/floor/test/integration/database.g.dart +++ b/floor/test/integration/database.g.dart @@ -85,7 +85,7 @@ class _$TestDatabase extends TestDatabase { await database.execute( 'CREATE TABLE IF NOT EXISTS `person` (`id` INTEGER, `custom_name` TEXT NOT NULL, PRIMARY KEY (`id`))'); await database.execute( - 'CREATE TABLE IF NOT EXISTS `dog` (`id` INTEGER, `name` TEXT, `nick_name` TEXT, `owner_id` INTEGER, FOREIGN KEY (`owner_id`) REFERENCES `person` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, PRIMARY KEY (`id`))'); + 'CREATE TABLE IF NOT EXISTS `dog` (`id` INTEGER, `name` TEXT, `nick_name` TEXT, `owner_id` INTEGER, `picture` BLOB, FOREIGN KEY (`owner_id`) REFERENCES `person` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE, PRIMARY KEY (`id`))'); await database.execute( 'CREATE INDEX `index_person_custom_name` ON `person` (`custom_name`)'); @@ -297,7 +297,8 @@ class _$DogDao extends DogDao { 'id': item.id, 'name': item.name, 'nick_name': item.nickName, - 'owner_id': item.ownerId + 'owner_id': item.ownerId, + 'picture': item.picture }); final sqflite.DatabaseExecutor database; @@ -310,7 +311,8 @@ class _$DogDao extends DogDao { row['id'] as int, row['name'] as String, row['nick_name'] as String, - row['owner_id'] as int); + row['owner_id'] as int, + row['picture']); final InsertionAdapter _dogInsertionAdapter; diff --git a/floor/test/integration/database_test.dart b/floor/test/integration/database_test.dart index e2afdc93..ab31db8b 100644 --- a/floor/test/integration/database_test.dart +++ b/floor/test/integration/database_test.dart @@ -1,3 +1,5 @@ +import 'dart:typed_data'; + import 'package:floor/floor.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:matcher/matcher.dart'; @@ -212,7 +214,7 @@ void main() { group('foreign key', () { test('foreign key constraint failed exception', () { - final dog = Dog(null, 'Peter', 'Pete', 2); + final dog = Dog(null, 'Peter', 'Pete', 2, Uint8List(8)); expect(() => dogDao.insertDog(dog), _throwsDatabaseException); }); @@ -220,7 +222,7 @@ void main() { test('find dog for person', () async { final person = Person(1, 'Simon'); await personDao.insertPerson(person); - final dog = Dog(2, 'Peter', 'Pete', person.id); + final dog = Dog(2, 'Peter', 'Pete', person.id, Uint8List(8)); await dogDao.insertDog(dog); final actual = await dogDao.findDogForPersonId(person.id); @@ -231,7 +233,7 @@ void main() { test('cascade delete dog on deletion of person', () async { final person = Person(1, 'Simon'); await personDao.insertPerson(person); - final dog = Dog(2, 'Peter', 'Pete', person.id); + final dog = Dog(2, 'Peter', 'Pete', person.id, Uint8List(8)); await dogDao.insertDog(dog); await personDao.deletePerson(person); diff --git a/floor/test/integration/model/dog.dart b/floor/test/integration/model/dog.dart index 35066a39..f2e3643f 100644 --- a/floor/test/integration/model/dog.dart +++ b/floor/test/integration/model/dog.dart @@ -1,5 +1,8 @@ +import 'dart:typed_data'; + import 'package:floor/floor.dart'; +import '../../test_util/list_helper.dart'; import 'person.dart'; @Entity( @@ -25,7 +28,9 @@ class Dog { @ColumnInfo(name: 'owner_id') final int ownerId; - Dog(this.id, this.name, this.nickName, this.ownerId); + final Uint8List picture; + + Dog(this.id, this.name, this.nickName, this.ownerId, this.picture); @override bool operator ==(Object other) => @@ -35,6 +40,7 @@ class Dog { id == other.id && name == other.name && nickName == other.nickName && + ListHelper.deepEquals(picture, other.picture) && ownerId == other.ownerId; @override @@ -43,6 +49,6 @@ class Dog { @override String toString() { - return 'Dog{id: $id, name: $name, nickName: $nickName, ownerId: $ownerId}'; + return 'Dog{id: $id, name: $name, nickName: $nickName, ownerId: $ownerId, picture: $picture}'; } } diff --git a/floor/test/test_util/list_helper.dart b/floor/test/test_util/list_helper.dart new file mode 100644 index 00000000..ded6f79b --- /dev/null +++ b/floor/test/test_util/list_helper.dart @@ -0,0 +1,22 @@ +import 'dart:typed_data'; + +class ListHelper{ + static bool deepEquals(final Uint8List l1,final Uint8List l2){ + if(identical(l1,l2)){ + return true; + } + if(l1 == null || l2 == null){ + return false; + } + if(l1.length!=l2.length) { + return false; + } + for(int i=0; i < l1.length ; ++i) { + if (l1.elementAt(i) != l2.elementAt(i)) { + return false; + } + } + return true; + } +} + diff --git a/floor_generator/lib/misc/constants.dart b/floor_generator/lib/misc/constants.dart index 9654fd51..e84b513b 100644 --- a/floor_generator/lib/misc/constants.dart +++ b/floor_generator/lib/misc/constants.dart @@ -33,6 +33,7 @@ abstract class SqlType { static const INTEGER = 'INTEGER'; static const TEXT = 'TEXT'; static const REAL = 'REAL'; + static const BLOB = 'BLOB'; } abstract class OnConflictStrategy { diff --git a/floor_generator/lib/processor/entity_processor.dart b/floor_generator/lib/processor/entity_processor.dart index 42bff6b9..6bf74d2f 100644 --- a/floor_generator/lib/processor/entity_processor.dart +++ b/floor_generator/lib/processor/entity_processor.dart @@ -266,6 +266,8 @@ class EntityProcessor extends Processor { return '$parameterValue as String'; } else if (parameterType.isDartCoreInt) { return '$parameterValue as int'; + } else if (parameterType.getDisplayString() == 'Uint8List') { + return '$parameterValue'; } else { return '$parameterValue as double'; // must be double } diff --git a/floor_generator/lib/processor/field_processor.dart b/floor_generator/lib/processor/field_processor.dart index 946b34d5..29687b3c 100644 --- a/floor_generator/lib/processor/field_processor.dart +++ b/floor_generator/lib/processor/field_processor.dart @@ -66,6 +66,8 @@ class FieldProcessor extends Processor { return SqlType.INTEGER; } else if (type.isDartCoreDouble) { return SqlType.REAL; + } else if (type.getDisplayString() == 'Uint8List') { + return SqlType.BLOB; } throw InvalidGenerationSourceError( 'Column type is not supported for $type.',