|
1 /** |
|
2 * db_recipe.cpp is part of bmsapp. |
|
3 * |
|
4 * bmsapp is free software: you can redistribute it and/or modify |
|
5 * it under the terms of the GNU General Public License as published by |
|
6 * the Free Software Foundation, either version 3 of the License, or |
|
7 * (at your option) any later version. |
|
8 * |
|
9 * bmsapp is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 */ |
|
17 |
|
18 #include "global.h" |
|
19 #include "db_recipe.h" |
|
20 |
|
21 |
|
22 bool DB_recipe::load(Recipe *reci, QDialog *dialog, int recno) |
|
23 { |
|
24 QSqlQuery query, yquery; |
|
25 |
|
26 query.prepare("SELECT * FROM recipes WHERE record = :recno"); |
|
27 query.bindValue(":recno", recno); |
|
28 query.exec(); |
|
29 if (! query.first()) { |
|
30 qDebug() << "loadRecipe seek error record" << recno; |
|
31 QMessageBox::warning(dialog, QObject::tr("Database error"), QObject::tr("MySQL error: record %1 not found").arg(recno)); |
|
32 dialog->done(QDialog::Rejected); // At this stage, this doesn't work because the dialog is not yet visible. |
|
33 return false; |
|
34 } |
|
35 |
|
36 // QSqlRecord rec = query.record(); |
|
37 // for (int i = 0; i < rec.count(); i++) |
|
38 // qDebug() << i << rec.fieldName(i) << query.value(i); |
|
39 |
|
40 reci->record = query.value("record").toInt(); |
|
41 reci->uuid = query.value("uuid").toString(); |
|
42 reci->locked = query.value("locked").toInt() ? true:false; |
|
43 |
|
44 reci->st_name = query.value("st_name").toString(); |
|
45 reci->st_letter = query.value("st_letter").toString(); |
|
46 reci->st_guide = query.value("st_guide").toString(); |
|
47 reci->st_category = query.value("st_category").toString(); |
|
48 reci->st_category_number = query.value("st_category_number").toInt(); |
|
49 reci->st_type = query.value("st_type").toInt(); |
|
50 reci->st_og_min = query.value("st_og_min").toDouble(); |
|
51 reci->st_og_max = query.value("st_og_max").toDouble(); |
|
52 reci->st_fg_min = query.value("st_fg_min").toDouble(); |
|
53 reci->st_fg_max = query.value("st_fg_max").toDouble(); |
|
54 reci->st_ibu_min = query.value("st_ibu_min").toDouble(); |
|
55 reci->st_ibu_max = query.value("st_ibu_max").toDouble(); |
|
56 reci->st_color_min = query.value("st_color_min").toDouble(); |
|
57 reci->st_color_max = query.value("st_color_max").toDouble(); |
|
58 reci->st_carb_min = query.value("st_carb_min").toDouble(); |
|
59 reci->st_carb_max = query.value("st_carb_max").toDouble(); |
|
60 reci->st_abv_min = query.value("st_abv_min").toDouble(); |
|
61 reci->st_abv_max = query.value("st_abv_max").toDouble(); |
|
62 |
|
63 reci->name = query.value("name").toString(); |
|
64 reci->notes = query.value("notes").toString(); |
|
65 reci->type = query.value("type").toInt(); |
|
66 reci->batch_size = query.value("batch_size").toDouble(); |
|
67 reci->boil_size = query.value("boil_size").toDouble(); |
|
68 reci->boil_time = query.value("boil_time").toDouble(); |
|
69 reci->efficiency = query.value("efficiency").toDouble(); |
|
70 reci->est_og = query.value("est_og").toDouble(); |
|
71 reci->est_fg = query.value("est_fg").toDouble(); |
|
72 reci->est_abv = query.value("est_abv").toDouble(); |
|
73 reci->est_color = query.value("est_color").toDouble(); |
|
74 reci->color_method = query.value("color_method").toInt(); |
|
75 reci->est_ibu = query.value("est_ibu").toDouble(); |
|
76 reci->ibu_method = query.value("ibu_method").toInt(); |
|
77 reci->est_carb = query.value("est_carb").toDouble(); |
|
78 |
|
79 reci->sparge_temp = query.value("sparge_temp").toDouble(); |
|
80 reci->sparge_ph = query.value("sparge_ph").toDouble(); |
|
81 reci->sparge_volume = query.value("sparge_volume").toDouble(); |
|
82 reci->sparge_source = query.value("sparge_source").toInt(); |
|
83 reci->sparge_acid_type = query.value("sparge_acid_type").toInt(); |
|
84 reci->sparge_acid_perc = query.value("sparge_acid_perc").toDouble(); |
|
85 reci->sparge_acid_amount = query.value("sparge_acid_amount").toDouble(); |
|
86 reci->mash_ph = query.value("mash_ph").toDouble(); |
|
87 reci->mash_name = query.value("mash_name").toString(); |
|
88 reci->calc_acid = query.value("calc_acid").toInt() ? true:false; |
|
89 |
|
90 reci->w1_name = query.value("w1_name").toString(); |
|
91 reci->w1_amount = query.value("w1_amount").toDouble(); |
|
92 reci->w1_calcium = query.value("w1_calcium").toDouble(); |
|
93 reci->w1_sulfate = query.value("w1_sulfate").toDouble(); |
|
94 reci->w1_chloride = query.value("w1_chloride").toDouble(); |
|
95 reci->w1_sodium = query.value("w1_sodium").toDouble(); |
|
96 reci->w1_magnesium = query.value("w1_magnesium").toDouble(); |
|
97 reci->w1_total_alkalinity = query.value("w1_total_alkalinity").toDouble(); |
|
98 reci->w1_ph = query.value("w1_ph").toDouble(); |
|
99 reci->w1_cost = query.value("w1_cost").toDouble(); |
|
100 reci->w2_name = query.value("w2_name").toString(); |
|
101 reci->w2_amount = query.value("w2_amount").toDouble(); |
|
102 reci->w2_calcium = query.value("w2_calcium").toDouble(); |
|
103 reci->w2_sulfate = query.value("w2_sulfate").toDouble(); |
|
104 reci->w2_chloride = query.value("w2_chloride").toDouble(); |
|
105 reci->w2_sodium = query.value("w2_sodium").toDouble(); |
|
106 reci->w2_magnesium = query.value("w2_magnesium").toDouble(); |
|
107 reci->w2_total_alkalinity = query.value("w2_total_alkalinity").toDouble(); |
|
108 reci->w2_ph = query.value("w2_ph").toDouble(); |
|
109 reci->w2_cost = query.value("w2_cost").toDouble(); |
|
110 reci->wg_amount = query.value("wg_amount").toDouble(); |
|
111 reci->wg_calcium = query.value("wg_calcium").toDouble(); |
|
112 reci->wg_sulfate = query.value("wg_sulfate").toDouble(); |
|
113 reci->wg_chloride = query.value("wg_chloride").toDouble(); |
|
114 reci->wg_sodium = query.value("wg_sodium").toDouble(); |
|
115 reci->wg_magnesium = query.value("wg_magnesium").toDouble(); |
|
116 reci->wg_total_alkalinity = query.value("wg_total_alkalinity").toDouble(); |
|
117 reci->wg_ph = query.value("wg_ph").toDouble(); |
|
118 reci->wb_calcium = query.value("wb_calcium").toDouble(); |
|
119 reci->wb_sulfate = query.value("wb_sulfate").toDouble(); |
|
120 reci->wb_chloride = query.value("wb_chloride").toDouble(); |
|
121 reci->wb_sodium = query.value("wb_sodium").toDouble(); |
|
122 reci->wb_magnesium = query.value("wb_magnesium").toDouble(); |
|
123 reci->wb_total_alkalinity = query.value("wb_total_alkalinity").toDouble(); |
|
124 reci->wb_ph = query.value("wb_ph").toDouble(); |
|
125 reci->wa_acid_name = query.value("wa_acid_name").toInt(); |
|
126 reci->wa_acid_perc = query.value("wa_acid_perc").toDouble(); |
|
127 reci->wa_base_name = query.value("wa_base_name").toInt(); |
|
128 |
|
129 QJsonParseError parseError; |
|
130 const auto& f_json = query.value("json_fermentables").toString(); |
|
131 if (!f_json.trimmed().isEmpty()) { |
|
132 const auto& formattedJson = QString("%1").arg(f_json); |
|
133 QJsonDocument fermentables = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
134 if (parseError.error != QJsonParseError::NoError) { |
|
135 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
|
136 } else if (fermentables.isArray()) { |
|
137 double percentcheck = 0; |
|
138 for (int i = 0; i < fermentables.array().size(); i++) { |
|
139 QJsonObject obj = fermentables.array().at(i).toObject(); |
|
140 Fermentables f; |
|
141 f.f_name = obj["f_name"].toString(); |
|
142 f.f_origin = obj["f_origin"].toString(); |
|
143 f.f_supplier = obj["f_supplier"].toString(); |
|
144 f.f_amount = obj["f_amount"].toDouble(); |
|
145 f.f_cost = obj["f_cost"].toDouble(); |
|
146 f.f_type = obj["f_type"].toInt(); |
|
147 f.f_yield = obj["f_yield"].toDouble(); |
|
148 f.f_color = obj["f_color"].toDouble(); |
|
149 f.f_coarse_fine_diff = obj["f_coarse_fine_diff"].toDouble(); |
|
150 f.f_moisture = obj["f_moisture"].toDouble(); |
|
151 f.f_diastatic_power = obj["f_diastatic_power"].toDouble(); |
|
152 f.f_protein = obj["f_protein"].toDouble(); |
|
153 f.f_dissolved_protein = obj["f_dissolved_protein"].toDouble(); |
|
154 f.f_max_in_batch = obj["f_max_in_batch"].toDouble(); |
|
155 f.f_graintype = obj["f_graintype"].toInt(); |
|
156 f.f_added = obj["f_added"].toInt(); |
|
157 f.f_recommend_mash = obj["f_recommend_mash"].toInt() ? true:false; |
|
158 f.f_add_after_boil = obj["f_add_after_boil"].toInt() ? true:false; |
|
159 f.f_adjust_to_total_100 = obj["f_adjust_to_total_100"].toInt() ? true:false; |
|
160 f.f_percentage = obj["f_percentage"].toDouble(); |
|
161 f.f_di_ph = obj["f_di_ph"].toDouble(); |
|
162 f.f_acid_to_ph_57 = obj["f_acid_to_ph_57"].toDouble(); |
|
163 if (f.f_adjust_to_total_100) |
|
164 reci->fermentables_use100 = true; |
|
165 percentcheck += f.f_percentage; |
|
166 reci->fermentables.append(f); |
|
167 } |
|
168 if (percentcheck == 0) { |
|
169 /* Missing percentages, fix it. */ |
|
170 double total = 0; |
|
171 for (int i = 0; i < reci->fermentables.size(); i++) { |
|
172 if (reci->fermentables.at(i).f_added < 4) |
|
173 total += reci->fermentables.at(i).f_amount; |
|
174 } |
|
175 for (int i = 0; i < reci->fermentables.size(); i++) { |
|
176 if (reci->fermentables.at(i).f_added < 4) |
|
177 reci->fermentables[i].f_percentage = round((reci->fermentables.at(i).f_amount / total) * 10000.0) / 100.0; |
|
178 } |
|
179 qDebug() << " fixed missing percentages"; |
|
180 } |
|
181 } |
|
182 } else { |
|
183 qDebug() << "empty fermentables"; |
|
184 } |
|
185 |
|
186 const auto& h_json = query.value("json_hops").toString(); |
|
187 if (!h_json.trimmed().isEmpty()) { |
|
188 const auto& formattedJson = QString("%1").arg(h_json); |
|
189 QJsonDocument hops = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
190 if (parseError.error != QJsonParseError::NoError) { |
|
191 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset; |
|
192 } else if (hops.isArray()) { |
|
193 for (int i = 0; i < hops.array().size(); i++) { |
|
194 QJsonObject obj = hops.array().at(i).toObject(); |
|
195 Hops h; |
|
196 h.h_name = obj["h_name"].toString(); |
|
197 h.h_origin = obj["h_origin"].toString(); |
|
198 h.h_amount = obj["h_amount"].toDouble(); |
|
199 h.h_cost = obj["h_cost"].toDouble(); |
|
200 h.h_type = obj["h_type"].toInt(); |
|
201 h.h_form = obj["h_form"].toInt(); |
|
202 h.h_useat = obj["h_useat"].toInt(); |
|
203 h.h_time = obj["h_time"].toInt(); |
|
204 h.h_alpha = obj["h_alpha"].toDouble(); |
|
205 h.h_beta = obj["h_beta"].toDouble(); |
|
206 h.h_hsi = obj["h_hsi"].toDouble(); |
|
207 h.h_humulene = obj["h_humulene"].toDouble(); |
|
208 h.h_caryophyllene = obj["h_caryophyllene"].toDouble(); |
|
209 h.h_cohumulone = obj["h_cohumulone"].toDouble(); |
|
210 h.h_myrcene = obj["h_myrcene"].toDouble(); |
|
211 h.h_total_oil = obj["h_total_oil"].toDouble(); |
|
212 reci->hops.append(h); |
|
213 } |
|
214 } |
|
215 } else { |
|
216 qDebug() << "empty hops"; |
|
217 } |
|
218 |
|
219 const auto& m_json = query.value("json_miscs").toString(); |
|
220 if (!m_json.trimmed().isEmpty()) { |
|
221 const auto& formattedJson = QString("%1").arg(m_json); |
|
222 QJsonDocument miscs = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
223 if (parseError.error != QJsonParseError::NoError) { |
|
224 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset; |
|
225 } else if (miscs.isArray()) { |
|
226 for (int i = 0; i < miscs.array().size(); i++) { |
|
227 QJsonObject obj = miscs.array().at(i).toObject(); |
|
228 Miscs m; |
|
229 m.m_name = obj["m_name"].toString(); |
|
230 m.m_amount = obj["m_amount"].toDouble(); |
|
231 m.m_type = obj["m_type"].toInt(); |
|
232 m.m_use_use = obj["m_use_use"].toInt(); |
|
233 m.m_time = obj["m_time"].toDouble(); |
|
234 m.m_amount_is_weight = obj["m_amount_is_weight"].toInt() ? true:false; |
|
235 m.m_cost = obj["m_cost"].toDouble(); |
|
236 reci->miscs.append(m); |
|
237 } |
|
238 } |
|
239 } else { |
|
240 qDebug() << "empty miscs"; |
|
241 } |
|
242 |
|
243 const auto& y_json = query.value("json_yeasts").toString(); |
|
244 if (!y_json.trimmed().isEmpty()) { |
|
245 const auto& formattedJson = QString("%1").arg(y_json); |
|
246 QJsonDocument yeasts = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
247 if (parseError.error != QJsonParseError::NoError) { |
|
248 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
|
249 } else if (yeasts.isArray()) { |
|
250 for (int i = 0; i < yeasts.array().size(); i++) { |
|
251 QJsonObject obj = yeasts.array().at(i).toObject(); |
|
252 Yeasts y; |
|
253 /* First some defaults for newer fields. */ |
|
254 y.y_tolerance = y.y_harvest_time = y.y_pitch_temperature = y.y_zymocide = 0; |
|
255 y.y_sta1 = y.y_bacteria = y.y_harvest_top = y.y_pofpos = false; |
|
256 y.y_gr_hl_lo = 50; |
|
257 y.y_sg_lo = 1.04; |
|
258 y.y_gr_hl_hi = 80; |
|
259 y.y_sg_hi = 1.08; |
|
260 /* Now get what we have got */ |
|
261 y.y_name = obj["y_name"].toString(); |
|
262 y.y_laboratory = obj["y_laboratory"].toString(); |
|
263 y.y_product_id = obj["y_product_id"].toString(); |
|
264 y.y_amount = obj["y_amount"].toDouble(); |
|
265 y.y_type = obj["y_type"].toInt(); |
|
266 y.y_form = obj["y_form"].toInt(); |
|
267 y.y_min_temperature = obj["y_min_temperature"].toDouble(); |
|
268 y.y_max_temperature = obj["y_max_temperature"].toDouble(); |
|
269 y.y_flocculation = obj["y_flocculation"].toInt(); |
|
270 y.y_attenuation = obj["y_attenuation"].toDouble(); |
|
271 y.y_cells = obj["y_cells"].toDouble(); |
|
272 y.y_tolerance = obj["y_tolerance"].toDouble(); |
|
273 y.y_inventory = obj["y_inventory"].toDouble(); |
|
274 y.y_use = obj["y_use"].toInt(); |
|
275 y.y_sta1 = obj["y_sta1"].toInt() ? true:false; |
|
276 y.y_bacteria = obj["y_bacteria"].toInt() ? true:false; |
|
277 y.y_harvest_top = obj["y_harvest_top"].toInt() ? true:false; |
|
278 y.y_harvest_time = obj["y_harvest_time"].toInt(); |
|
279 y.y_pitch_temperature = obj["y_pitch_temperature"].toDouble(); |
|
280 y.y_pofpos = obj["y_pofpos"].toInt() ? true:false; |
|
281 y.y_zymocide = obj["y_zymocide"].toInt(); |
|
282 y.y_gr_hl_lo = obj["y_gr_hl_lo"].toInt(); |
|
283 y.y_sg_lo = obj["y_sg_lo"].toDouble(); |
|
284 y.y_gr_hl_hi = obj["y_gr_hl_hi"].toInt(); |
|
285 y.y_sg_hi = obj["y_sg_hi"].toDouble(); |
|
286 y.y_cost = obj["y_cost"].toDouble(); |
|
287 |
|
288 if (y.y_tolerance == 0 || y.y_cells == 0) { // More and better tests? |
|
289 /* |
|
290 * Possible data upgrade needed. |
|
291 */ |
|
292 yquery.prepare("SELECT tolerance,cells,sta1,bacteria,harvest_top,harvest_time,pitch_temperature," |
|
293 "pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi " |
|
294 "FROM inventory_yeasts WHERE name=:name AND laboratory=:laboratory AND product_id=:product_id"); |
|
295 yquery.bindValue(":name", y.y_name); |
|
296 yquery.bindValue(":laboratory", y.y_laboratory); |
|
297 yquery.bindValue(":product_id", y.y_product_id); |
|
298 yquery.exec(); |
|
299 if (yquery.first()) { |
|
300 y.y_tolerance = yquery.value(0).toDouble(); |
|
301 y.y_cells = yquery.value(1).toDouble(); |
|
302 y.y_sta1 = yquery.value(2).toInt() ? true:false; |
|
303 y.y_bacteria = yquery.value(3).toInt() ? true:false; |
|
304 y.y_harvest_top = yquery.value(4).toInt() ? true:false; |
|
305 y.y_harvest_time = yquery.value(5).toInt(); |
|
306 y.y_pitch_temperature = yquery.value(6).toDouble(); |
|
307 y.y_pofpos = yquery.value(7).toInt() ? true:false; |
|
308 y.y_zymocide = yquery.value(8).toInt(); |
|
309 y.y_gr_hl_lo = yquery.value(9).toInt(); |
|
310 y.y_sg_lo = yquery.value(10).toDouble(); |
|
311 y.y_gr_hl_hi = yquery.value(11).toInt(); |
|
312 y.y_sg_hi = yquery.value(12).toDouble(); |
|
313 } else { |
|
314 qDebug() << y.y_name << y.y_product_id << "not found for upgrade"; |
|
315 } |
|
316 } |
|
317 reci->yeasts.append(y); |
|
318 } |
|
319 } |
|
320 } else { |
|
321 qDebug() << "empty yeasts"; |
|
322 } |
|
323 |
|
324 const auto& ma_json = query.value("json_mashs").toString().trimmed(); |
|
325 if (!ma_json.trimmed().isEmpty()) { |
|
326 const auto& formattedJson = QString("%1").arg(ma_json); |
|
327 QJsonDocument mashs = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
328 if (parseError.error != QJsonParseError::NoError) { |
|
329 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
|
330 } else if (mashs.isArray()) { |
|
331 for (int i = 0; i < mashs.array().size(); i++) { |
|
332 QJsonObject obj = mashs.array().at(i).toObject(); |
|
333 Mashs m; |
|
334 m.step_name = obj["step_name"].toString(); |
|
335 m.step_type = obj["step_type"].toInt(); |
|
336 m.step_volume = obj["step_volume"].toDouble(); |
|
337 m.step_infuse_amount = obj["step_infuse_amount"].toDouble(); |
|
338 m.step_infuse_temp = obj["step_infuse_temp"].toDouble(); |
|
339 m.step_temp = obj["step_temp"].toDouble(); |
|
340 m.step_time = obj["step_time"].toDouble(); |
|
341 m.ramp_time = obj["ramp_time"].toDouble(); |
|
342 m.end_temp = obj["end_temp"].toDouble(); |
|
343 m.step_wg_ratio = obj["step_wg_ratio"].toDouble(); |
|
344 reci->mashs.append(m); |
|
345 } |
|
346 } |
|
347 } else { |
|
348 qDebug() << "empty mashs"; |
|
349 } |
|
350 |
|
351 qDebug() << "loadRecipe" << reci->record << "done"; |
|
352 return true; |
|
353 } |
|
354 |
|
355 |
|
356 bool DB_recipe::save(Recipe *reci, QDialog *dialog) |
|
357 { |
|
358 QSqlQuery query; |
|
359 |
|
360 if (reci->record == -1) { |
|
361 query.prepare("INSERT INTO recipes SET locked=:locked, st_name=:st_name, st_letter=:st_letter, " |
|
362 "st_guide=:st_guide, st_category=:st_category, st_category_number=:st_catnr, st_type=:st_type, " |
|
363 "st_og_min=:st_og_min, st_og_max=:st_og_max, st_fg_min=:st_fg_min, st_fg_max=:st_fg_max, " |
|
364 "st_ibu_min=:st_ibu_min, st_ibu_max=:st_ibu_max, st_color_min=:st_color_min, st_color_max=:st_color_max, " |
|
365 "st_carb_min=:st_carb_min, st_carb_max=:st_carb_max, st_abv_min=:st_abv_min, st_abv_max=:st_abv_max, " |
|
366 "name=:name, notes=:notes, type=:type, batch_size=:batch_size, boil_size=:boil_size, " |
|
367 "boil_time=:boil_time, efficiency=:efficiency, est_og=:est_og, est_fg=:est_fg, est_abv=:est_abv, " |
|
368 "est_color=:est_color, color_method=:color_method, est_ibu=:est_ibu, ibu_method=:ibu_method, " |
|
369 "est_carb=:est_carb, sparge_temp=:sparge_temp, sparge_ph=:sparge_ph, " |
|
370 "sparge_volume=:sparge_volume, sparge_source=:sparge_source, sparge_acid_type=:sparge_acid_type, " |
|
371 "sparge_acid_perc=:sparge_acid_perc, sparge_acid_amount=:sparge_acid_amount, mash_ph=:mash_ph, " |
|
372 "mash_name=:mash_name, calc_acid=:calc_acid, " |
|
373 "w1_name=:w1_name, w1_amount=:w1_amount, w1_calcium=:w1_calcium, w1_sulfate=:w1_sulfate, " |
|
374 "w1_chloride=:w1_chloride, w1_sodium=:w1_sodium, w1_magnesium=:w1_magnesium, " |
|
375 "w1_total_alkalinity=:w1_total_alkalinity, w1_ph=:w1_ph, w1_cost=:w1_cost, " |
|
376 "w2_name=:w2_name, w2_amount=:w2_amount, w2_calcium=:w2_calcium, w2_sulfate=:w2_sulfate, " |
|
377 "w2_chloride=:w2_chloride, w2_sodium=:w2_sodium, w2_magnesium=:w2_magnesium, " |
|
378 "w2_total_alkalinity=:w2_total_alkalinity, w2_ph=:w2_ph, w2_cost=:w2_cost, " |
|
379 "wg_amount=:wg_amount, wg_calcium=:wg_calcium, wg_sulfate=:wg_sulfate, " |
|
380 "wg_chloride=:wg_chloride, wg_sodium=:wg_sodium, wg_magnesium=:wg_magnesium, " |
|
381 "wg_total_alkalinity=:wg_total_alkalinity, wg_ph=:wg_ph, " |
|
382 "wb_calcium=:wb_calcium, wb_sulfate=:wb_sulfate, wb_chloride=:wb_chloride, wb_sodium=:wb_sodium, " |
|
383 "wb_magnesium=:wb_magnesium, wb_total_alkalinity=:wb_total_alkalinity, wb_ph=:wb_ph, " |
|
384 "wa_acid_name=:wa_acid_name, wa_acid_perc=:wa_acid_perc, wa_base_name=:wa_base_name, " |
|
385 "json_fermentables=:json_fermentables, json_hops=:json_hops, json_miscs=:json_miscs, " |
|
386 "json_yeasts=:json_yeasts, json_mashs=:json_mashs, uuid=:uuid"); |
|
387 } else { |
|
388 query.prepare("UPDATE recipes SET locked=:locked, st_name=:st_name, st_letter=:st_letter, " |
|
389 "st_guide=:st_guide, st_category=:st_category, st_category_number=:st_catnr, st_type=:st_type, " |
|
390 "st_og_min=:st_og_min, st_og_max=:st_og_max, st_fg_min=:st_fg_min, st_fg_max=:st_fg_max, " |
|
391 "st_ibu_min=:st_ibu_min, st_ibu_max=:st_ibu_max, st_color_min=:st_color_min, st_color_max=:st_color_max, " |
|
392 "st_carb_min=:st_carb_min, st_carb_max=:st_carb_max, st_abv_min=:st_abv_min, st_abv_max=:st_abv_max, " |
|
393 "name=:name, notes=:notes, type=:type, batch_size=:batch_size, boil_size=:boil_size, " |
|
394 "boil_time=:boil_time, efficiency=:efficiency, est_og=:est_og, est_fg=:est_fg, est_abv=:est_abv, " |
|
395 "est_color=:est_color, color_method=:color_method, est_ibu=:est_ibu, ibu_method=:ibu_method, " |
|
396 "est_carb=:est_carb, sparge_temp=:sparge_temp, sparge_ph=:sparge_ph, " |
|
397 "sparge_volume=:sparge_volume, sparge_source=:sparge_source, sparge_acid_type=:sparge_acid_type, " |
|
398 "sparge_acid_perc=:sparge_acid_perc, sparge_acid_amount=:sparge_acid_amount, mash_ph=:mash_ph, " |
|
399 "mash_name=:mash_name, calc_acid=:calc_acid, " |
|
400 "w1_name=:w1_name, w1_amount=:w1_amount, w1_calcium=:w1_calcium, w1_sulfate=:w1_sulfate, " |
|
401 "w1_chloride=:w1_chloride, w1_sodium=:w1_sodium, w1_magnesium=:w1_magnesium, " |
|
402 "w1_total_alkalinity=:w1_total_alkalinity, w1_ph=:w1_ph, w1_cost=:w1_cost, " |
|
403 "w2_name=:w2_name, w2_amount=:w2_amount, w2_calcium=:w2_calcium, w2_sulfate=:w2_sulfate, " |
|
404 "w2_chloride=:w2_chloride, w2_sodium=:w2_sodium, w2_magnesium=:w2_magnesium, " |
|
405 "w2_total_alkalinity=:w2_total_alkalinity, w2_ph=:w2_ph, w2_cost=:w2_cost, " |
|
406 "wg_amount=:wg_amount, wg_calcium=:wg_calcium, wg_sulfate=:wg_sulfate, " |
|
407 "wg_chloride=:wg_chloride, wg_sodium=:wg_sodium, wg_magnesium=:wg_magnesium, " |
|
408 "wg_total_alkalinity=:wg_total_alkalinity, wg_ph=:wg_ph, " |
|
409 "wb_calcium=:wb_calcium, wb_sulfate=:wb_sulfate, wb_chloride=:wb_chloride, wb_sodium=:wb_sodium, " |
|
410 "wb_magnesium=:wb_magnesium, wb_total_alkalinity=:wb_total_alkalinity, wb_ph=:wb_ph, " |
|
411 "wa_acid_name=:wa_acid_name, wa_acid_perc=:wa_acid_perc, wa_base_name=:wa_base_name, " |
|
412 "json_fermentables=:json_fermentables, json_hops=:json_hops, json_miscs=:json_miscs, " |
|
413 "json_yeasts=:json_yeasts, json_mashs=:json_mashs WHERE record = :recno"); |
|
414 } |
|
415 query.bindValue(":locked", reci->locked ? 1:0); |
|
416 query.bindValue(":st_name", reci->st_name); |
|
417 query.bindValue(":st_letter", reci->st_letter); |
|
418 query.bindValue(":st_guide", reci->st_guide); |
|
419 query.bindValue(":st_category", reci->st_category); |
|
420 query.bindValue(":st_catnr", reci->st_category_number); |
|
421 query.bindValue(":st_type", reci->st_type); |
|
422 query.bindValue(":st_og_min", round(reci->st_og_min * 1000) / 1000); |
|
423 query.bindValue(":st_og_max", round(reci->st_og_max * 1000) / 1000); |
|
424 query.bindValue(":st_fg_min", round(reci->st_fg_min * 1000) / 1000); |
|
425 query.bindValue(":st_fg_max", round(reci->st_fg_max * 1000) / 1000); |
|
426 query.bindValue(":st_ibu_min", round(reci->st_ibu_min * 10) / 10); |
|
427 query.bindValue(":st_ibu_max", round(reci->st_ibu_max * 10) / 10); |
|
428 query.bindValue(":st_color_min", round(reci->st_color_min * 10) / 10); |
|
429 query.bindValue(":st_color_max", round(reci->st_color_max * 10) / 10); |
|
430 query.bindValue(":st_carb_min", round(reci->st_carb_min * 10) / 10); |
|
431 query.bindValue(":st_carb_max", round(reci->st_carb_max * 10) / 10); |
|
432 query.bindValue(":st_abv_min", round(reci->st_abv_min * 10) / 10); |
|
433 query.bindValue(":st_abv_max", round(reci->st_abv_max * 10) / 10); |
|
434 query.bindValue(":name", reci->name); |
|
435 query.bindValue(":notes", reci->notes); |
|
436 query.bindValue(":type", reci->type); |
|
437 query.bindValue(":batch_size", round(reci->batch_size * 10) / 10); |
|
438 query.bindValue(":boil_size", round(reci->boil_size * 10) / 10); |
|
439 query.bindValue(":boil_time", round(reci->boil_time * 10) / 10); |
|
440 query.bindValue(":efficiency", round(reci->efficiency * 10) / 10); |
|
441 query.bindValue(":est_og", round(reci->est_og * 1000) / 1000); |
|
442 query.bindValue(":est_fg", round(reci->est_fg * 1000) / 1000); |
|
443 query.bindValue(":est_abv", round(reci->est_abv * 10) / 10); |
|
444 query.bindValue(":est_color", round(reci->est_color * 10) / 10); |
|
445 query.bindValue(":color_method", reci->color_method); |
|
446 query.bindValue(":est_ibu", round(reci->est_ibu * 10) / 10); |
|
447 query.bindValue(":ibu_method", reci->ibu_method); |
|
448 query.bindValue(":est_carb", round(reci->est_carb * 10) / 10); |
|
449 query.bindValue(":sparge_temp", round(reci->sparge_temp * 10) / 10); |
|
450 query.bindValue(":sparge_ph", round(reci->sparge_ph * 100) / 100); |
|
451 query.bindValue(":sparge_volume", round(reci->sparge_volume * 10) / 10); |
|
452 query.bindValue(":sparge_source", reci->sparge_source); |
|
453 query.bindValue(":sparge_acid_type", reci->sparge_acid_type); |
|
454 query.bindValue(":sparge_acid_perc", round(reci->sparge_acid_perc * 10) / 10); |
|
455 query.bindValue(":sparge_acid_amount", round(reci->sparge_acid_amount * 100000) / 100000); |
|
456 query.bindValue(":mash_ph", round(reci->mash_ph * 100) / 100); |
|
457 query.bindValue(":mash_name", reci->mash_name); |
|
458 query.bindValue(":calc_acid", reci->calc_acid ?1:0); |
|
459 query.bindValue(":w1_name", reci->w1_name); |
|
460 query.bindValue(":w1_amount", round(reci->w1_amount * 10) / 10); |
|
461 query.bindValue(":w1_calcium", round(reci->w1_calcium * 100000) / 100000); |
|
462 query.bindValue(":w1_sulfate", round(reci->w1_sulfate * 100000) / 100000); |
|
463 query.bindValue(":w1_chloride", round(reci->w1_chloride * 100000) / 100000); |
|
464 query.bindValue(":w1_sodium", round(reci->w1_sodium * 100000) / 100000); |
|
465 query.bindValue(":w1_magnesium", round(reci->w1_magnesium * 100000) / 100000); |
|
466 query.bindValue(":w1_total_alkalinity", round(reci->w1_total_alkalinity * 100000) / 100000); |
|
467 query.bindValue(":w1_ph", round(reci->w1_ph * 100) / 100); |
|
468 query.bindValue(":w1_cost", round(reci->w1_cost * 100) / 100); |
|
469 query.bindValue(":w2_name", reci->w2_name); |
|
470 query.bindValue(":w2_amount", round(reci->w2_amount * 10) / 10); |
|
471 query.bindValue(":w2_calcium", round(reci->w2_calcium * 100000) / 100000); |
|
472 query.bindValue(":w2_sulfate", round(reci->w2_sulfate * 100000) / 100000); |
|
473 query.bindValue(":w2_chloride", round(reci->w2_chloride * 100000) / 100000); |
|
474 query.bindValue(":w2_sodium", round(reci->w2_sodium * 100000) / 100000); |
|
475 query.bindValue(":w2_magnesium", round(reci->w2_magnesium * 100000) / 100000); |
|
476 query.bindValue(":w2_total_alkalinity", round(reci->w2_total_alkalinity * 100000) / 100000); |
|
477 query.bindValue(":w2_ph", round(reci->w2_ph * 100) / 100); |
|
478 query.bindValue(":w2_cost", round(reci->w2_cost * 100) / 100); |
|
479 query.bindValue(":wg_amount", round(reci->wg_amount * 10) / 10); |
|
480 query.bindValue(":wg_calcium", round(reci->wg_calcium * 100000) / 100000); |
|
481 query.bindValue(":wg_sulfate", round(reci->wg_sulfate * 100000) / 100000); |
|
482 query.bindValue(":wg_chloride", round(reci->wg_chloride * 100000) / 100000); |
|
483 query.bindValue(":wg_sodium", round(reci->wg_sodium * 100000) / 100000); |
|
484 query.bindValue(":wg_magnesium", round(reci->wg_magnesium * 100000) / 100000); |
|
485 query.bindValue(":wg_total_alkalinity", round(reci->wg_total_alkalinity * 100000) / 100000); |
|
486 query.bindValue(":wg_ph", round(reci->wg_ph * 100) / 100); |
|
487 query.bindValue(":wb_calcium", round(reci->wb_calcium * 100000) / 100000); |
|
488 query.bindValue(":wb_sulfate", round(reci->wb_sulfate * 100000) / 100000); |
|
489 query.bindValue(":wb_chloride", round(reci->wb_chloride * 100000) / 100000); |
|
490 query.bindValue(":wb_sodium", round(reci->wb_sodium * 100000) / 100000); |
|
491 query.bindValue(":wb_magnesium", round(reci->wb_magnesium * 100000) / 100000); |
|
492 query.bindValue(":wb_total_alkalinity", round(reci->wb_total_alkalinity * 100000) / 100000); |
|
493 query.bindValue(":wb_ph", round(reci->wb_ph * 100) / 100); |
|
494 query.bindValue(":wa_acid_name", reci->wa_acid_name); |
|
495 query.bindValue(":wa_acid_perc", round(reci->wa_acid_perc * 10) / 10); |
|
496 query.bindValue(":wa_base_name", reci->wa_base_name); |
|
497 |
|
498 if (reci->fermentables.size() == 0) { |
|
499 query.bindValue(":json_fermentables", "[]"); |
|
500 } else { |
|
501 QJsonArray array; |
|
502 for (int i = 0; i < reci->fermentables.size(); i++) { |
|
503 QJsonObject obj; |
|
504 obj.insert("f_name", reci->fermentables.at(i).f_name); |
|
505 obj.insert("f_origin", reci->fermentables.at(i).f_origin); |
|
506 obj.insert("f_supplier", reci->fermentables.at(i).f_supplier); |
|
507 obj.insert("f_amount", round(reci->fermentables.at(i).f_amount * 10000) / 10000); |
|
508 obj.insert("f_cost", round(reci->fermentables.at(i).f_cost * 1000) / 1000); |
|
509 obj.insert("f_type", reci->fermentables.at(i).f_type); |
|
510 obj.insert("f_yield", round(reci->fermentables.at(i).f_yield * 10) / 10); |
|
511 obj.insert("f_color", round(reci->fermentables.at(i).f_color * 10) / 10); |
|
512 obj.insert("f_coarse_fine_diff", round(reci->fermentables.at(i).f_coarse_fine_diff * 10) / 10); |
|
513 obj.insert("f_moisture", round(reci->fermentables.at(i).f_moisture * 10) / 10); |
|
514 obj.insert("f_diastatic_power", round(reci->fermentables.at(i).f_diastatic_power * 100000) / 100000); |
|
515 obj.insert("f_protein", round(reci->fermentables.at(i).f_protein * 10) / 10); |
|
516 obj.insert("f_dissolved_protein", round(reci->fermentables.at(i).f_dissolved_protein * 10) / 10); |
|
517 obj.insert("f_max_in_batch", reci->fermentables.at(i).f_max_in_batch); |
|
518 obj.insert("f_graintype", reci->fermentables.at(i).f_graintype); |
|
519 obj.insert("f_added", reci->fermentables.at(i).f_added); |
|
520 obj.insert("f_recommend_mash", reci->fermentables.at(i).f_recommend_mash ? 1:0); |
|
521 obj.insert("f_add_after_boil", reci->fermentables.at(i).f_add_after_boil ? 1:0); |
|
522 obj.insert("f_adjust_to_total_100", reci->fermentables.at(i).f_adjust_to_total_100 ? 1:0); |
|
523 obj.insert("f_percentage", round(reci->fermentables.at(i).f_percentage * 10) / 10); |
|
524 obj.insert("f_di_ph", round(reci->fermentables.at(i).f_di_ph * 100000) / 100000); |
|
525 obj.insert("f_acid_to_ph_57", round(reci->fermentables.at(i).f_acid_to_ph_57 * 100000) / 100000); |
|
526 array.append(obj); /* Append this object */ |
|
527 } |
|
528 QJsonDocument doc; |
|
529 doc.setArray(array); |
|
530 query.bindValue(":json_fermentables", doc.toJson(QJsonDocument::Compact)); |
|
531 } |
|
532 |
|
533 if (reci->hops.size() == 0) { |
|
534 query.bindValue(":json_hops", "[]"); |
|
535 } else { |
|
536 QJsonArray array; |
|
537 for (int i = 0; i < reci->hops.size(); i++) { |
|
538 QJsonObject obj; |
|
539 obj.insert("h_name", reci->hops.at(i).h_name); |
|
540 obj.insert("h_origin", reci->hops.at(i).h_origin); |
|
541 obj.insert("h_amount", round(reci->hops.at(i).h_amount * 10000) / 10000); |
|
542 obj.insert("h_cost", round(reci->hops.at(i).h_cost * 100) / 100); |
|
543 obj.insert("h_type", reci->hops.at(i).h_type); |
|
544 obj.insert("h_form", reci->hops.at(i).h_form); |
|
545 obj.insert("h_useat", reci->hops.at(i).h_useat); |
|
546 obj.insert("h_time", round(reci->hops.at(i).h_time)); |
|
547 obj.insert("h_alpha", round(reci->hops.at(i).h_alpha * 100) / 100); |
|
548 obj.insert("h_beta", round(reci->hops.at(i).h_beta * 100) / 100); |
|
549 obj.insert("h_hsi", round(reci->hops.at(i).h_hsi * 100) / 100); |
|
550 obj.insert("h_humulene", round(reci->hops.at(i).h_humulene * 100) / 100); |
|
551 obj.insert("h_caryophyllene", round(reci->hops.at(i).h_caryophyllene * 100) / 100); |
|
552 obj.insert("h_cohumulone", round(reci->hops.at(i).h_cohumulone * 100) / 100); |
|
553 obj.insert("h_myrcene", round(reci->hops.at(i).h_myrcene * 100) / 100); |
|
554 obj.insert("h_total_oil", round(reci->hops.at(i).h_total_oil * 100) / 100); |
|
555 array.append(obj); /* Append this object */ |
|
556 } |
|
557 QJsonDocument doc; |
|
558 doc.setArray(array); |
|
559 query.bindValue(":json_hops", doc.toJson(QJsonDocument::Compact)); |
|
560 } |
|
561 |
|
562 if (reci->miscs.size() == 0) { |
|
563 query.bindValue(":json_miscs", "[]"); |
|
564 } else { |
|
565 QJsonArray array; |
|
566 for (int i = 0; i < reci->miscs.size(); i++) { |
|
567 QJsonObject obj; |
|
568 obj.insert("m_name", reci->miscs.at(i).m_name); |
|
569 obj.insert("m_amount", round(reci->miscs.at(i).m_amount * 10000) / 10000); |
|
570 obj.insert("m_type", reci->miscs.at(i).m_type); |
|
571 obj.insert("m_use_use", reci->miscs.at(i).m_use_use); |
|
572 obj.insert("m_time", round(reci->miscs.at(i).m_time)); |
|
573 obj.insert("m_amount_is_weight", reci->miscs.at(i).m_amount_is_weight ? 1:0); |
|
574 obj.insert("m_cost", round(reci->miscs.at(i).m_cost * 10000) / 10000); |
|
575 array.append(obj); /* Append this object */ |
|
576 } |
|
577 QJsonDocument doc; |
|
578 doc.setArray(array); |
|
579 query.bindValue(":json_miscs", doc.toJson(QJsonDocument::Compact)); |
|
580 } |
|
581 |
|
582 if (reci->yeasts.size() == 0) { |
|
583 query.bindValue(":json_yeasts", "[]"); |
|
584 } else { |
|
585 QJsonArray array; |
|
586 for (int i = 0; i < reci->yeasts.size(); i++) { |
|
587 QJsonObject obj; |
|
588 obj.insert("y_name", reci->yeasts.at(i).y_name); |
|
589 obj.insert("y_laboratory", reci->yeasts.at(i).y_laboratory); |
|
590 obj.insert("y_product_id", reci->yeasts.at(i).y_product_id); |
|
591 obj.insert("y_amount", round(reci->yeasts.at(i).y_amount * 10000) / 10000); |
|
592 obj.insert("y_type", reci->yeasts.at(i).y_type); |
|
593 obj.insert("y_form", reci->yeasts.at(i).y_form); |
|
594 obj.insert("y_min_temperature", round(reci->yeasts.at(i).y_min_temperature * 10) / 10); |
|
595 obj.insert("y_max_temperature", round(reci->yeasts.at(i).y_max_temperature * 10) / 10); |
|
596 obj.insert("y_flocculation", reci->yeasts.at(i).y_flocculation); |
|
597 obj.insert("y_attenuation", round(reci->yeasts.at(i).y_attenuation * 10) / 10); |
|
598 obj.insert("y_cells", reci->yeasts.at(i).y_cells); |
|
599 obj.insert("y_tolerance", round(reci->yeasts.at(i).y_tolerance * 10) / 10); |
|
600 obj.insert("y_inventory", round(reci->yeasts.at(i).y_inventory * 10000) / 10000); |
|
601 obj.insert("y_use", reci->yeasts.at(i).y_use); |
|
602 obj.insert("y_sta1", reci->yeasts.at(i).y_sta1 ? 1:0); |
|
603 obj.insert("y_bacteria", reci->yeasts.at(i).y_bacteria ? 1:0); |
|
604 obj.insert("y_harvest_top", reci->yeasts.at(i).y_harvest_top ? 1:0); |
|
605 obj.insert("y_harvest_time", reci->yeasts.at(i).y_harvest_time); |
|
606 obj.insert("y_pitch_temperature", round(reci->yeasts.at(i).y_pitch_temperature * 10) / 10); |
|
607 obj.insert("y_pofpos", reci->yeasts.at(i).y_pofpos ? 1:0); |
|
608 obj.insert("y_zymocide", reci->yeasts.at(i).y_zymocide); |
|
609 obj.insert("y_gr_hl_lo", reci->yeasts.at(i).y_gr_hl_lo); |
|
610 obj.insert("y_sg_lo", round(reci->yeasts.at(i).y_sg_lo * 1000) / 1000); |
|
611 obj.insert("y_gr_hl_hi", reci->yeasts.at(i).y_gr_hl_hi); |
|
612 obj.insert("y_sg_hi", round(reci->yeasts.at(i).y_sg_hi * 1000) / 1000); |
|
613 obj.insert("y_cost", round(reci->yeasts.at(i).y_cost * 1000) / 1000); |
|
614 array.append(obj); /* Append this object */ |
|
615 } |
|
616 QJsonDocument doc; |
|
617 doc.setArray(array); |
|
618 query.bindValue(":json_yeasts", doc.toJson(QJsonDocument::Compact)); |
|
619 } |
|
620 |
|
621 if (reci->mashs.size() == 0) { |
|
622 query.bindValue(":json_mashs", "[]"); |
|
623 } else { |
|
624 QJsonArray array; |
|
625 for (int i = 0; i < reci->mashs.size(); i++) { |
|
626 QJsonObject obj; |
|
627 obj.insert("step_name", reci->mashs.at(i).step_name); |
|
628 obj.insert("step_type", reci->mashs.at(i).step_type); |
|
629 obj.insert("step_volume", round(reci->mashs.at(i).step_volume * 100) / 100); |
|
630 obj.insert("step_infuse_amount", round(reci->mashs.at(i).step_infuse_amount * 100) / 100); |
|
631 obj.insert("step_infuse_temp", round(reci->mashs.at(i).step_infuse_temp * 100) / 100); |
|
632 obj.insert("step_temp", round(reci->mashs.at(i).step_temp * 100) / 100); |
|
633 obj.insert("step_time", round(reci->mashs.at(i).step_time * 100) / 100); |
|
634 obj.insert("ramp_time", round(reci->mashs.at(i).ramp_time * 100) / 100); |
|
635 obj.insert("end_temp", round(reci->mashs.at(i).end_temp * 100) / 100); |
|
636 obj.insert("step_wg_ratio", round(reci->mashs.at(i).step_wg_ratio * 100) / 100); |
|
637 array.append(obj); /* Append this object */ |
|
638 } |
|
639 QJsonDocument doc; |
|
640 doc.setArray(array); |
|
641 query.bindValue(":json_mashs", doc.toJson(QJsonDocument::Compact)); |
|
642 } |
|
643 |
|
644 if (reci->record == -1) { |
|
645 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
|
646 } else { |
|
647 query.bindValue(":recno", reci->record); |
|
648 } |
|
649 query.exec(); |
|
650 qDebug() << query.lastQuery(); |
|
651 if (query.lastError().isValid()) { |
|
652 qDebug() << "EditRecipe" << query.lastError(); |
|
653 QMessageBox::warning(dialog, QObject::tr("Database error"), |
|
654 QObject::tr("MySQL error: %1\n%2\n%3") |
|
655 .arg(query.lastError().nativeErrorCode()) |
|
656 .arg(query.lastError().driverText()) |
|
657 .arg(query.lastError().databaseText())); |
|
658 return false; |
|
659 } else { |
|
660 /* |
|
661 * If this was a new recipe, find out what record number we |
|
662 * have got and set it. So when the user saves this record |
|
663 * again, it will be updated instead of inserting a new copy. |
|
664 */ |
|
665 if (reci->record < 0) { |
|
666 QVariant id = query.lastInsertId(); |
|
667 reci->record = id.toInt(); |
|
668 qDebug() << "saveRecipe Inserted record" << reci->record; |
|
669 } else { |
|
670 qDebug() << "saveRecipe Updated record" << reci->record; |
|
671 } |
|
672 } |
|
673 return true; |
|
674 } |
|
675 |
|
676 |
|
677 bool DB_recipe::dele(QDialog *dialog, int recno) |
|
678 { |
|
679 QSqlQuery query; |
|
680 |
|
681 query.prepare("DELETE FROM recipes WHERE record = :recno"); |
|
682 query.bindValue(":recno", recno); |
|
683 query.exec(); |
|
684 if (query.lastError().isValid()) { |
|
685 qDebug() << "deleteRecipe" << query.lastError(); |
|
686 QMessageBox::warning(dialog, QObject::tr("Database error"), |
|
687 QObject::tr("MySQL error: %1\n%2\n%3") |
|
688 .arg(query.lastError().nativeErrorCode()) |
|
689 .arg(query.lastError().driverText()) |
|
690 .arg(query.lastError().databaseText())); |
|
691 return false; |
|
692 } |
|
693 |
|
694 qDebug() << "deleteRecipe Deleted" << recno; |
|
695 return true; |
|
696 } |
|
697 |