361 | | QString tables[] = { |
362 | | "recordedprogram", |
363 | | "recordedrating", |
364 | | "recordedcredits", |
365 | | "" }; // This blank entry must exist, do not remove. |
366 | | QString table = tables[tableIndex]; |
367 | | |
| 361 | // tables[tableIndex][0] is the table name |
| 362 | // tables[tableIndex][1] is the name of the column on which the join is |
| 363 | // performed |
| 364 | QString tables[][2] = { |
| 365 | { "recordedprogram", "progstart" }, |
| 366 | { "recordedrating", "progstart" }, |
| 367 | { "recordedcredits", "progstart" }, |
| 368 | { "recordedmarkup", "starttime" }, |
| 369 | { "recordedseek", "starttime" }, |
| 370 | { "", "" } }; // This blank entry must exist, do not remove. |
| 371 | QString table = tables[tableIndex][0]; |
| 372 | QString column = tables[tableIndex][1]; |
| 373 | |
| 374 | // Because recordedseek can have millions of rows, we don't want to JOIN it |
| 375 | // with recorded. Instead, pull out DISTINCT chanid and starttime into a |
| 376 | // temporary table (resulting in tens, hundreds, or--at most--a few |
| 377 | // thousand rows) for the JOIN |
| 378 | QString querystr; |
| 379 | querystr = "CREATE TEMPORARY TABLE IF NOT EXISTS temprecordedcleanup ( " |
| 380 | "chanid int(10) unsigned NOT NULL default '0', " |
| 381 | "starttime datetime NOT NULL default '0000-00-00 00:00:00' );"; |
| 382 | |
| 383 | if (!query.exec(querystr)) |
| 384 | { |
| 385 | MythContext::DBError("Housekeeper Creating Temporary Table", query); |
| 386 | return; |
| 387 | } |
| 388 | |
| 391 | query.prepare(QString("TRUNCATE TABLE temprecordedcleanup;")); |
| 392 | if (!query.exec() || !query.isActive()) |
| 393 | { |
| 394 | MythContext::DBError("Housekeeper Truncating Temporary Table", |
| 395 | query); |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | query.prepare(QString("INSERT INTO temprecordedcleanup " |
| 400 | "( chanid, starttime ) " |
| 401 | "SELECT DISTINCT chanid, starttime " |
| 402 | "FROM %1;") |
| 403 | .arg(table)); |
| 404 | |
| 405 | if (!query.exec() || !query.isActive()) |
| 406 | { |
| 407 | MythContext::DBError("HouseKeeper Cleaning Recorded Tables", query); |
| 408 | return; |
| 409 | } |
| 410 | |