This commit is contained in:
Hamza-Ayed
2024-12-08 18:16:31 +03:00
parent 630d0c4afb
commit e0c242bd77
34 changed files with 1876 additions and 1345 deletions

View File

@@ -37,18 +37,21 @@ class DbSql {
latitude REAL,
longitude REAL,
name TEXT UNIQUE,
rate TEXT
rate TEXT,
createdAt TEXT
)
''');
await db.execute('DROP TABLE IF EXISTS ${TableName.recentLocations}');
await db.execute('''
CREATE TABLE IF NOT EXISTS ${TableName.recentLocations}(
id INTEGER PRIMARY KEY AUTOINCREMENT,
latitude REAL,
longitude REAL,
name TEXT ,
rate TEXT
)
''');
CREATE TABLE ${TableName.recentLocations}(
id INTEGER PRIMARY KEY AUTOINCREMENT,
latitude REAL,
longitude REAL,
name TEXT,
rate TEXT,
createdAt TEXT
)
''');
await db.execute('''
CREATE TABLE IF NOT EXISTS ${TableName.driverOrdersRefuse}(
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -97,6 +100,34 @@ class DbSql {
return await db.insert(table, map);
}
Future<int> insertMapLocation(Map<String, dynamic> map, String table) async {
Database db = await instance.database;
// Check if the record already exists (based on latitude, longitude, and name)
var existing = await db.query(
table,
where: 'latitude = ? AND longitude = ? AND name = ?',
whereArgs: [map['latitude'], map['longitude'], map['name']],
);
if (existing.isNotEmpty) {
// If record exists, update the createdAt field with the current timestamp
var updatedMap = Map<String, dynamic>.from(map);
updatedMap['createdAt'] =
DateTime.now().toIso8601String(); // Update timestamp
return await db.update(
table,
updatedMap,
where: 'id = ?',
whereArgs: [existing.first['id']], // Update the existing row
);
} else {
// If record doesn't exist, insert new record with the current timestamp
map['createdAt'] = DateTime.now().toIso8601String();
return await db.insert(table, map);
}
}
Future<int> updateData(Map<String, dynamic> map, String table, int id) async {
Database db = await instance.database;