如何在 flutter 中从 sqlite 获取最后一个条目?
How to get last entry from sqlite in flutter?
我在SO中看到了很多答案,但都与android有关。
我想获取最后输入的ID table.This是我的用户table:
await db.execute("CREATE TABLE User("
"userId INTEGER PRIMARY KEY,"
"first_name TEXT,"
"last_name TEXT,"
"user_password TEXT,"
"mobile_no TEXT,"
"email_id TEXT,"
")");
print("User Table created");
final database = await db;
final data = await database.rawQuery('SELECT * FROM User');
final lastId = data.last['userId'];
您可以使用 Order by
和 Limit
关键字。我现在无法自行测试,但 google 表示 sqflite 支持它们。应该看起来像这样:
db.rawQuery("SELECT * FROM $table ORDER BY userId DESC LIMIT 1");
或者像这样:
db.query(
dbTable,
orderBy: "userId DESC",
limit: 1
);
我在SO中看到了很多答案,但都与android有关。
我想获取最后输入的ID table.This是我的用户table:
await db.execute("CREATE TABLE User("
"userId INTEGER PRIMARY KEY,"
"first_name TEXT,"
"last_name TEXT,"
"user_password TEXT,"
"mobile_no TEXT,"
"email_id TEXT,"
")");
print("User Table created");
final database = await db;
final data = await database.rawQuery('SELECT * FROM User');
final lastId = data.last['userId'];
您可以使用 Order by
和 Limit
关键字。我现在无法自行测试,但 google 表示 sqflite 支持它们。应该看起来像这样:
db.rawQuery("SELECT * FROM $table ORDER BY userId DESC LIMIT 1");
或者像这样:
db.query(
dbTable,
orderBy: "userId DESC",
limit: 1
);