如何在我的控制台中打印我插入的值? (颤振 | sqflite)

How do I print my inserted values in my console? (Flutter | sqflite)

我目前能够成功地将值插入到系统中,但是,我希望能够在我的控制台中显示插入的值。 如何在我的控制台中打印插入的值?我尝试这样做,但只能获得插入值的“id”。我不确定如何打印 table.

中的其余值

这是我的插入代码:

  // Insert Operation: Insert a Note object to database
  Future<int> insertNote(Note note) async {
    //getting db reference
    Database db = await database;
    //running the insert command
    //our data from note is converted to map object
    var result = await db.insert(noteTable, note.toMap());
    if (kDebugMode) {
      print('Note data inserted successfully: $result');
    } 
    return result;
  }

这是我用来将 Note 对象转换为 Map 对象的代码

  // Convert a Note object into a Map object
  Map<String, dynamic> toMap() {
    var map = <String,dynamic>{};
    if (id != null) {
      map['id'] = _id;
    }
    map['title'] = _title;
    map['description'] = _description;
    map['priority'] = _priority;
    map['color'] = _color;
    map['date'] = _date;

    return map;
  }

这是我控制台上的结果:

当您在数据库中插入行时,您只会在 return 中获得行 ID。

所以如果你想打印最近的数据,那么你必须使用 id 查询你的数据库,或者你也可以打印所有可用的数据。

对于table

db.query("table_name);

db.rawQuery('SELECT * FROM "table"');

对于特定的 id

db.query("table_name",where: '$rowId = ?', whereArgs: [id]);

db.rawQuery('SELECT * FROM "table" WHERE $rowId = $id');

更多信息请查看:https://pub.dev/packages/sqflite