MCPcopy Create free account
hub / github.com/QuiteRSS/quiterss / prepareDatabase

Method prepareDatabase

src/database/database.cpp:261–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259}
260
261void Database::prepareDatabase()
262{
263 {
264 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "initialization");
265 db.setDatabaseName(mainApp->dbFileName());
266 if (!db.open()) {
267 QString message = QString("Cannot open SQLite database! \n"
268 "Error: %1").arg(db.lastError().text());
269 qCritical() << message;
270 QMessageBox::critical(mainApp->mainWindow(), QObject::tr("Error"), message);
271 } else {
272 setPragma(db);
273 QSqlQuery q(db);
274 q.setForwardOnly(true);
275
276 if (!mainApp->dbFileExists()) {
277 qWarning() << "Creating database";
278
279 createTables(db);
280 createLabels(db);
281 q.prepare("INSERT INTO info(name, value) VALUES ('version', :version)");
282 q.bindValue(":version", version());
283 q.exec();
284 q.prepare("INSERT INTO info(name, value) VALUES('appVersion', :appVersion)");
285 q.bindValue(":appVersion", STRPRODUCTVER);
286 q.exec();
287 } else {
288 qWarning() << "Preparation database";
289
290 addColumnsToFeedsTables(db);
291
292 // Version DB > 0.12.1
293 Settings settings;
294
295 int dbVersion = -1;
296 q.exec("SELECT value FROM info WHERE name='version'");
297 if (q.first()) {
298 dbVersion = q.value(0).toInt();
299 }
300
301 QString appVersion = QString();
302 q.exec("SELECT value FROM info WHERE name='appVersion'");
303 if (q.first()) {
304 appVersion = q.value(0).toString();
305 }
306
307 // Create backups for DB and Settings
308 if (appVersion != STRPRODUCTVER) {
309 Common::createFileBackup(mainApp->dbFileName(), appVersion);
310 Common::createFileBackup(settings.fileName(), appVersion);
311 }
312
313 if (dbVersion < 14) {
314 q.exec("ALTER TABLE feeds ADD COLUMN showNotification integer default 0");
315 q.exec("ALTER TABLE feeds ADD COLUMN disableUpdate integer default 0");
316 q.exec("ALTER TABLE feeds ADD COLUMN javaScriptEnable integer default 1");
317 }
318 if (dbVersion < 16) {

Callers

nothing calls this directly

Calls 11

dbFileNameMethod · 0.80
mainWindowMethod · 0.80
dbFileExistsMethod · 0.80
prepareMethod · 0.80
execMethod · 0.80
valueMethod · 0.80
fileNameMethod · 0.80
setValueMethod · 0.80
finishMethod · 0.80
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected