I have to know a specific row is exist where uidCol column is aaa in tagtable. But I didn't know so I'm just using try~catch block.
What I want to do is to check local DB and if there are no data, fetching from firestore.
What I'm doing is like below
try {
await db.rawQuery('SELECT * FROM tagTable WHERE uidCol="aaa"');
} catch(exception){
await _fetchTagsFromFirestore().catchError((e){
print('FATAL ERROR: ${e.toString()}');
return FETCH_RESULT.FAILURE;
});
}
But I think it is not right way to check row is exist. How can I deal with properly?
I'm assuming you want to check if there's a record that exists with the specified criteria in the database and do something if it does exist.
getting the result from the database and storing in a queryResult:
var queryResult = await db.rawQuery('SELECT * FROM tagTable WHERE uidCol="aaa"');
checking if the result is empty:
result.isNotEmpty ? //do something if the result is not empty here
: []; //else return empty list
Try this it worked for me
var db= DatabaseHelper();
Future<int> getcount(id) async {
var dbclient = await db;
int count = Sqflite.firstIntValue(
await dbclient.rawQuery("SELECT COUNT(*) FROM $cartTable WHERE $columnid=$id"));
return count;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With