src/database/db_product.cpp

changeset 527
84091b9cb800
parent 526
3b9abdae181e
--- a/src/database/db_product.cpp	Sat Jun 01 21:10:54 2024 +0200
+++ b/src/database/db_product.cpp	Sat Jun 08 15:54:30 2024 +0200
@@ -23,31 +23,6 @@
 {
     QSqlQuery query, yquery;
 
-    /*
-     * Upgrade database extra columns for target water.
-     */
-    query.exec("SHOW COLUMNS FROM `products` LIKE 'tw_name'");
-    if (! query.first()) {
-	qWarning() << "loadProduct upgrade for target water";
-	QString sql = "ALTER TABLE `products` ADD `tw_name` VARCHAR(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NULL AFTER `calc_acid`, ";
-	sql.append("ADD `tw_calcium` FLOAT NOT NULL DEFAULT '0' AFTER `tw_name`, ");
-	sql.append("ADD `tw_sulfate` FLOAT NOT NULL DEFAULT '0' AFTER `tw_calcium`, ");
-	sql.append("ADD `tw_chloride` FLOAT NOT NULL DEFAULT '0' AFTER `tw_sulfate`, ");
-	sql.append("ADD `tw_sodium` FLOAT NOT NULL DEFAULT '0' AFTER `tw_chloride`, ");
-	sql.append("ADD `tw_magnesium` FLOAT NOT NULL DEFAULT '0' AFTER `tw_sodium`, ");
-	sql.append("ADD `tw_total_alkalinity` FLOAT NOT NULL DEFAULT '0' AFTER `tw_magnesium`;");
-//	qDebug() << sql;
-	query.exec(sql);
-	if (query.lastError().isValid()) {
-            qWarning() << "loadProduct upgrade" << query.lastError();
-            QMessageBox::warning(dialog, QObject::tr("Database error"),
-                        QObject::tr("MySQL error: %1\n%2\n%3")
-                        .arg(query.lastError().nativeErrorCode())
-                        .arg(query.lastError().driverText())
-                        .arg(query.lastError().databaseText()));
-	}
-    }
-
     query.prepare("SELECT * FROM products WHERE record = :recno");
     query.bindValue(":recno", recno);
     query.exec();
@@ -101,6 +76,8 @@
     prod->eq_chiller_volume = query.value("eq_chiller_volume").toDouble();
     prod->eq_chiller_lpm = query.value("eq_chiller_lpm").toDouble();
     prod->eq_chiller_loss = query.value("eq_chiller_loss").toDouble();
+    prod->eq_HLT_volume = query.value("eq_HLT_volume").toDouble();
+    prod->eq_HLT_deadspace = query.value("eq_HLT_deadspace").toDouble();
 
     prod->brew_date_start = query.value("brew_date_start").toDateTime();
     prod->brew_mash_ph = query.value("brew_mash_ph").toDouble();
@@ -263,6 +240,14 @@
     prod->wb_magnesium = query.value("wb_magnesium").toDouble();
     prod->wb_total_alkalinity = query.value("wb_total_alkalinity").toDouble();
     prod->wb_ph = query.value("wb_ph").toDouble();
+    prod->tw_name = query.value("tw_name").toString();
+    prod->tw_calcium = query.value("tw_calcium").toDouble();
+    prod->tw_sulfate = query.value("tw_sulfate").toDouble();
+    prod->tw_chloride = query.value("tw_chloride").toDouble();
+    prod->tw_sodium = query.value("tw_sodium").toDouble();
+    prod->tw_magnesium = query.value("tw_magnesium").toDouble();
+    prod->tw_total_alkalinity = query.value("tw_total_alkalinity").toDouble();
+    prod->tw_ph = query.value("tw_ph").toDouble();
     prod->wa_acid_name = query.value("wa_acid_name").toInt();
     prod->wa_acid_perc = query.value("wa_acid_perc").toDouble();
     prod->wa_base_name = query.value("wa_base_name").toInt();
@@ -615,6 +600,7 @@
         "eq_kettle_height=:eq_kettle_height, eq_mash_volume=:eq_mash_volume, eq_mash_max=:eq_mash_max, "
 	"eq_chiller_type=:eq_chiller_type, eq_chiller_to79=:eq_chiller_to79, eq_chiller_volume=:eq_chiller_volume, "
 	"eq_chiller_lpm=:eq_chiller_lpm, eq_chiller_loss=:eq_chiller_loss, "
+	"eq_HLT_volume=:eq_HLT_volume, eq_HLT_deadspace=:eq_HLT_deadspace, "
 	"brew_date_start=:brew_date_start, brew_mash_ph=:brew_mash_ph, brew_mash_sg=:brew_mash_sg, "
 	"brew_mash_efficiency=:brew_mash_efficiency, brew_sparge_temperature=:brew_sparge_temperature, "
 	"brew_sparge_volume=:brew_sparge_volume, brew_sparge_est=:brew_sparge_est, brew_sparge_ph=:brew_sparge_ph, "
@@ -665,6 +651,8 @@
         "wg_total_alkalinity=:wg_total_alkalinity, wg_ph=:wg_ph, "
 	"wb_calcium=:wb_calcium, wb_sulfate=:wb_sulfate, wb_chloride=:wb_chloride, wb_sodium=:wb_sodium, "
 	"wb_magnesium=:wb_magnesium, wb_total_alkalinity=:wb_total_alkalinity, wb_ph=:wb_ph, "
+	"tw_name=:tw_name, tw_calcium=:tw_calcium, tw_sulfate=:tw_sulfate, tw_chloride=:tw_chloride, "
+	"tw_sodium=:tw_sodium, tw_magnesium=:tw_magnesium, tw_total_alkalinity=:tw_total_alkalinity, tw_ph=:tw_ph, "
 	"wa_acid_name=:wa_acid_name, wa_acid_perc=:wa_acid_perc, wa_base_name=:wa_base_name, "
 	"starter_enable=:starter_enable, starter_type=:starter_type, starter_sg=:starter_sg, "
 	"starter_viability=:starter_viability, yeast_prod_date=:yeast_prod_date, yeast_pitchrate=:yeast_pitchrate, "
@@ -718,6 +706,8 @@
     query.bindValue(":eq_chiller_volume", round(prod->eq_chiller_volume * 100) / 100);
     query.bindValue(":eq_chiller_lpm", round(prod->eq_chiller_lpm * 100) / 100);
     query.bindValue(":eq_chiller_loss", round(prod->eq_chiller_loss * 100) / 100);
+    query.bindValue(":eq_HLT_volume", round(prod->eq_HLT_volume * 10) / 10);
+    query.bindValue(":eq_HLT_deadspace", round(prod->eq_HLT_deadspace * 10) / 10);
     query.bindValue(":brew_date_start", prod->brew_date_start);
     query.bindValue(":brew_mash_ph", round(prod->brew_mash_ph * 100) / 100);
     query.bindValue(":brew_mash_sg", round(prod->brew_mash_sg * 1000) / 1000);
@@ -870,6 +860,14 @@
     query.bindValue(":wb_magnesium", round(prod->wb_magnesium * 100000) / 100000);
     query.bindValue(":wb_total_alkalinity", round(prod->wb_total_alkalinity * 100000) / 100000);
     query.bindValue(":wb_ph", round(prod->wb_ph * 100) / 100);
+    query.bindValue(":tw_name", prod->tw_name);
+    query.bindValue(":tw_calcium", round(prod->tw_calcium * 100000) / 100000);
+    query.bindValue(":tw_sulfate", round(prod->tw_sulfate * 100000) / 100000);
+    query.bindValue(":tw_chloride", round(prod->tw_chloride * 100000) / 100000);
+    query.bindValue(":tw_sodium", round(prod->tw_sodium * 100000) / 100000);
+    query.bindValue(":tw_magnesium", round(prod->tw_magnesium * 100000) / 100000);
+    query.bindValue(":tw_total_alkalinity", round(prod->tw_total_alkalinity * 100000) / 100000);
+    query.bindValue(":tw_ph", round(prod->tw_ph * 100) / 100);
     query.bindValue(":wa_acid_name", prod->wa_acid_name);
     query.bindValue(":wa_acid_perc", round(prod->wa_acid_perc * 10) / 10);
     query.bindValue(":wa_base_name", prod->wa_base_name);

mercurial