commit a4f7d5bc887a79d067caa261b2d485e3c98b0acd
Author: Michael Haas <laga@mb841.(none)>
Date: Thu Sep 11 22:01:45 2008 +0200
Save XMLTV config path in database.
Add a configpath column to the videosource table
diff --git a/mythtv/libs/libmythtv/dbcheck.cpp b/mythtv/libs/libmythtv/dbcheck.cpp
index 6822100..e8bf724 100644
a
|
b
|
using namespace std; |
18 | 18 | #define MINIMUM_DBMS_VERSION 5,0,15 |
19 | 19 | |
20 | 20 | /// This is the DB schema version expected by the running MythTV instance. |
21 | | const QString currentDatabaseVersion = "1223"; |
| 21 | const QString currentDatabaseVersion = "1224"; |
22 | 22 | |
23 | 23 | static bool UpdateDBVersionNumber(const QString &newnumber); |
24 | 24 | static bool performActualUpdate( |
… |
… |
NULL |
4302 | 4302 | return false; |
4303 | 4303 | } |
4304 | 4304 | |
| 4305 | if (dbver == "1223") |
| 4306 | { |
| 4307 | |
| 4308 | const char *updates[] = { |
| 4309 | "ALTER TABLE videosource ADD COLUMN configpath VARCHAR(4096) DEFAULT NULL;", NULL |
| 4310 | }; |
| 4311 | |
| 4312 | if (!performActualUpdate(updates, "1224", dbver)) |
| 4313 | return false; |
| 4314 | |
| 4315 | |
| 4316 | |
| 4317 | bool ok = true; |
| 4318 | MSqlQuery query(MSqlQuery::InitCon()); |
| 4319 | query.prepare( |
| 4320 | "SELECT name, sourceid " |
| 4321 | "FROM videosource"); |
| 4322 | |
| 4323 | if (!query.exec()) |
| 4324 | { |
| 4325 | MythDB::DBError( |
| 4326 | "Could not perform select for update to '1224'", query); |
| 4327 | ok = false; |
| 4328 | } |
| 4329 | else |
| 4330 | { |
| 4331 | MSqlQuery query2(MSqlQuery::InitCon()); |
| 4332 | while (query.next()) |
| 4333 | { |
| 4334 | QString videosource = query.value(0).toString(); |
| 4335 | QString configpath = gContext->GetSetting(QString("XMLTVConfig.%1").arg(videosource)); |
| 4336 | |
| 4337 | if (configpath != QString("")) |
| 4338 | { |
| 4339 | query2.prepare( |
| 4340 | "UPDATE videosource " |
| 4341 | "SET configpath = :PATH " |
| 4342 | "WHERE sourceid = :SOURCEID "); |
| 4343 | query2.bindValue(":PATH", configpath); |
| 4344 | query2.bindValue(":SOURCEID", query.value(1).toString()); |
| 4345 | if (!query2.exec()) |
| 4346 | { |
| 4347 | MythDB::DBError( |
| 4348 | "Could not perform update for '1224'", query2); |
| 4349 | ok = false; |
| 4350 | } |
| 4351 | } |
| 4352 | } |
| 4353 | } |
| 4354 | if (!ok) |
| 4355 | return false; |
| 4356 | |
| 4357 | MSqlQuery query3(MSqlQuery::InitCon()); |
| 4358 | query3.prepare( |
| 4359 | "DELETE FROM settings " |
| 4360 | "WHERE value LIKE 'XMLTVConfig.%'"); |
| 4361 | if (!query3.exec()) |
| 4362 | { |
| 4363 | MythDB::DBError( |
| 4364 | "Could not perform update for '1224'", query3); |
| 4365 | ok = false; |
| 4366 | } |
| 4367 | |
| 4368 | if (!ok) |
| 4369 | return false; |
| 4370 | } |
| 4371 | |
| 4372 | |
4305 | 4373 | return true; |
4306 | 4374 | } |
4307 | 4375 | |
diff --git a/mythtv/libs/libmythtv/videosource.cpp b/mythtv/libs/libmythtv/videosource.cpp
index 2b6cff1..dc09e96 100644
a
|
b
|
XMLTV_generic_config::XMLTV_generic_config(const VideoSource& _parent, |
424 | 424 | QString filename = QString("%1/%2.xmltv") |
425 | 425 | .arg(GetConfDir()).arg(parent.getSourceName()); |
426 | 426 | |
| 427 | MSqlQuery query(MSqlQuery::InitCon()); |
| 428 | query.prepare( |
| 429 | "UPDATE videosource " |
| 430 | "SET configpath = :PATH " |
| 431 | "WHERE sourceid = :SOURCEID"); |
| 432 | |
| 433 | query.bindValue(":PATH", filename); |
| 434 | query.bindValue(":SOURCEID", parent.getSourceID()); |
| 435 | |
| 436 | if (!query.exec() || !query.isActive()) |
| 437 | { |
| 438 | MythContext::DBError(" XMLTV_generic_config::save", query); |
| 439 | return; |
| 440 | } |
| 441 | |
| 442 | |
427 | 443 | grabberArgs.push_back("--config-file"); |
428 | 444 | grabberArgs.push_back(filename); |
429 | 445 | grabberArgs.push_back("--configure"); |
diff --git a/mythtv/programs/mythfilldatabase/filldata.cpp b/mythtv/programs/mythfilldatabase/filldata.cpp
index 638a2b7..265c1f4 100644
a
|
b
|
bool FillData::GrabData(Source source, int offset, QDate *qCurrentDate) |
343 | 343 | QString filename = QString(tempfilename); |
344 | 344 | |
345 | 345 | QString home = QDir::homeDirPath(); |
346 | | QString configfile = QString("%1/%2.xmltv").arg(GetConfDir()) |
347 | | .arg(source.name); |
| 346 | QString configfile; |
| 347 | |
| 348 | MSqlQuery query(MSqlQuery::InitCon()); |
| 349 | QString querystr = "SELECT configpath from videosource"; |
| 350 | querystr += " WHERE sourceid = :ID"; |
| 351 | query.prepare(querystr); |
| 352 | query.bindValue(":ID",source.id); |
| 353 | if (!query.exec() || !query.isActive()) { |
| 354 | MythContext::DBError("FillData::grabData", query); |
| 355 | //return; |
| 356 | } |
| 357 | |
| 358 | |
| 359 | if (query.size() == 0) { |
| 360 | VERBOSE(VB_GENERAL, "configpath in videosource table is empty, falling back to old behavior"); |
| 361 | QString home = QDir::homeDirPath(); |
| 362 | configfile = QString("%1/%2.xmltv").arg(GetConfDir()) |
| 363 | .arg(source.name); |
| 364 | } |
| 365 | else { |
| 366 | query.next(); |
| 367 | configfile = query.value(0).toString(); |
| 368 | } |
| 369 | |
| 370 | VERBOSE(VB_GENERAL, QString("XMLTV config file is: %1").arg(configfile)); |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
348 | 375 | |
349 | 376 | QString command = QString("nice %1 --config-file '%2' --output %3") |
350 | 377 | .arg(xmltv_grabber).arg(configfile).arg(filename); |
… |
… |
bool FillData::GrabData(Source source, int offset, QDate *qCurrentDate) |
377 | 404 | } |
378 | 405 | |
379 | 406 | QDateTime qdtNow = QDateTime::currentDateTime(); |
380 | | MSqlQuery query(MSqlQuery::InitCon()); |
| 407 | //MSqlQuery query(MSqlQuery::InitCon()); |
381 | 408 | QString status = QObject::tr("currently running."); |
382 | 409 | |
383 | 410 | query.exec(QString("UPDATE settings SET data ='%1' " |