20 |
20 |
21 |
21 |
22 bool DB_product::load(Product *prod, QDialog *dialog, int recno) |
22 bool DB_product::load(Product *prod, QDialog *dialog, int recno) |
23 { |
23 { |
24 QSqlQuery query, yquery; |
24 QSqlQuery query, yquery; |
25 |
|
26 /* |
|
27 * Upgrade database extra columns for target water. |
|
28 */ |
|
29 query.exec("SHOW COLUMNS FROM `products` LIKE 'tw_name'"); |
|
30 if (! query.first()) { |
|
31 qWarning() << "loadProduct upgrade for target water"; |
|
32 QString sql = "ALTER TABLE `products` ADD `tw_name` VARCHAR(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL AFTER `calc_acid`, "; |
|
33 sql.append("ADD `tw_calcium` FLOAT NOT NULL DEFAULT '0' AFTER `tw_name`, "); |
|
34 sql.append("ADD `tw_sulfate` FLOAT NOT NULL DEFAULT '0' AFTER `tw_calcium`, "); |
|
35 sql.append("ADD `tw_chloride` FLOAT NOT NULL DEFAULT '0' AFTER `tw_sulfate`, "); |
|
36 sql.append("ADD `tw_sodium` FLOAT NOT NULL DEFAULT '0' AFTER `tw_chloride`, "); |
|
37 sql.append("ADD `tw_magnesium` FLOAT NOT NULL DEFAULT '0' AFTER `tw_sodium`, "); |
|
38 sql.append("ADD `tw_total_alkalinity` FLOAT NOT NULL DEFAULT '0' AFTER `tw_magnesium`;"); |
|
39 // qDebug() << sql; |
|
40 query.exec(sql); |
|
41 if (query.lastError().isValid()) { |
|
42 qWarning() << "loadProduct upgrade" << query.lastError(); |
|
43 QMessageBox::warning(dialog, QObject::tr("Database error"), |
|
44 QObject::tr("MySQL error: %1\n%2\n%3") |
|
45 .arg(query.lastError().nativeErrorCode()) |
|
46 .arg(query.lastError().driverText()) |
|
47 .arg(query.lastError().databaseText())); |
|
48 } |
|
49 } |
|
50 |
25 |
51 query.prepare("SELECT * FROM products WHERE record = :recno"); |
26 query.prepare("SELECT * FROM products WHERE record = :recno"); |
52 query.bindValue(":recno", recno); |
27 query.bindValue(":recno", recno); |
53 query.exec(); |
28 query.exec(); |
54 if (! query.first()) { |
29 if (! query.first()) { |
99 prod->eq_chiller_type = query.value("eq_chiller_type").toInt(); |
74 prod->eq_chiller_type = query.value("eq_chiller_type").toInt(); |
100 prod->eq_chiller_to79 = query.value("eq_chiller_to79").toDouble(); |
75 prod->eq_chiller_to79 = query.value("eq_chiller_to79").toDouble(); |
101 prod->eq_chiller_volume = query.value("eq_chiller_volume").toDouble(); |
76 prod->eq_chiller_volume = query.value("eq_chiller_volume").toDouble(); |
102 prod->eq_chiller_lpm = query.value("eq_chiller_lpm").toDouble(); |
77 prod->eq_chiller_lpm = query.value("eq_chiller_lpm").toDouble(); |
103 prod->eq_chiller_loss = query.value("eq_chiller_loss").toDouble(); |
78 prod->eq_chiller_loss = query.value("eq_chiller_loss").toDouble(); |
|
79 prod->eq_HLT_volume = query.value("eq_HLT_volume").toDouble(); |
|
80 prod->eq_HLT_deadspace = query.value("eq_HLT_deadspace").toDouble(); |
104 |
81 |
105 prod->brew_date_start = query.value("brew_date_start").toDateTime(); |
82 prod->brew_date_start = query.value("brew_date_start").toDateTime(); |
106 prod->brew_mash_ph = query.value("brew_mash_ph").toDouble(); |
83 prod->brew_mash_ph = query.value("brew_mash_ph").toDouble(); |
107 prod->brew_mash_sg = query.value("brew_mash_sg").toDouble(); |
84 prod->brew_mash_sg = query.value("brew_mash_sg").toDouble(); |
108 prod->brew_mash_efficiency = query.value("brew_mash_efficiency").toDouble(); |
85 prod->brew_mash_efficiency = query.value("brew_mash_efficiency").toDouble(); |
261 prod->wb_chloride = query.value("wb_chloride").toDouble(); |
238 prod->wb_chloride = query.value("wb_chloride").toDouble(); |
262 prod->wb_sodium = query.value("wb_sodium").toDouble(); |
239 prod->wb_sodium = query.value("wb_sodium").toDouble(); |
263 prod->wb_magnesium = query.value("wb_magnesium").toDouble(); |
240 prod->wb_magnesium = query.value("wb_magnesium").toDouble(); |
264 prod->wb_total_alkalinity = query.value("wb_total_alkalinity").toDouble(); |
241 prod->wb_total_alkalinity = query.value("wb_total_alkalinity").toDouble(); |
265 prod->wb_ph = query.value("wb_ph").toDouble(); |
242 prod->wb_ph = query.value("wb_ph").toDouble(); |
|
243 prod->tw_name = query.value("tw_name").toString(); |
|
244 prod->tw_calcium = query.value("tw_calcium").toDouble(); |
|
245 prod->tw_sulfate = query.value("tw_sulfate").toDouble(); |
|
246 prod->tw_chloride = query.value("tw_chloride").toDouble(); |
|
247 prod->tw_sodium = query.value("tw_sodium").toDouble(); |
|
248 prod->tw_magnesium = query.value("tw_magnesium").toDouble(); |
|
249 prod->tw_total_alkalinity = query.value("tw_total_alkalinity").toDouble(); |
|
250 prod->tw_ph = query.value("tw_ph").toDouble(); |
266 prod->wa_acid_name = query.value("wa_acid_name").toInt(); |
251 prod->wa_acid_name = query.value("wa_acid_name").toInt(); |
267 prod->wa_acid_perc = query.value("wa_acid_perc").toDouble(); |
252 prod->wa_acid_perc = query.value("wa_acid_perc").toDouble(); |
268 prod->wa_base_name = query.value("wa_base_name").toInt(); |
253 prod->wa_base_name = query.value("wa_base_name").toInt(); |
269 |
254 |
270 prod->starter_enable = query.value("starter_enable").toInt() ? true:false; |
255 prod->starter_enable = query.value("starter_enable").toInt() ? true:false; |
613 "eq_boil_time=:eq_boil_time, eq_top_up_kettle=:eq_top_up_kettle, eq_notes=:eq_notes, " |
598 "eq_boil_time=:eq_boil_time, eq_top_up_kettle=:eq_top_up_kettle, eq_notes=:eq_notes, " |
614 "eq_lauter_deadspace=:eq_lauter_deadspace, eq_kettle_volume=:eq_kettle_volume, " |
599 "eq_lauter_deadspace=:eq_lauter_deadspace, eq_kettle_volume=:eq_kettle_volume, " |
615 "eq_kettle_height=:eq_kettle_height, eq_mash_volume=:eq_mash_volume, eq_mash_max=:eq_mash_max, " |
600 "eq_kettle_height=:eq_kettle_height, eq_mash_volume=:eq_mash_volume, eq_mash_max=:eq_mash_max, " |
616 "eq_chiller_type=:eq_chiller_type, eq_chiller_to79=:eq_chiller_to79, eq_chiller_volume=:eq_chiller_volume, " |
601 "eq_chiller_type=:eq_chiller_type, eq_chiller_to79=:eq_chiller_to79, eq_chiller_volume=:eq_chiller_volume, " |
617 "eq_chiller_lpm=:eq_chiller_lpm, eq_chiller_loss=:eq_chiller_loss, " |
602 "eq_chiller_lpm=:eq_chiller_lpm, eq_chiller_loss=:eq_chiller_loss, " |
|
603 "eq_HLT_volume=:eq_HLT_volume, eq_HLT_deadspace=:eq_HLT_deadspace, " |
618 "brew_date_start=:brew_date_start, brew_mash_ph=:brew_mash_ph, brew_mash_sg=:brew_mash_sg, " |
604 "brew_date_start=:brew_date_start, brew_mash_ph=:brew_mash_ph, brew_mash_sg=:brew_mash_sg, " |
619 "brew_mash_efficiency=:brew_mash_efficiency, brew_sparge_temperature=:brew_sparge_temperature, " |
605 "brew_mash_efficiency=:brew_mash_efficiency, brew_sparge_temperature=:brew_sparge_temperature, " |
620 "brew_sparge_volume=:brew_sparge_volume, brew_sparge_est=:brew_sparge_est, brew_sparge_ph=:brew_sparge_ph, " |
606 "brew_sparge_volume=:brew_sparge_volume, brew_sparge_est=:brew_sparge_est, brew_sparge_ph=:brew_sparge_ph, " |
621 "brew_preboil_volume=:brew_preboil_volume, brew_preboil_sg=:brew_preboil_sg, brew_preboil_ph=:brew_preboil_ph, " |
607 "brew_preboil_volume=:brew_preboil_volume, brew_preboil_sg=:brew_preboil_sg, brew_preboil_ph=:brew_preboil_ph, " |
622 "brew_preboil_efficiency=:brew_preboil_efficiency, brew_aboil_volume=:brew_aboil_volume, " |
608 "brew_preboil_efficiency=:brew_preboil_efficiency, brew_aboil_volume=:brew_aboil_volume, " |
663 "wg_amount=:wg_amount, wg_calcium=:wg_calcium, wg_sulfate=:wg_sulfate, " |
649 "wg_amount=:wg_amount, wg_calcium=:wg_calcium, wg_sulfate=:wg_sulfate, " |
664 "wg_chloride=:wg_chloride, wg_sodium=:wg_sodium, wg_magnesium=:wg_magnesium, " |
650 "wg_chloride=:wg_chloride, wg_sodium=:wg_sodium, wg_magnesium=:wg_magnesium, " |
665 "wg_total_alkalinity=:wg_total_alkalinity, wg_ph=:wg_ph, " |
651 "wg_total_alkalinity=:wg_total_alkalinity, wg_ph=:wg_ph, " |
666 "wb_calcium=:wb_calcium, wb_sulfate=:wb_sulfate, wb_chloride=:wb_chloride, wb_sodium=:wb_sodium, " |
652 "wb_calcium=:wb_calcium, wb_sulfate=:wb_sulfate, wb_chloride=:wb_chloride, wb_sodium=:wb_sodium, " |
667 "wb_magnesium=:wb_magnesium, wb_total_alkalinity=:wb_total_alkalinity, wb_ph=:wb_ph, " |
653 "wb_magnesium=:wb_magnesium, wb_total_alkalinity=:wb_total_alkalinity, wb_ph=:wb_ph, " |
|
654 "tw_name=:tw_name, tw_calcium=:tw_calcium, tw_sulfate=:tw_sulfate, tw_chloride=:tw_chloride, " |
|
655 "tw_sodium=:tw_sodium, tw_magnesium=:tw_magnesium, tw_total_alkalinity=:tw_total_alkalinity, tw_ph=:tw_ph, " |
668 "wa_acid_name=:wa_acid_name, wa_acid_perc=:wa_acid_perc, wa_base_name=:wa_base_name, " |
656 "wa_acid_name=:wa_acid_name, wa_acid_perc=:wa_acid_perc, wa_base_name=:wa_base_name, " |
669 "starter_enable=:starter_enable, starter_type=:starter_type, starter_sg=:starter_sg, " |
657 "starter_enable=:starter_enable, starter_type=:starter_type, starter_sg=:starter_sg, " |
670 "starter_viability=:starter_viability, yeast_prod_date=:yeast_prod_date, yeast_pitchrate=:yeast_pitchrate, " |
658 "starter_viability=:starter_viability, yeast_prod_date=:yeast_prod_date, yeast_pitchrate=:yeast_pitchrate, " |
671 "prop1_type=:prop1_type, prop1_volume=:prop1_volume, prop2_type=:prop2_type, prop2_volume=:prop2_volume, " |
659 "prop1_type=:prop1_type, prop1_volume=:prop1_volume, prop2_type=:prop2_type, prop2_volume=:prop2_volume, " |
672 "prop3_type=:prop3_type, prop3_volume=:prop3_volume, prop4_type=:prop4_type, prop4_volume=:prop4_volume, " |
660 "prop3_type=:prop3_type, prop3_volume=:prop3_volume, prop4_type=:prop4_type, prop4_volume=:prop4_volume, " |
716 query.bindValue(":eq_chiller_type", prod->eq_chiller_type); |
704 query.bindValue(":eq_chiller_type", prod->eq_chiller_type); |
717 query.bindValue(":eq_chiller_to79", round(prod->eq_chiller_to79)); |
705 query.bindValue(":eq_chiller_to79", round(prod->eq_chiller_to79)); |
718 query.bindValue(":eq_chiller_volume", round(prod->eq_chiller_volume * 100) / 100); |
706 query.bindValue(":eq_chiller_volume", round(prod->eq_chiller_volume * 100) / 100); |
719 query.bindValue(":eq_chiller_lpm", round(prod->eq_chiller_lpm * 100) / 100); |
707 query.bindValue(":eq_chiller_lpm", round(prod->eq_chiller_lpm * 100) / 100); |
720 query.bindValue(":eq_chiller_loss", round(prod->eq_chiller_loss * 100) / 100); |
708 query.bindValue(":eq_chiller_loss", round(prod->eq_chiller_loss * 100) / 100); |
|
709 query.bindValue(":eq_HLT_volume", round(prod->eq_HLT_volume * 10) / 10); |
|
710 query.bindValue(":eq_HLT_deadspace", round(prod->eq_HLT_deadspace * 10) / 10); |
721 query.bindValue(":brew_date_start", prod->brew_date_start); |
711 query.bindValue(":brew_date_start", prod->brew_date_start); |
722 query.bindValue(":brew_mash_ph", round(prod->brew_mash_ph * 100) / 100); |
712 query.bindValue(":brew_mash_ph", round(prod->brew_mash_ph * 100) / 100); |
723 query.bindValue(":brew_mash_sg", round(prod->brew_mash_sg * 1000) / 1000); |
713 query.bindValue(":brew_mash_sg", round(prod->brew_mash_sg * 1000) / 1000); |
724 query.bindValue(":brew_mash_efficiency", round(prod->brew_mash_efficiency * 10) / 10); |
714 query.bindValue(":brew_mash_efficiency", round(prod->brew_mash_efficiency * 10) / 10); |
725 query.bindValue(":brew_sparge_temperature", round(prod->brew_sparge_temperature * 10) / 10); |
715 query.bindValue(":brew_sparge_temperature", round(prod->brew_sparge_temperature * 10) / 10); |
868 query.bindValue(":wb_chloride", round(prod->wb_chloride * 100000) / 100000); |
858 query.bindValue(":wb_chloride", round(prod->wb_chloride * 100000) / 100000); |
869 query.bindValue(":wb_sodium", round(prod->wb_sodium * 100000) / 100000); |
859 query.bindValue(":wb_sodium", round(prod->wb_sodium * 100000) / 100000); |
870 query.bindValue(":wb_magnesium", round(prod->wb_magnesium * 100000) / 100000); |
860 query.bindValue(":wb_magnesium", round(prod->wb_magnesium * 100000) / 100000); |
871 query.bindValue(":wb_total_alkalinity", round(prod->wb_total_alkalinity * 100000) / 100000); |
861 query.bindValue(":wb_total_alkalinity", round(prod->wb_total_alkalinity * 100000) / 100000); |
872 query.bindValue(":wb_ph", round(prod->wb_ph * 100) / 100); |
862 query.bindValue(":wb_ph", round(prod->wb_ph * 100) / 100); |
|
863 query.bindValue(":tw_name", prod->tw_name); |
|
864 query.bindValue(":tw_calcium", round(prod->tw_calcium * 100000) / 100000); |
|
865 query.bindValue(":tw_sulfate", round(prod->tw_sulfate * 100000) / 100000); |
|
866 query.bindValue(":tw_chloride", round(prod->tw_chloride * 100000) / 100000); |
|
867 query.bindValue(":tw_sodium", round(prod->tw_sodium * 100000) / 100000); |
|
868 query.bindValue(":tw_magnesium", round(prod->tw_magnesium * 100000) / 100000); |
|
869 query.bindValue(":tw_total_alkalinity", round(prod->tw_total_alkalinity * 100000) / 100000); |
|
870 query.bindValue(":tw_ph", round(prod->tw_ph * 100) / 100); |
873 query.bindValue(":wa_acid_name", prod->wa_acid_name); |
871 query.bindValue(":wa_acid_name", prod->wa_acid_name); |
874 query.bindValue(":wa_acid_perc", round(prod->wa_acid_perc * 10) / 10); |
872 query.bindValue(":wa_acid_perc", round(prod->wa_acid_perc * 10) / 10); |
875 query.bindValue(":wa_base_name", prod->wa_base_name); |
873 query.bindValue(":wa_base_name", prod->wa_base_name); |
876 query.bindValue(":starter_enable", prod->starter_enable ? 1:0); |
874 query.bindValue(":starter_enable", prod->starter_enable ? 1:0); |
877 query.bindValue(":starter_type", prod->starter_type); |
875 query.bindValue(":starter_type", prod->starter_type); |