fix(database): fix identifiers, string quotation, table initialisation

This commit is contained in:
fbachus
2026-07-24 23:36:07 +02:00
parent 24ddd65bf5
commit 2c4be8438e
+19 -16
View File
@@ -35,6 +35,8 @@ class DbHelper {
Route.initRouteTable(); Route.initRouteTable();
Segment.initSegmentTable(); Segment.initSegmentTable();
Station.initStationTable(); Station.initStationTable();
Station.initStationLinesTable();
Line.initLineTable();
Vehicle.initVehicleTable(); Vehicle.initVehicleTable();
Departure.initDepartureTable(); Departure.initDepartureTable();
} }
@@ -183,7 +185,7 @@ class Route {
segment INTEGER, segment INTEGER,
segmentorder INTEGER, -- TODO: implement sorting segmentorder INTEGER, -- TODO: implement sorting
FOREIGN KEY(route) REFERENCES route(id), FOREIGN KEY(route) REFERENCES route(id),
FOREIGN KEY(segment) REFERENCES $segment(id) FOREIGN KEY(segment) REFERENCES '$segment'(id)
); );
"""); """);
} }
@@ -208,7 +210,7 @@ class Route {
var tmp = await database.rawQuery(""" var tmp = await database.rawQuery("""
SELECT * FROM segments SELECT * FROM segments
JOIN routesegments ON routesegments.segmentid = segments.id JOIN routesegments ON routesegments.segmentid = segments.id
WHERE routesegments.route = $routeId WHERE routesegments.route = '$routeId'
ORDER BY routesegments.segmentorder ASC; ORDER BY routesegments.segmentorder ASC;
"""); """);
return tmp.map((x) => Segment.fromMap(x)).toList(); return tmp.map((x) => Segment.fromMap(x)).toList();
@@ -377,7 +379,7 @@ class Segment {
String station = Station.tableName; String station = Station.tableName;
String vehicle = Vehicle.tableName; String vehicle = Vehicle.tableName;
database.execute(""" database.execute("""
CREATE TABLE IF NOT EXISTS $tableName( CREATE TABLE IF NOT EXISTS '$tableName'(
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
ref TEXT, ref TEXT,
startpoint TEXT, startpoint TEXT,
@@ -385,9 +387,9 @@ class Segment {
starttime TEXT, starttime TEXT,
endtime TEXT, endtime TEXT,
vehicle INTEGER, vehicle INTEGER,
FOREIGN KEY(startpoint) REFERENCES $station(stationid), FOREIGN KEY(startpoint) REFERENCES '$station'(stationid),
FOREIGN KEY(endpoint) REFERENCES $station(stationid), FOREIGN KEY(endpoint) REFERENCES '$station'(stationid),
FOREIGN KEY(vehicle) REFERENCES $vehicle(vehicleid) FOREIGN KEY(vehicle) REFERENCES '$vehicle'(vehicleid)
); );
"""); """);
} }
@@ -525,11 +527,12 @@ class Station {
static Future<List<Line>> _dbGetStationLines(String stationId) async { static Future<List<Line>> _dbGetStationLines(String stationId) async {
Database database = DbHelper.db; Database database = DbHelper.db;
String line = Line.tableName;
var lines = await database.rawQuery(""" var lines = await database.rawQuery("""
SELECT * FROM lines SELECT * FROM '$line'
JOIN stationlines sl ON sl.lineid = line.id JOIN stationlines sl ON sl.lineid = line.lineid
WHERE stationlines.stationid = $stationId WHERE sl.stationid = '$stationId'
ORDER BY line.id ASC; ORDER BY line.lineid ASC;
"""); """);
return lines.map((x) => Line.fromMap(x)).toList(); return lines.map((x) => Line.fromMap(x)).toList();
} }
@@ -623,11 +626,11 @@ class Vehicle {
static void initVehicleTable() async { static void initVehicleTable() async {
Database database = DbHelper.db; Database database = DbHelper.db;
String line = Line.tableName; String line = Line.tableName;
database.execute("""CREATE TABLE IF NOT EXISTS $tableName( database.execute("""CREATE TABLE IF NOT EXISTS '$tableName'(
id TEXT PRIMARY KEY, id TEXT PRIMARY KEY,
name TEXT, name TEXT,
line TEXT, line TEXT,
FOREIGN KEY(line) REFERENCES $line(lineid) FOREIGN KEY(line) REFERENCES '$line'(lineid)
); );
"""); """);
} }
@@ -731,7 +734,7 @@ class Line {
); );
static void initLineTable() async { static void initLineTable() async {
Database database = DbHelper.db; Database database = DbHelper.db;
database.execute("""CREATE TABLE IF NOT EXISTS $tableName( database.execute("""CREATE TABLE IF NOT EXISTS '$tableName'(
lineid TEXT PRIMARY KEY, lineid TEXT PRIMARY KEY,
destination TEXT, destination TEXT,
direction TEXT, direction TEXT,
@@ -896,7 +899,7 @@ class Departure {
Database database = DbHelper.db; Database database = DbHelper.db;
String vehicle = Vehicle.tableName; String vehicle = Vehicle.tableName;
String station = Station.tableName; String station = Station.tableName;
database.execute("""CREATE TABLE IF NOT EXISTS $tableName( database.execute("""CREATE TABLE IF NOT EXISTS '$tableName'(
id INTEGER, id INTEGER,
ref TEXT, ref TEXT,
vehicle TEXT, vehicle TEXT,
@@ -905,8 +908,8 @@ class Departure {
stationname TEXT, stationname TEXT,
arrivaltime TEXT, arrivaltime TEXT,
departuretime TEXT, departuretime TEXT,
FOREIGN KEY(vehicle) REFERENCES $vehicle(id), FOREIGN KEY(vehicle) REFERENCES '$vehicle'(id),
FOREIGN KEY(station) REFERENCES $station(id) FOREIGN KEY(station) REFERENCES '$station'(id)
); );
"""); """);
} }