drift icon indicating copy to clipboard operation
drift copied to clipboard

CHECK constraint fails in profile/release mode

Open z-tc opened this issue 6 years ago • 5 comments

I have following object which is inserted into DB:

class Devices extends Table {
  TextColumn get id => text()();

  TextColumn get name => text()();
  TextColumn get manufacturer => text()();
  TextColumn get description => text().nullable()();
  TextColumn get imageUrl => text().nullable()();
  TextColumn get location => text()();

  RealColumn get latitude => real()();
  RealColumn get longitude => real()(); 

  DateTimeColumn get dateAdded => dateTime().nullable()();

  BoolColumn get isFavorite => boolean().nullable()();

  @override
  Set<Column> get primaryKey => {id};
}

During the debug, all crud operations are performed without any issues, but in release or profile mode, I get the following exception: E/flutter ( 6250): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SqliteException(275): CHECK constraint failed: devices, constraint failed (code 275) E/flutter ( 6250): #0 PreparedStatement.execute (package:moor_ffi/src/impl/prepared_statement.dart:107) E/flutter ( 6250): #1 _VmDelegate._runWithArgs (package:moor_ffi/src/vm_database.dart:72) E/flutter ( 6250): #2 _VmDelegate.runUpdate (package:moor_ffi/src/vm_database.dart:90) E/flutter ( 6250): #3 _ExecutorWithQueryDelegate.runUpdate.<anonymous closure> (package:moor/src/runtime/executor/helpers/engines.dart:51) E/flutter ( 6250): #4 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:32) E/flutter ( 6250): #5 _ExecutorWithQueryDelegate._synchronized (package:moor/src/runtime/executor/helpers/engines.dart:22) E/flutter ( 6250): #6 _ExecutorWithQueryDelegate.runUpdate (package:moor/src/runtime/executor/helpers/engines.dart:49) E/flutter ( 6250): #7 LazyDatabase.runUpdate (package:moor/src/utils/lazy_database.dart:68) E/flutter ( 6250): #8 UpdateStatement._performQuery.<anonymous closure> (package:moor/src/runtime/query_builder/statements/update.dart:35) E/flutter ( 6250): #9 UpdateStatement._performQuery.<anonymous closure> (package:moor/src/runtime/query_builder/statements/update.dart:34) E/flutter ( 6250): #10 QueryEngine.doWhenOpened.<anonymous closure> (package:moor/src/runtime/api/query_engine.dart:98) E/flutter ( 6250): #11 _rootRunUnary (dart:async/zone.dart:1192) E/flutter ( 6250): #12 _CustomZone.runUnary (dart:async/zone.dart:1085) E/flutter ( 6250): #13 _FutureListener.handleValue (dart:async/future_impl.dart:141) E/flutter ( 6250): #14 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682) E/flutter ( 6250): #15 Future._propagateToListeners (dart:async/future_impl.dart:711) E/flutter ( 6250): #16 Future._completeWithValue (dart:async/future_impl.dart:526) E/flutter ( 6250): #17 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:36) E/flutter ( 6250): #18 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:298) E/flutter ( 6250): #19 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:0) E/flutter ( 6250): <asynchronous suspension> E/flutter ( 6250):

Any ideas why is this happening? Thanks!

z-tc avatar Jun 30 '20 10:06 z-tc

Are you building on Windows and testing on a 32-bit ARM device? If so, you're likely seeing a Dart compiler bug. Switching to the Flutter beta channel should help.

simolus3 avatar Jun 30 '20 10:06 simolus3

Just switched to beta channel, but I get the same error. I am using a real device with ARMv7-A CPU architecture.

z-tc avatar Jun 30 '20 11:06 z-tc

Thanks - and you're building on Windows, right?

To verify that you're seeing https://github.com/flutter/flutter/issues/54948, can you put this at the beginning of your main method:

import 'package:moor_ffi/database.dart' as ffi;

void main() {
  final db = ffi.Database.memory();
  final stmt = db.prepare("SELECT printf('%x', ?) AS r");

  final result = stmt.select([1]).first['r'] as String;
  print(result);
  db.close();
}

It should print 1, but if it prints something like 100000000 it's because of the permutation bug.

simolus3 avatar Jun 30 '20 13:06 simolus3

Yes, sorry, I am building on Windows, and I tried the above code - it prints 100000000. So it is https://github.com/flutter/flutter/issues/54948 issue... Hmm, now I really have no idea how to overcome it :)

z-tc avatar Jul 01 '20 07:07 z-tc

Uh oh. Can you try to switch to the master channel and see if it's fixed there (maybe also try a flutter clean)? If that still doesn't work, you could post details about your setup to that issue so that someone from the Flutter/Dart team can look into it. If you need an urgent workaround, you could build your app through a Linux VM or WSL.

I'll close this issue since it's a Dart bug, but let me know if you need anything more.

simolus3 avatar Jul 01 '20 08:07 simolus3