summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--p2pvr/Jamfile.jam27
-rw-r--r--p2pvr/lib/Jamfile.jam1
-rw-r--r--p2pvr/lib/resources.h9
-rw-r--r--p2pvr/lib/schedules.cpp24
-rw-r--r--p2pvr/lib/sql/GetScheduleConditates.sql20
5 files changed, 59 insertions, 22 deletions
diff --git a/p2pvr/Jamfile.jam b/p2pvr/Jamfile.jam
index b1190f6..a09e449 100644
--- a/p2pvr/Jamfile.jam
+++ b/p2pvr/Jamfile.jam
@@ -27,3 +27,30 @@ build-project carddaemon ;
install debuginstall : lib carddaemon daemon ice : <location>./testing ;
package.install install : : : carddaemon daemon ;
+import type ;
+import generators ;
+import feature ;
+import "class" : new ;
+type.register SQL : sql ;
+class sql-generator : generator
+{
+ import "class" : new ;
+ rule __init__ ( * : * )
+ {
+ generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
+ }
+ rule run ( project name ? : property-set : sources * )
+ {
+ return [ generator.run $(project) $(name) : $(property-set) : $(sources) ] ;
+ }
+ rule generated-targets ( sources + : property-set : project name ? )
+ {
+ return [ generator.generated-targets $(sources) : $(property-set) : $(project) $(name) ] ;
+ }
+}
+generators.register [ new sql-generator sql.sql2o : SQL : OBJ ] ;
+actions sql.sql2o
+{
+ ld -r -b binary -o $(1) $(2)
+}
+IMPORT $(__name__) : sql.sql2o : : sql.sql2o ;
diff --git a/p2pvr/lib/Jamfile.jam b/p2pvr/lib/Jamfile.jam
index 2947d05..d4ccbfd 100644
--- a/p2pvr/lib/Jamfile.jam
+++ b/p2pvr/lib/Jamfile.jam
@@ -3,6 +3,7 @@ lib boost_filesystem ;
lib p2pvrlib :
[ glob-tree *.cpp ]
+ [ glob-tree *.sql ]
../../libmisc/misc.cpp
:
<library>boost_system
diff --git a/p2pvr/lib/resources.h b/p2pvr/lib/resources.h
new file mode 100644
index 0000000..301ad4b
--- /dev/null
+++ b/p2pvr/lib/resources.h
@@ -0,0 +1,9 @@
+#ifndef RESOURCES_H
+#define RESOURCES_H
+
+#define ResourceString(name, resource) \
+extern "C" { extern char _binary_##resource##_start, _binary_##resource##_end; } \
+static const std::string name(&_binary_##resource##_start, &_binary_##resource##_end);
+
+#endif
+
diff --git a/p2pvr/lib/schedules.cpp b/p2pvr/lib/schedules.cpp
index 387dba8..167c61f 100644
--- a/p2pvr/lib/schedules.cpp
+++ b/p2pvr/lib/schedules.cpp
@@ -5,30 +5,10 @@
#include <Ice/Ice.h>
#include <sqlVariableBinder.h>
#include "p2Helpers.h"
+#include "resources.h"
#include <boost/date_time/posix_time/posix_time.hpp>
-// This gets the list of things we want to record (all showings)
-static const std::string GetScheduleConditates = "\
-select (e.title, e.subtitle, e.description)::text what, e.serviceid, e.eventid, sv.transportstreamid, \
- e.starttime - max(s.early), e.stoptime - interval '1 second' + max(s.late), \
- max(s.priority) \
-from services sv, events e, schedules s \
-where (s.serviceid is null or s.serviceid = e.serviceid) \
-and (s.title is null or lower(s.title) = lower(e.title)) \
-and (s.eventid is null or s.eventid = e.eventid) \
-and (s.search is null or event_tsvector(e) @@ plainto_tsquery(s.search)) \
-and sv.serviceid = e.serviceid \
-and e.starttime > now() \
-and not exists ( \
- select 1 \
- from seen \
- where lower(e.title) = lower(seen.title) \
- and coalesce(lower(e.subtitle), '') = coalesce(lower(seen.subtitle), '') \
- and ts_rank(to_tsvector(e.description), plainto_tsquery(seen.description)) + \
- ts_rank(to_tsvector(seen.description), plainto_tsquery(e.description)) > 1) \
-group by e.serviceid, e.eventid, sv.serviceid \
-order by max(s.priority) desc, e.title, e.subtitle, e.description, sv.transportstreamid, e.starttime \
-";
+ResourceString(GetScheduleConditates, lib_sql_GetScheduleConditates_sql);
std::string Schedules::SchedulerAlgorithm;
diff --git a/p2pvr/lib/sql/GetScheduleConditates.sql b/p2pvr/lib/sql/GetScheduleConditates.sql
new file mode 100644
index 0000000..1b9441b
--- /dev/null
+++ b/p2pvr/lib/sql/GetScheduleConditates.sql
@@ -0,0 +1,20 @@
+select (e.title, e.subtitle, e.description)::text what, e.serviceid, e.eventid, sv.transportstreamid,
+ e.starttime - max(s.early), e.stoptime - interval '1 second' + max(s.late),
+ max(s.priority)
+from services sv, events e, schedules s
+where (s.serviceid is null or s.serviceid = e.serviceid)
+and (s.title is null or lower(s.title) = lower(e.title))
+and (s.eventid is null or s.eventid = e.eventid)
+and (s.search is null or event_tsvector(e) @@ plainto_tsquery(s.search))
+and sv.serviceid = e.serviceid
+and e.starttime > now()
+and not exists (
+ select 1
+ from seen
+ where lower(e.title) = lower(seen.title)
+ and coalesce(lower(e.subtitle), '') = coalesce(lower(seen.subtitle), '')
+ and ts_rank(to_tsvector(e.description), plainto_tsquery(seen.description)) +
+ ts_rank(to_tsvector(seen.description), plainto_tsquery(e.description)) > 1)
+group by e.serviceid, e.eventid, sv.serviceid
+order by max(s.priority) desc, e.title, e.subtitle, e.description, sv.transportstreamid, e.starttime
+