let AI comment everything because well... yeah...
This commit is contained in:
@@ -4,13 +4,20 @@ import 'package:sqflite/sqflite.dart';
|
||||
import 'dart:io' as io;
|
||||
import 'package:path/path.dart';
|
||||
|
||||
// * Gives the complete functionality for the databases
|
||||
// ! functions may not be named complete correctly
|
||||
// * Database helper for managing excursions
|
||||
// * Provides CRUD operations for both main entries and templates
|
||||
// * Uses SQLite database with two tables:
|
||||
// * - excursion: Stores finalized excursion records
|
||||
// * - excursionTemplates: Stores template entries for quick creation
|
||||
|
||||
/// Database helper class implementing IDb interface
|
||||
/// Handles all database operations for excursions and tracking data
|
||||
class ExcursionDBHelper implements IDb {
|
||||
// Database instance
|
||||
static Database? _excursionDB;
|
||||
|
||||
// checks if the databses are existing and creates them with the initPlaceDatabase function if not
|
||||
/// Get database instance, creating it if necessary
|
||||
/// Returns existing database or initializes a new one
|
||||
@override
|
||||
Future<Database> get dB async {
|
||||
if (_excursionDB != null) {
|
||||
@@ -20,7 +27,8 @@ class ExcursionDBHelper implements IDb {
|
||||
return _excursionDB!;
|
||||
}
|
||||
|
||||
// Creates the databases with help from the _onCreateExcursion function
|
||||
/// Initialize the database
|
||||
/// Creates database file and tables if they don't exist
|
||||
@override
|
||||
initDatabases() async {
|
||||
io.Directory documentsDirectory = await getApplicationCacheDirectory();
|
||||
@@ -33,21 +41,28 @@ class ExcursionDBHelper implements IDb {
|
||||
return excursionDB;
|
||||
}
|
||||
|
||||
// The function that helps
|
||||
/// Create database tables
|
||||
/// Sets up schema for both main entries and templates
|
||||
@override
|
||||
onCreateDatabases(Database excursionDB, int version) async {
|
||||
// Create main excursions table with tracking data fields
|
||||
await excursionDB.execute(
|
||||
'CREATE TABLE excursion (ID INTEGER PRIMARY KEY AUTOINCREMENT, Rudel TEXT, Teilnehmer TEXT, Datum TEXT, Dauer TEXT, MHund INTEGER, MLeine TEXT, BLand TEXT, Lkr TEXT, BeiOrt TEXT, BimaName TEXT, Wetter TEXT, Temperat TEXT, RegenVor TEXT, KmRad TEXT, KmAuto TEXT, KmFuss TEXT, KmTotal TEXT, KmAuProz TEXT, KmFuProz TEXT, KmRaProz TEXT, SpGut TEXT, SpMittel, SpSchlecht TEXT, SpurFund TEXT, SpurLang TEXT, SpurTiere Text, SpSicher TEXT, WelpenSp TEXT, WelpenAnz TEXT, WpSicher TEXT, LosungGes TEXT, LosungAnz TEXT, LosungGen TEXT, UrinAnz TEXT, UrinGen TEXT, OestrAnz TEXT, OestrGen TEXT, HaarAnz TEXT, HaarGen TEXT, LosungKm TEXT, GenetiKm TEXT, Hinweise TEXT, Bemerk TEXT, IntKomm TEXT, BimaNr TEXT, BimaNutzer TEXT, BimaAGV TEXT, FallNum INTEGER, Weg TEXT, Sent INTEGER DEFAULT 0)',
|
||||
);
|
||||
|
||||
// Create templates table (similar structure but without Sent flag)
|
||||
await excursionDB.execute(
|
||||
'CREATE TABLE excursionTemplates (ID INTEGER PRIMARY KEY AUTOINCREMENT, Rudel TEXT, Teilnehmer TEXT, Datum TEXT, Dauer TEXT, MHund INTEGER, MLeine TEXT, BLand TEXT, Lkr TEXT, BeiOrt TEXT, BimaName TEXT, Wetter TEXT, Temperat TEXT, RegenVor TEXT, KmRad TEXT, KmAuto TEXT, KmFuss TEXT, KmTotal TEXT, KmAuProz TEXT, KmFuProz TEXT, KmRaProz TEXT, SpGut TEXT, SpMittel, SpSchlecht TEXT, SpurFund TEXT, SpurLang TEXT, SpurTiere Text, SpSicher TEXT, WelpenSp TEXT, WelpenAnz TEXT, WpSicher TEXT, LosungGes TEXT, LosungAnz TEXT, LosungGen TEXT, UrinAnz TEXT, UrinGen TEXT, OestrAnz TEXT, OestrGen TEXT, HaarAnz TEXT, HaarGen TEXT, LosungKm TEXT, GenetiKm TEXT, Hinweise TEXT, Bemerk TEXT, IntKomm TEXT, BimaNr TEXT, BimaNutzer TEXT, BimaAGV TEXT, FallNum INTEGER, Weg TEXT)',
|
||||
);
|
||||
}
|
||||
|
||||
// Function to add a finished entry and return its ID
|
||||
/// Add a new main entry to the database
|
||||
/// @param excursion Map containing the excursion data
|
||||
/// @return ID of the newly inserted entry
|
||||
@override
|
||||
Future<int> addMainEntry(Map<String, String> excursion) async {
|
||||
var excursionDBClient = await dB;
|
||||
// Commented out code for handling existing entries
|
||||
// final existingID = await excursionDBClient.query(
|
||||
// 'excursion',
|
||||
// where: 'ID = ?',
|
||||
@@ -56,7 +71,7 @@ class ExcursionDBHelper implements IDb {
|
||||
|
||||
// if (existingID.isNotEmpty) {
|
||||
// updateMainEntry(excursion);
|
||||
// return existingID.first['ID'] as int; // Return existing ID
|
||||
// return existingID.first['ID'] as int;
|
||||
// }
|
||||
|
||||
int id = await excursionDBClient.insert(
|
||||
@@ -65,13 +80,15 @@ class ExcursionDBHelper implements IDb {
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
|
||||
return id; // Return the ID of the newly inserted entry
|
||||
return id;
|
||||
}
|
||||
|
||||
/// Update an existing main entry
|
||||
/// @param excursion Map containing the updated excursion data
|
||||
/// @return Number of rows affected
|
||||
@override
|
||||
Future<int> updateMainEntry(Map<String, String> excursion) async {
|
||||
var excursionDBClient = await dB;
|
||||
|
||||
return await excursionDBClient.update(
|
||||
'excursion',
|
||||
excursion,
|
||||
@@ -80,11 +97,11 @@ class ExcursionDBHelper implements IDb {
|
||||
);
|
||||
}
|
||||
|
||||
// function to update the sent value
|
||||
/// Mark an entry as sent to the server
|
||||
/// @param id ID of the entry to update
|
||||
@override
|
||||
Future<void> updateSent(int id) async {
|
||||
var excursionDBClient = await dB;
|
||||
|
||||
await excursionDBClient.update(
|
||||
'excursion',
|
||||
{'Sent': 1},
|
||||
@@ -93,11 +110,13 @@ class ExcursionDBHelper implements IDb {
|
||||
);
|
||||
}
|
||||
|
||||
// same thing as before but with templatews
|
||||
/// Add a new template entry
|
||||
/// @param templates Map containing the template data
|
||||
/// @return ID of the newly inserted template
|
||||
@override
|
||||
Future<int> addTemplate(Map<String, String> templates) async {
|
||||
var excursionDBClient = await dB;
|
||||
|
||||
// Commented out code for handling existing templates
|
||||
// final existingCID = await excursionDBClient.query(
|
||||
// 'excursionTemplates',
|
||||
// where: 'ID = ?',
|
||||
@@ -110,16 +129,15 @@ class ExcursionDBHelper implements IDb {
|
||||
int id = await excursionDBClient.insert(
|
||||
'excursionTemplates',
|
||||
templates,
|
||||
// conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
return id;
|
||||
}
|
||||
|
||||
// Updates a existing template
|
||||
/// Update an existing template
|
||||
/// @param template Map containing the updated template data
|
||||
@override
|
||||
Future<void> updateTemplate(Map<String, String> template) async {
|
||||
var excursionDBClient = await dB;
|
||||
|
||||
await excursionDBClient.update(
|
||||
'excursionTemplates',
|
||||
template,
|
||||
@@ -128,7 +146,8 @@ class ExcursionDBHelper implements IDb {
|
||||
);
|
||||
}
|
||||
|
||||
// get the finished entries from db
|
||||
/// Retrieve all main entries from the database
|
||||
/// @return List of all excursions or empty list if none exist
|
||||
@override
|
||||
Future<List<Map<String, dynamic>>> getAllMainEntries() async {
|
||||
var excursionDBClient = await dB;
|
||||
@@ -140,7 +159,8 @@ class ExcursionDBHelper implements IDb {
|
||||
}
|
||||
}
|
||||
|
||||
// get the finished templates from db
|
||||
/// Retrieve all templates from the database
|
||||
/// @return List of all templates or empty list if none exist
|
||||
@override
|
||||
Future<List<Map<String, dynamic>>> getAllTemplates() async {
|
||||
var excursionDBClient = await dB;
|
||||
@@ -152,21 +172,24 @@ class ExcursionDBHelper implements IDb {
|
||||
}
|
||||
}
|
||||
|
||||
// deletes all finished entries from the db LOCALLY
|
||||
/// Delete all main entries from the local database
|
||||
/// Note: This only affects the local database, not the server
|
||||
@override
|
||||
Future<void> deleteAllMainEntries() async {
|
||||
var excursionDBClient = await dB;
|
||||
await excursionDBClient.delete('excursion');
|
||||
}
|
||||
|
||||
// deletes all templates from the db LOCALLY
|
||||
/// Delete all templates from the local database
|
||||
/// Note: This only affects the local database, not the server
|
||||
@override
|
||||
Future<void> deleteAllTemplates() async {
|
||||
var excursionDBClient = await dB;
|
||||
await excursionDBClient.delete('excursionTemplates');
|
||||
}
|
||||
|
||||
// delete specific template
|
||||
/// Delete a specific template by ID
|
||||
/// @param id ID of the template to delete
|
||||
@override
|
||||
Future<void> deleteTemplateById(String id) async {
|
||||
var excursionDBClient = await dB;
|
||||
@@ -177,7 +200,8 @@ class ExcursionDBHelper implements IDb {
|
||||
);
|
||||
}
|
||||
|
||||
// delete specific excursion
|
||||
/// Delete a specific main entry by ID
|
||||
/// @param id ID of the entry to delete
|
||||
@override
|
||||
Future<void> deleteMainEntryById(String id) async {
|
||||
var excursionDBClient = await dB;
|
||||
|
||||
@@ -4,13 +4,20 @@ import 'package:sqflite/sqflite.dart';
|
||||
import 'dart:io' as io;
|
||||
import 'package:path/path.dart';
|
||||
|
||||
// * Gives the complete functionality for the databases
|
||||
// ! functions may not be named complete correctly
|
||||
// * Database helper for managing camera trap locations (places)
|
||||
// * Provides CRUD operations for both main entries and templates
|
||||
// * Uses SQLite database with two tables:
|
||||
// * - place: Stores finalized camera trap locations
|
||||
// * - placeTemplates: Stores template entries for quick creation
|
||||
|
||||
class PlaceDBHelper implements IDb{
|
||||
/// Database helper class implementing IDb interface
|
||||
/// Handles all database operations for camera trap locations
|
||||
class PlaceDBHelper implements IDb {
|
||||
// Database instance
|
||||
static Database? _dB;
|
||||
|
||||
// checks if the databses are existing and creates them with the initPlaceDatabase function if not
|
||||
/// Get database instance, creating it if necessary
|
||||
/// Returns existing database or initializes a new one
|
||||
@override
|
||||
Future<Database> get dB async {
|
||||
if (_dB != null) {
|
||||
@@ -20,7 +27,8 @@ class PlaceDBHelper implements IDb{
|
||||
return _dB!;
|
||||
}
|
||||
|
||||
// Creates the databases with help from the _onCreatePlace function
|
||||
/// Initialize the database
|
||||
/// Creates database file and tables if they don't exist
|
||||
@override
|
||||
initDatabases() async {
|
||||
io.Directory documentsDirectory = await getApplicationCacheDirectory();
|
||||
@@ -30,19 +38,26 @@ class PlaceDBHelper implements IDb{
|
||||
return placeDB;
|
||||
}
|
||||
|
||||
// The function that helps
|
||||
/// Create database tables
|
||||
/// Sets up schema for both main entries and templates
|
||||
@override
|
||||
onCreateDatabases(Database placeDB, int version) async {
|
||||
// Create main places table
|
||||
await placeDB.execute(
|
||||
'CREATE TABLE place (ID INTEGER PRIMARY KEY AUTOINCREMENT, CID TEXT, Standort TEXT, Rudel TEXT, Datum TEXT, Adresse1 TEXT, Adresse2 TEXT, Adresse3 TEXT, BLand TEXT, Lkr TEXT, BeiOrt TEXT, OrtInfo TEXT, Status TEXT, FFTyp TEXT, FotoFilm TEXT, MEZ TEXT, Platzung TEXT, KSchloNr TEXT, KontDat DATE, Betreuung TEXT, AbbauDat DATE, Auftrag TEXT, KontAbsp TEXT, SonstBem TEXT, FKontakt1 TEXT, FKontakt2 TEXT, FKontakt3 TEXT, KTage1 INTEGER, KTage2 INTEGER, ProtoAm DATE, IntKomm TEXT, DECLNG DECIMALS(4,8), DECLAT DECIMALS(4,8), Sent INTEGER DEFAULT 0)');
|
||||
|
||||
// Create templates table (similar structure but without Sent flag)
|
||||
await placeDB.execute(
|
||||
'CREATE TABLE placeTemplates (ID INTEGER PRIMARY KEY AUTOINCREMENT, CID TEXT, Standort TEXT, Rudel TEXT, Datum TEXT, Adresse1 TEXT, Adresse2 TEXT, Adresse3 TEXT, BLand TEXT, Lkr TEXT, BeiOrt TEXT, OrtInfo TEXT, Status TEXT, FFTyp TEXT, FotoFilm TEXT, MEZ TEXT, Platzung TEXT, KSchloNr TEXT, KontDat DATE, Betreuung TEXT, AbbauDat DATE, Auftrag TEXT, KontAbsp TEXT, SonstBem TEXT, FKontakt1 TEXT, FKontakt2 TEXT, FKontakt3 TEXT, KTage1 INTEGER, KTage2 INTEGER, ProtoAm DATE, IntKomm TEXT, DECLNG DECIMALS(4,8), DECLAT DECIMALS(4,8))');
|
||||
}
|
||||
|
||||
// Function to add a finished entry and return its ID
|
||||
/// Add a new main entry to the database
|
||||
/// @param place Map containing the place data
|
||||
/// @return ID of the newly inserted entry
|
||||
@override
|
||||
Future<int> addMainEntry(Map<String, String> place) async {
|
||||
var placeDBClient = await dB;
|
||||
// Commented out code for handling existing entries
|
||||
// final existingID = await placeDBClient.query(
|
||||
// 'place',
|
||||
// where: 'ID = ?',
|
||||
@@ -51,7 +66,7 @@ class PlaceDBHelper implements IDb{
|
||||
//
|
||||
// if (existingID.isNotEmpty) {
|
||||
// updateMainEntry(place);
|
||||
// return existingID.first['ID'] as int; // Return existing ID
|
||||
// return existingID.first['ID'] as int;
|
||||
// }
|
||||
|
||||
int id = await placeDBClient.insert(
|
||||
@@ -60,31 +75,35 @@ class PlaceDBHelper implements IDb{
|
||||
//conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
|
||||
return id; // Return the ID of the newly inserted entry
|
||||
return id;
|
||||
}
|
||||
|
||||
/// Update an existing main entry
|
||||
/// @param place Map containing the updated place data
|
||||
/// @return Number of rows affected
|
||||
@override
|
||||
Future<int> updateMainEntry(Map<String, String> place) async {
|
||||
var placeDBClient = await dB;
|
||||
|
||||
return await placeDBClient
|
||||
.update('place', place, where: "ID = ?", whereArgs: [place['ID']]);
|
||||
}
|
||||
|
||||
// function to update the sent value
|
||||
/// Mark an entry as sent to the server
|
||||
/// @param id ID of the entry to update
|
||||
@override
|
||||
Future<void> updateSent(int id) async {
|
||||
var placeDBClient = await dB;
|
||||
|
||||
await placeDBClient.update('place', {'Sent': 1},
|
||||
where: 'ID = ?', whereArgs: [id]);
|
||||
}
|
||||
|
||||
// same thing as before but with templatews
|
||||
/// Add a new template entry
|
||||
/// @param templates Map containing the template data
|
||||
/// @return ID of the newly inserted template
|
||||
@override
|
||||
Future<int> addTemplate(Map<String, String> templates) async {
|
||||
var placeDBClient = await dB;
|
||||
|
||||
// Commented out code for handling existing templates
|
||||
// final existingCID = await placeDBClient.query(
|
||||
// 'placeTemplates',
|
||||
// where: 'ID = ?',
|
||||
@@ -97,16 +116,15 @@ class PlaceDBHelper implements IDb{
|
||||
int id = await placeDBClient.insert(
|
||||
'placeTemplates',
|
||||
templates,
|
||||
// conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
return id;
|
||||
}
|
||||
|
||||
// Updates a existing template
|
||||
/// Update an existing template
|
||||
/// @param template Map containing the updated template data
|
||||
@override
|
||||
Future<void> updateTemplate(Map<String, String> template) async {
|
||||
var placeDBClient = await dB;
|
||||
|
||||
await placeDBClient.update(
|
||||
'placeTemplates',
|
||||
template,
|
||||
@@ -115,7 +133,8 @@ class PlaceDBHelper implements IDb{
|
||||
);
|
||||
}
|
||||
|
||||
// get the finished entries from db
|
||||
/// Retrieve all main entries from the database
|
||||
/// @return List of all places or empty list if none exist
|
||||
@override
|
||||
Future<List<Map<String, dynamic>>> getAllMainEntries() async {
|
||||
var placeDBClient = await dB;
|
||||
@@ -127,7 +146,8 @@ class PlaceDBHelper implements IDb{
|
||||
}
|
||||
}
|
||||
|
||||
// get the finished templates from db
|
||||
/// Retrieve all templates from the database
|
||||
/// @return List of all templates or empty list if none exist
|
||||
@override
|
||||
Future<List<Map<String, dynamic>>> getAllTemplates() async {
|
||||
var placeDBClient = await dB;
|
||||
@@ -139,21 +159,24 @@ class PlaceDBHelper implements IDb{
|
||||
}
|
||||
}
|
||||
|
||||
// deletes all finished entries from the db LOCALLY
|
||||
/// Delete all main entries from the local database
|
||||
/// Note: This only affects the local database, not the server
|
||||
@override
|
||||
Future<void> deleteAllMainEntries() async {
|
||||
var placeDBClient = await dB;
|
||||
await placeDBClient.delete('place');
|
||||
}
|
||||
|
||||
// deletes all templates from the db LOCALLY
|
||||
/// Delete all templates from the local database
|
||||
/// Note: This only affects the local database, not the server
|
||||
@override
|
||||
Future<void> deleteAllTemplates() async {
|
||||
var placeDBClient = await dB;
|
||||
await placeDBClient.delete('placeTemplates');
|
||||
}
|
||||
|
||||
// delete specific template
|
||||
/// Delete a specific template by ID
|
||||
/// @param id ID of the template to delete
|
||||
@override
|
||||
Future<void> deleteTemplateById(String id) async {
|
||||
var placeDBClient = await dB;
|
||||
@@ -164,7 +187,8 @@ class PlaceDBHelper implements IDb{
|
||||
);
|
||||
}
|
||||
|
||||
// delete specific place
|
||||
/// Delete a specific main entry by ID
|
||||
/// @param id ID of the entry to delete
|
||||
@override
|
||||
Future<void> deleteMainEntryById(String id) async {
|
||||
var placeDBClient = await dB;
|
||||
|
||||
Reference in New Issue
Block a user