setReal method
Implementation
Future<dynamic> setReal(tableName, double value) async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, "$tableName.db");
Database _database = await openDatabase(path, version: _databaseVersion,
onCreate: (Database db, int version) async {
await db.execute(
'CREATE TABLE ${tableName}1 (${tableName}_key INTEGER, $tableName REAL)');
});
Database db = _database;
var getValue;
getValue = Sqflite.firstIntValue(
await db.rawQuery('SELECT COUNT(*) FROM ${tableName}1'));
if (getValue == 0) {
print("data will be inserted");
return await db.transaction((txn) async {
return await txn.rawInsert(
'INSERT INTO ${tableName}1(${tableName}_key, $tableName) VALUES(?, ?)',
[1, value]);
});
} else {
print("data will be updated");
return await db.rawUpdate(
'UPDATE ${tableName}1 SET ${tableName}_key = ?, $tableName = ?',
[1, value]);
}
}