[mythtv] conflict resolution

Chris Pinkham cpinkham at bc2va.org
Mon Nov 3 13:49:53 EST 2003


> SQL is not great at ordered operations, it's a set based language, and trying
> to order by closest match is going to be slow and difficult I think.
> I need to have a think about how to make the SQL re-usable so we get the
> same query everywhere in the code otherwise it's going to get a little
> hairy working out what is actually going to be recorded...

To do the fuzzy match, couldn't you first compare something like this:

	((record.starttime > program.starttime - INTERVAL $fuzzy_minutes minutes) and
	 (record.starttime < program.starttime + INTERVAL $fuzzy_minutes minutes) and
	 (record.endtime > program.endtime - INTERVAL $fuzzy_minutes minutes) and
	 (record.endtime < program.endtime + INTERVAL $fuzzy_minutes minutes))

instead of the current

	((TO_DAYS(record.startdate) = TO_DAYS(program.starttime)) and
	 (TIME_TO_SEC(record.endtime) = TIME_TO_SEC(program.endtime)) and
	 (TO_DAYS(record.enddate) = TO_DAYS(program.endtime)))

Then to order the closest match use the absolute difference in the unixtimes
of record.starttime and program.starttime.

select blah, blah,
	abs(unix_timestamp(record.starttime) - unix_timestamp(program.starttime))
		as secs_diff
	from blah
	where blah
	order by secs_diff;

Hopefully I did that right.  Too many interruptions during my "lunch" "hour"
(both in quotes because both have fuzzy definitions). :)
-- 

Chris



More information about the mythtv-dev mailing list