1 #ifndef AMO_LIBRARY_SQLITEWRAPPER_H 2 #define AMO_LIBRARY_SQLITEWRAPPER_H 9 #include <calculator/losses/GasFlueGasMaterial.h> 10 #include <calculator/motor/MotorData.h> 11 #include <calculator/pump/PumpData.h> 28 SQLiteWrapper(std::string
const &db_name,
bool init_db =
false);
32 int execute_command(std::string
const &command_buffer)
const;
34 int prepare_statement(sqlite3_stmt *&stmt, std::string
const &stmt_buffer)
const;
36 int bind_value(sqlite3_stmt *stmt,
int const stmt_insert_col_index, std::string
const &text_buffer)
const;
38 int bind_value(sqlite3_stmt *stmt,
int const stmt_insert_col_index,
int const int_to_insert)
const;
40 int bind_value(sqlite3_stmt *stmt,
int const stmt_insert_col_index,
double const double_to_insert)
const;
42 int bind_value(sqlite3_stmt *stmt,
int const stmt_insert_col_index)
const;
44 int bind_value(sqlite3_stmt *stmt,
int const stmt_insert_col_index,
const bool value_to_insert)
const;
46 int bind_foreign_key(sqlite3_stmt *stmt,
int const stmt_insert_col_index,
int const int_to_insert)
const;
48 bool step_validity(
int const rc)
const;
50 int step_command(sqlite3_stmt *stmt)
const;
52 int reset_command(sqlite3_stmt *stmt)
const;
54 void begin_transaction()
const;
56 void commit_transaction()
const;
58 static std::string convert_text(
const unsigned char *text);
60 static Motor::EfficiencyClass convert_motor_efficiency_class(
int efficiencyClass);
62 static Motor::LineFrequency convert_motor_line_frequency(
int lineFrequency);
65 std::vector<T> get_all_objects(sqlite3_stmt *stmt, std::function<T(sqlite3_stmt *)> cb)
const 67 std::vector<T> retVal;
70 while (step_command(stmt) == SQLITE_ROW)
72 retVal.push_back(cb(stmt));
79 T get_object(sqlite3_stmt *stmt,
int const id, std::function<T(sqlite3_stmt *)> cb)
const 83 bind_value(stmt, 1,
id);
84 int rc = step_command(stmt);
94 throw std::runtime_error(
"Invalid command during get_object. SQLite return code: " + std::to_string(rc));
96 throw std::runtime_error(
"No valid database connection");
100 sqlite3 *m_connection =
nullptr;
101 std::shared_ptr<sqlite3> m_db;
109 SQLite(std::string
const &db_name,
bool init_db =
false);
114 std::vector<SolidLoadChargeMaterial> getSolidLoadChargeMaterials()
const;
116 std::vector<SolidLoadChargeMaterial> getCustomSolidLoadChargeMaterials()
const;
118 bool deleteSolidLoadChargeMaterial(
int id);
121 std::vector<GasLoadChargeMaterial> getGasLoadChargeMaterials()
const;
123 std::vector<GasLoadChargeMaterial> getCustomGasLoadChargeMaterials()
const;
125 bool deleteGasLoadChargeMaterial(
int id);
128 std::vector<LiquidLoadChargeMaterial> getLiquidLoadChargeMaterials()
const;
130 std::vector<LiquidLoadChargeMaterial> getCustomLiquidLoadChargeMaterials()
const;
132 bool deleteLiquidLoadChargeMaterial(
int id);
135 std::vector<SolidLiquidFlueGasMaterial> getSolidLiquidFlueGasMaterials()
const;
137 std::vector<SolidLiquidFlueGasMaterial> getCustomSolidLiquidFlueGasMaterials()
const;
139 bool deleteSolidLiquidFlueGasMaterial(
int id);
142 std::vector<GasCompositions> getGasFlueGasMaterials()
const;
144 std::vector<GasCompositions> getCustomGasFlueGasMaterials()
const;
146 bool deleteGasFlueGasMaterial(
int id);
149 std::vector<Atmosphere> getAtmosphereSpecificHeat()
const;
150 Atmosphere getAtmosphereSpecificHeatById(
int id)
const;
151 std::vector<Atmosphere> getCustomAtmosphereSpecificHeat()
const;
152 bool insertAtmosphereSpecificHeat(
Atmosphere const &material);
153 bool updateAtmosphereSpecificHeat(
Atmosphere const &material);
154 bool deleteAtmosphereSpecificHeat(
int id);
156 std::vector<WallLosses> getWallLossesSurface()
const;
157 std::vector<WallLosses> getCustomWallLossesSurface()
const;
158 WallLosses getWallLossesSurfaceById(
int id)
const;
159 bool insertWallLossesSurface(
WallLosses const &material);
160 bool deleteWallLossesSurface(
int id);
161 bool updateWallLossesSurface(
WallLosses const &material);
163 std::vector<MotorData> getMotorData()
const;
164 std::vector<MotorData> getCustomMotorData()
const;
165 MotorData getMotorDataById(
int id)
const;
166 bool insertMotorData(
MotorData const &motor);
167 bool deleteMotorData(
int id);
168 bool updateMotorData(
MotorData const &motor);
170 std::vector<PumpData> getPumpData()
const;
171 std::vector<PumpData> getCustomPumpData()
const;
172 PumpData getPumpDataById(
int id)
const;
173 bool insertPumpData(
PumpData const &pump);
174 bool deletePumpData(
int id);
175 bool updatePumpData(
PumpData const &pump);
179 inline bool isDefaultMaterial(
const int id, std::size_t
const defaultMaterialsSize)
181 return static_cast<std::size_t
>(id) <= defaultMaterialsSize;
184 sqlite3_stmt *m_solid_load_charge_materials_insert_stmt =
nullptr;
185 sqlite3_stmt *m_solid_load_charge_materials_select_stmt =
nullptr;
186 sqlite3_stmt *m_solid_load_charge_materials_select_single_stmt =
nullptr;
187 sqlite3_stmt *m_solid_load_charge_materials_select_custom_stmt =
nullptr;
188 sqlite3_stmt *m_solid_load_charge_materials_update_stmt =
nullptr;
189 sqlite3_stmt *m_solid_load_charge_materials_delete_stmt =
nullptr;
191 sqlite3_stmt *m_gas_load_charge_materials_insert_stmt =
nullptr;
192 sqlite3_stmt *m_gas_load_charge_materials_select_stmt =
nullptr;
193 sqlite3_stmt *m_gas_load_charge_materials_select_single_stmt =
nullptr;
194 sqlite3_stmt *m_gas_load_charge_materials_select_custom_stmt =
nullptr;
195 sqlite3_stmt *m_gas_load_charge_materials_update_stmt =
nullptr;
196 sqlite3_stmt *m_gas_load_charge_materials_delete_stmt =
nullptr;
198 sqlite3_stmt *m_liquid_load_charge_materials_insert_stmt =
nullptr;
199 sqlite3_stmt *m_liquid_load_charge_materials_select_stmt =
nullptr;
200 sqlite3_stmt *m_liquid_load_charge_materials_select_single_stmt =
nullptr;
201 sqlite3_stmt *m_liquid_load_charge_materials_select_custom_stmt =
nullptr;
202 sqlite3_stmt *m_liquid_load_charge_materials_update_stmt =
nullptr;
203 sqlite3_stmt *m_liquid_load_charge_materials_delete_stmt =
nullptr;
205 sqlite3_stmt *m_solid_liquid_flue_gas_materials_insert_stmt =
nullptr;
206 sqlite3_stmt *m_solid_liquid_flue_gas_materials_select_stmt =
nullptr;
207 sqlite3_stmt *m_solid_liquid_flue_gas_materials_select_single_stmt =
nullptr;
208 sqlite3_stmt *m_solid_liquid_flue_gas_materials_select_custom_stmt =
nullptr;
209 sqlite3_stmt *m_solid_liquid_flue_gas_materials_update_stmt =
nullptr;
210 sqlite3_stmt *m_solid_liquid_flue_gas_materials_delete_stmt =
nullptr;
212 sqlite3_stmt *m_gas_flue_gas_materials_insert_stmt =
nullptr;
213 sqlite3_stmt *m_gas_flue_gas_materials_select_stmt =
nullptr;
214 sqlite3_stmt *m_gas_flue_gas_materials_select_single_stmt =
nullptr;
215 sqlite3_stmt *m_gas_flue_gas_materials_select_custom_stmt =
nullptr;
216 sqlite3_stmt *m_gas_flue_gas_materials_update_stmt =
nullptr;
217 sqlite3_stmt *m_gas_flue_gas_materials_delete_stmt =
nullptr;
219 sqlite3_stmt *m_atmosphere_specific_heat_insert_stmt =
nullptr;
220 sqlite3_stmt *m_atmosphere_specific_heat_select_stmt =
nullptr;
221 sqlite3_stmt *m_atmosphere_specific_heat_select_single_stmt =
nullptr;
222 sqlite3_stmt *m_atmosphere_specific_heat_select_custom_stmt =
nullptr;
223 sqlite3_stmt *m_atmosphere_specific_heat_update_stmt =
nullptr;
224 sqlite3_stmt *m_atmosphere_specific_heat_delete_stmt =
nullptr;
226 sqlite3_stmt *m_wall_losses_surface_insert_stmt =
nullptr;
227 sqlite3_stmt *m_wall_losses_surface_select_stmt =
nullptr;
228 sqlite3_stmt *m_wall_losses_surface_select_single_stmt =
nullptr;
229 sqlite3_stmt *m_wall_losses_surface_select_custom_stmt =
nullptr;
230 sqlite3_stmt *m_wall_losses_surface_update_stmt =
nullptr;
231 sqlite3_stmt *m_wall_losses_surface_delete_stmt =
nullptr;
233 sqlite3_stmt *m_motor_data_insert_stmt =
nullptr;
234 sqlite3_stmt *m_motor_data_select_stmt =
nullptr;
235 sqlite3_stmt *m_motor_data_select_single_stmt =
nullptr;
236 sqlite3_stmt *m_motor_data_select_custom_stmt =
nullptr;
237 sqlite3_stmt *m_motor_data_update_stmt =
nullptr;
238 sqlite3_stmt *m_motor_data_delete_stmt =
nullptr;
240 sqlite3_stmt *m_pump_data_insert_stmt =
nullptr;
241 sqlite3_stmt *m_pump_data_select_stmt =
nullptr;
242 sqlite3_stmt *m_pump_data_select_single_stmt =
nullptr;
243 sqlite3_stmt *m_pump_data_select_custom_stmt =
nullptr;
244 sqlite3_stmt *m_pump_data_update_stmt =
nullptr;
245 sqlite3_stmt *m_pump_data_delete_stmt =
nullptr;
247 void create_select_stmt();
249 void create_update_and_delete_stmt();
251 void create_insert_stmt();
253 void create_tables();
265 bool insert_atmosphere_specific_heat(
Atmosphere const &material);
267 bool insert_wall_losses_surface(
WallLosses const &surface);
269 bool insert_motor_data(
MotorData const &m);
271 bool insert_pump_data(
PumpData const &pump);
273 void insert_default_data();
275 std::vector<SolidLoadChargeMaterial> get_default_solid_load_charge_materials();
277 std::vector<GasLoadChargeMaterial> get_default_gas_load_charge_materials();
279 std::vector<LiquidLoadChargeMaterial> get_default_liquid_load_charge_materials();
281 std::vector<SolidLiquidFlueGasMaterial> get_default_solid_liquid_flue_gas_materials();
283 std::vector<GasCompositions> get_default_gas_flue_gas_materials();
285 std::vector<Atmosphere> get_default_atmosphere_specific_heat();
287 std::vector<WallLosses> get_default_wall_losses_surface();
289 std::vector<MotorData> get_default_motor_data();
291 std::vector<PumpData> get_default_pump_data();
294 #endif //AMO_LIBRARY_SQLITEWRAPPER_H