162 /* |
162 /* |
163 * Upgrade database. Check and do upgrades. |
163 * Upgrade database. Check and do upgrades. |
164 */ |
164 */ |
165 void MainWindow::updateDataBase() |
165 void MainWindow::updateDataBase() |
166 { |
166 { |
167 QSqlQuery query1, query2, query3, query4; |
167 QSqlQuery query1, query2, query4; |
168 int count = 0; |
168 int count = 0; |
169 bool added_packs = false; |
169 bool added_packs = false; |
170 |
170 |
171 qDebug() << "updateDatabase() start"; |
171 qDebug() << "updateDatabase() start"; |
172 |
172 |
202 query2.bindValue(":form", query1.value("form").toInt()); |
202 query2.bindValue(":form", query1.value("form").toInt()); |
203 query2.exec(); |
203 query2.exec(); |
204 if (! query2.first()) { |
204 if (! query2.first()) { |
205 qDebug() << " add yeastpack" << query1.value("laboratory").toString() << query1.value("form").toInt(); |
205 qDebug() << " add yeastpack" << query1.value("laboratory").toString() << query1.value("form").toInt(); |
206 |
206 |
207 query3.prepare("SELECT record,cells FROM inventory_yeasts WHERE laboratory=:laboratory AND form=:form"); |
|
208 query3.bindValue(":laboratory", query1.value("laboratory").toString()); |
|
209 query3.bindValue(":form", query1.value("form").toInt()); |
|
210 query3.exec(); |
|
211 query3.first(); |
|
212 /* Should succeed */ |
|
213 |
|
214 query4.prepare("INSERT INTO inventory_yeastpack SET uuid=:uuid, laboratory=:laboratory, " |
207 query4.prepare("INSERT INTO inventory_yeastpack SET uuid=:uuid, laboratory=:laboratory, " |
215 "form=:form, package=:package, cells=:cells, viability=:viability, max=:max"); |
208 "form=:form, package=:package, viability=:viability, max=:max"); |
216 query4.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
209 query4.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
217 query4.bindValue(":laboratory", query1.value("laboratory").toString()); |
210 query4.bindValue(":laboratory", query1.value("laboratory").toString()); |
218 query4.bindValue(":form", query1.value("form").toInt()); |
211 query4.bindValue(":form", query1.value("form").toInt()); |
219 query4.bindValue(":package", g_yeast_forms[query1.value("form").toInt()]); |
212 query4.bindValue(":package", g_yeast_forms[query1.value("form").toInt()]); |
220 query4.bindValue(":cells", query3.value("cells").toDouble()); |
|
221 switch (query1.value("form").toInt()) { |
213 switch (query1.value("form").toInt()) { |
222 case YEAST_FORMS_LIQUID: query4.bindValue(":viability", 0.80); |
214 case YEAST_FORMS_LIQUID: query4.bindValue(":viability", 0.80); |
223 query4.bindValue(":max", 97); |
215 query4.bindValue(":max", 97); |
224 break; |
216 break; |
225 case YEAST_FORMS_DRY: query4.bindValue(":viability", 0.998); |
217 case YEAST_FORMS_DRY: query4.bindValue(":viability", 0.998); |