From e0b305fd1d845cba1b11578722f88adb193f756e Mon Sep 17 00:00:00 2001 From: Matthijs Bijman Date: Thu, 16 Feb 2017 22:06:09 +0100 Subject: Update simulator to work with new db schema The new schema removes the queued_simulation_section table and introduces the state and last_simulated_tick columns to the experiments table. --- Simulator/include/database/Database.h | 4 ++++ Simulator/include/database/Queries.h | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'Simulator/include/database') diff --git a/Simulator/include/database/Database.h b/Simulator/include/database/Database.h index 6e8bfeef..7f867d6c 100644 --- a/Simulator/include/database/Database.h +++ b/Simulator/include/database/Database.h @@ -49,6 +49,10 @@ namespace Database */ void dequeueExperiment(int id) const; + /* + Marks the given experiment as finished in the database. + */ + void finishExperiment(int id) const; /* Creates a simulation object from a simulation in the database. diff --git a/Simulator/include/database/Queries.h b/Simulator/include/database/Queries.h index 73afc1a1..33e8cdb9 100644 --- a/Simulator/include/database/Queries.h +++ b/Simulator/include/database/Queries.h @@ -6,11 +6,15 @@ namespace Database namespace Queries { Query GET_QUEUED_EXPERIMENTS(std::string(R"query( - SELECT experiment_id FROM queued_experiments; + SELECT id FROM experiments WHERE state LIKE 'QUEUED'; )query")); - Query<> REMOVE_QUEUED_EXPERIMENT(std::string(R"query( - DELETE FROM queued_experiments WHERE experiment_id = $id; + Query<> SET_EXPERIMENT_STATE_SIMULATING(std::string(R"query( + UPDATE experiments SET state='SIMULATING' WHERE id=$id; + )query")); + + Query<> SET_EXPERIMENT_STATE_FINISHED(std::string(R"query( + UPDATE experiments SET state='FINISHED' WHERE id=$id; )query")); Query GET_EXPERIMENT_BY_ID(std::string(R"query( @@ -25,7 +29,10 @@ namespace Database SELECT id, path_id, datacenter_id, start_tick FROM sections WHERE path_id = $id; )query")); - + Query<> WRITE_EXPERIMENT_LAST_SIMULATED_TICK(std::string(R"query( + UPDATE experiments SET last_simulated_tick = $val WHERE id = $id; + )query")); + /* Returns the type of the scheduler of the given simulation section. Returns: -- cgit v1.2.3