0

我正在将数据插入我的数据库并收到以下错误...

flutter: Moor: Sent INSERT INTO add_cash (name, amount, date, frequency, is_deleted) VALUES (?, ?, ?, ?, ?) with args [income, 100000, 1573102800, once, 0]

问号是否表示数据未插入数据库

这是将数据发送到数据库的按钮

CupertinoButton.filled(
  onPressed: () {
    scakey.currentState.onItemTapped(1);
    createAddCash();
  },
  child: Text('ADD CASH'),
),
void createAddCash() async {
  final database = Provider.of<AppDatabase>(context);
  final task = AddCashData(
      name: oneController.text,
      amount: int.parse(twoController.text),
      date: selectedDate,
      frequency: selectedItem,
      isDeleted: false);
  database.insertAddCash(task);
}

这是我的数据库

class AddCash extends Table {
  IntColumn get id => integer().autoIncrement()();
  TextColumn get name => text()();
  IntColumn get amount => integer()();
  DateTimeColumn get date => dateTime()();
  TextColumn get frequency => text()();
  BoolColumn get isDeleted => boolean()();
}


@UseMoor(tables: [AddCash])
class AppDatabase extends _$AppDatabase {
  AppDatabase()
      // Specify the location of the database file
      : super(
          (FlutterQueryExecutor.inDatabaseFolder(
            path: 'db.sqlite',
            // Good for debugging - prints SQL in the console
            logStatements: true,
          )),
        );
  @override
  int get schemaVersion => 1;

  Future insertAddCash(AddCashData addCashData) =>
      into(addCash).insert(addCashData);
}
4

1 回答 1

1

问号是否表示数据未插入数据库

不,这不是错误消息。问号表示将存储到数据库的参数。我建议您try-catch 在代码之间添加,以便您检查错误是什么。

  try {
    final task = AddCashData(...);
    database.insertAddCash(task);
   } catch (e) {
    print(e.toStirng()); // this line will be printed if there is any errors 
   }
于 2019-11-21T13:13:36.667 回答