156 qInfo() << "loadSetup" << my_brewery_name; |
157 qInfo() << "loadSetup" << my_brewery_name; |
157 } |
158 } |
158 |
159 |
159 |
160 |
160 /* |
161 /* |
|
162 * Upgrade database. Check and do upgrades. |
|
163 */ |
|
164 void MainWindow::updateDataBase() |
|
165 { |
|
166 QSqlQuery query1, query2, query3, query4; |
|
167 int count = 0; |
|
168 |
|
169 qDebug() << "updateDatabase() start"; |
|
170 |
|
171 /* |
|
172 * Make sure we have the inventory_yeastpack with initial records. |
|
173 */ |
|
174 query1.exec("CREATE TABLE IF NOT EXISTS `inventory_yeastpack` (" |
|
175 "`record` int(11) NOT NULL AUTO_INCREMENT," |
|
176 "`uuid` varchar(36) NOT NULL," |
|
177 "`laboratory` varchar(128) NOT NULL," |
|
178 "`form` tinyint(4) NOT NULL DEFAULT 0," |
|
179 "`package` varchar(128) NOT NULL," |
|
180 "`notes` text DEFAULT NULL," |
|
181 "`cells` double NOT NULL DEFAULT 0," |
|
182 "`viability` double NOT NULL DEFAULT 0.99," |
|
183 "`max` tinyint(4) NOT NULL DEFAULT 100," |
|
184 "`size` float NOT NULL DEFAULT 0," |
|
185 "PRIMARY KEY (`record`)," |
|
186 "UNIQUE KEY `uuid` (`uuid`)," |
|
187 "KEY `lab_form` (`laboratory`,`form`) USING BTREE" |
|
188 ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Yeast packages data'"); |
|
189 if (query1.lastError().isValid()) { |
|
190 qWarning() << " create inventory_yeastpack" << query1.lastError(); |
|
191 } else { |
|
192 query1.exec("SELECT DISTINCT laboratory,form FROM inventory_yeasts"); |
|
193 while (query1.next()) { |
|
194 query2.prepare("SELECT record FROM inventory_yeastpack WHERE laboratory=:laboratory AND form=:form"); |
|
195 query2.bindValue(":laboratory", query1.value("laboratory").toString()); |
|
196 query2.bindValue(":form", query1.value("form").toInt()); |
|
197 query2.exec(); |
|
198 if (! query2.first()) { |
|
199 qDebug() << " add yeastpack" << query1.value("laboratory").toString() << query1.value("form").toInt(); |
|
200 |
|
201 query3.prepare("SELECT record,cells FROM inventory_yeasts WHERE laboratory=:laboratory AND form=:form"); |
|
202 query3.bindValue(":laboratory", query1.value("laboratory").toString()); |
|
203 query3.bindValue(":form", query1.value("form").toInt()); |
|
204 query3.exec(); |
|
205 query3.first(); |
|
206 /* Should succeed */ |
|
207 |
|
208 query4.prepare("INSERT INTO inventory_yeastpack SET uuid=:uuid, laboratory=:laboratory, " |
|
209 "form=:form, package=:package, cells=:cells"); |
|
210 query4.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
|
211 query4.bindValue(":laboratory", query1.value("laboratory").toString()); |
|
212 query4.bindValue(":form", query1.value("form").toInt()); |
|
213 query4.bindValue(":package", g_yeast_forms[query1.value("form").toInt()]); |
|
214 query4.bindValue(":cells", query3.value("cells").toDouble()); |
|
215 query4.exec(); |
|
216 if (query4.lastError().isValid()) { |
|
217 qWarning() << " add yeastpack" << query4.lastError(); |
|
218 } else { |
|
219 count++; |
|
220 } |
|
221 } |
|
222 } |
|
223 } |
|
224 |
|
225 qDebug() << "updateDatabase()" << count << "updates"; |
|
226 } |
|
227 |
|
228 |
|
229 /* |
161 * On the server where bmsd runs, there is a crontask.php that does these checks |
230 * On the server where bmsd runs, there is a crontask.php that does these checks |
162 * too. Here we do some of the same commands so that we have the results sooner. |
231 * too. Here we do some of the same commands so that we have the results sooner. |
163 * Currently this takes 6 to 9 mSecs. |
232 * Currently this takes 6 to 9 mSecs. |
164 */ |
233 */ |
165 void MainWindow::maintDataBase() |
234 void MainWindow::maintDataBase() |