I am currently successfully able to insert values into the system, however, I want to be able to display the inserted values in my console. How do I print the inserted values in my console? I tried doing so and I was only able to get the "id" of the inserted value. I'm not sure how to print the rest of the values in the table.
Here's my insert code:
// 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;
}
Here's the code I used to convert the Note object into a Map object
// 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;
}
This is the result on my console:
CodePudding user response:
When you insert row in database you will only get row id in return.
So if you want to print recent data then you have to make a query to your database with id or you can also print all the data available.
For table
db.query("table_name);
or
db.rawQuery('SELECT * FROM "table"');
For specific id
db.query("table_name",where: '$rowId = ?', whereArgs: [id]);
or
db.rawQuery('SELECT * FROM "table" WHERE $rowId = $id');
For more info check : https://pub.dev/packages/sqflite