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();
Segment.initSegmentTable();
Station.initStationTable();
Station.initStationLinesTable();
Line.initLineTable();
Vehicle.initVehicleTable();
Departure.initDepartureTable();
}
@@ -183,7 +185,7 @@ class Route {
segment INTEGER,
segmentorder INTEGER, -- TODO: implement sorting
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("""
SELECT * FROM segments
JOIN routesegments ON routesegments.segmentid = segments.id
WHERE routesegments.route = $routeId
WHERE routesegments.route = '$routeId'
ORDER BY routesegments.segmentorder ASC;
""");
return tmp.map((x) => Segment.fromMap(x)).toList();
@@ -377,7 +379,7 @@ class Segment {
String station = Station.tableName;
String vehicle = Vehicle.tableName;
database.execute("""
CREATE TABLE IF NOT EXISTS $tableName(
CREATE TABLE IF NOT EXISTS '$tableName'(
id INTEGER PRIMARY KEY AUTOINCREMENT,
ref TEXT,
startpoint TEXT,
@@ -385,9 +387,9 @@ class Segment {
starttime TEXT,
endtime TEXT,
vehicle INTEGER,
FOREIGN KEY(startpoint) REFERENCES $station(stationid),
FOREIGN KEY(endpoint) REFERENCES $station(stationid),
FOREIGN KEY(vehicle) REFERENCES $vehicle(vehicleid)
FOREIGN KEY(startpoint) REFERENCES '$station'(stationid),
FOREIGN KEY(endpoint) REFERENCES '$station'(stationid),
FOREIGN KEY(vehicle) REFERENCES '$vehicle'(vehicleid)
);
""");
}
@@ -525,11 +527,12 @@ class Station {
static Future<List<Line>> _dbGetStationLines(String stationId) async {
Database database = DbHelper.db;
String line = Line.tableName;
var lines = await database.rawQuery("""
SELECT * FROM lines
JOIN stationlines sl ON sl.lineid = line.id
WHERE stationlines.stationid = $stationId
ORDER BY line.id ASC;
SELECT * FROM '$line'
JOIN stationlines sl ON sl.lineid = line.lineid
WHERE sl.stationid = '$stationId'
ORDER BY line.lineid ASC;
""");
return lines.map((x) => Line.fromMap(x)).toList();
}
@@ -623,11 +626,11 @@ class Vehicle {
static void initVehicleTable() async {
Database database = DbHelper.db;
String line = Line.tableName;
database.execute("""CREATE TABLE IF NOT EXISTS $tableName(
database.execute("""CREATE TABLE IF NOT EXISTS '$tableName'(
id TEXT PRIMARY KEY,
name 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 {
Database database = DbHelper.db;
database.execute("""CREATE TABLE IF NOT EXISTS $tableName(
database.execute("""CREATE TABLE IF NOT EXISTS '$tableName'(
lineid TEXT PRIMARY KEY,
destination TEXT,
direction TEXT,
@@ -896,7 +899,7 @@ class Departure {
Database database = DbHelper.db;
String vehicle = Vehicle.tableName;
String station = Station.tableName;
database.execute("""CREATE TABLE IF NOT EXISTS $tableName(
database.execute("""CREATE TABLE IF NOT EXISTS '$tableName'(
id INTEGER,
ref TEXT,
vehicle TEXT,
@@ -905,8 +908,8 @@ class Departure {
stationname TEXT,
arrivaltime TEXT,
departuretime TEXT,
FOREIGN KEY(vehicle) REFERENCES $vehicle(id),
FOREIGN KEY(station) REFERENCES $station(id)
FOREIGN KEY(vehicle) REFERENCES '$vehicle'(id),
FOREIGN KEY(station) REFERENCES '$station'(id)
);
""");
}