NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 31 32 33 34 35 … 93 Next »
SQL help needed

 
  • 0 Vote(s) - 0 Average
SQL help needed
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,589
Threads: 385
Joined: Dec 2004
#1
2008-05-24, 10:14 PM
I'm currently developing the dvbt radio plugin to maintain a 7 day radio EPG in a SQLite DB (that's the easy bit).

The problem I've got is I want to extract the Now/Next info from the DB, i.e., assuming I've got a full 7 days of EPG, as soon as I start the plugin, I can identify the Now/Next playing radio shows without having to scavenge the dvbt stream.

I can get the 'Now' info with the following (example) SQL statement
Code:
SELECT PROGRAMMES.service_id, PROGRAMMES.title, PROGRAMMES.description, PROGRAMMES.start_time, PROGRAMMES.end_time FROM PROGRAMMES WHERE (start_time <= '2008-05-24 22:50:40Z') AND (end_time > '2008-05-24 22:50:40Z')

The start and end times are created using
Code:
DateTime.Now.ToString("u")
This works fine and I can pull all of the Now playing shows into a DataSet.

The problem is getting the Next shows. I get the DataSet to create a DataTableReader and step through the rows. For each row, I then query the DB with the following example
Code:
SELECT PROGRAMMES.service_id, PROGRAMMES.title, PROGRAMMES.description, PROGRAMMES.start_time, PROGRAMMES.end_time FROM PROGRAMMES WHERE (service_id = '18496') AND (start_time = '2008-05-24 23:00:00Z')
In this case, the service_id matches that of the row returned by the DataSet's DataTableReader and the start_time is the end_time of that show. In other words, the Next show is the one that starts at the end_time of a Now playing show (obviously).

The problem is, I don't get any results returned despite the fact that there are shows in the DB which match the service_id and start_time that I'm passing in the SQL statement.

Any ideas?

Cheers,
Brian
Graham
Offline

Posting Freak

UK
Posts: 4,058
Threads: 102
Joined: Dec 2005
#2
2008-05-25, 12:40 AM
Health Warning: My SQL experience is limited and rusty and probably best ignored.

I quite like the idea of views and/or sub queries.

Create view Now as select blah from blah where start_time is less than or equal to "now" and end_time is greater than "now"

Select blah from blah where channel = blah and start_time equals (select end_time from Now where channel = blah)

A view or a sub-query or both might help split one big complicated query into smaller simpler queries.

Apologies if I have missed the point.

Good luck

Graham
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,589
Threads: 385
Joined: Dec 2004
#3
2008-05-25, 01:28 AM
Graham Wrote:Health Warning: My SQL experience is limited and rusty and probably best ignored.
Smile

I'm by no means an expert in SQL and find it constanly frustrating - sometimes I can run off a pretty complex SQL query and it works first time. Then the simplest things just refuse to work.

It appears the query for the 'Next' service_id/start_time doesn't like the datetime format despite it being exactly the same as the one used when I get the 'Now' programmes. I experimented with simply querying for anything with a known start_time and it still returned no results.

I've put in a workaround. I pull all programmes with the same service_id then I just step through comparing the end of the Now programme with the start of each Next programme, converting the DATETIME values to strings. Annoying - it works once I've got the data but not in the query.

I wish I could work out how to setup stored procedures in SQLite - it'd make things easier.

Cheers,
Brian
Ommina
Offline

Senior Member

Posts: 330
Threads: 39
Joined: Feb 2006
#4
2008-05-25, 05:36 AM
No stored procedures in SQLite -- so you're off the hook for figuring out how to make them. Smile

How are start_time and end_time stored in the database? Depending on what format they are in, you maybe be able to get away with something like:

Code:
SELECT PROGRAMMES.service_id, PROGRAMMES.title, PROGRAMMES.description, PROGRAMMES.start_time, PROGRAMMES.end_time FROM PROGRAMMES WHERE datetime('now') Between start_time and end_time;

SQLite will change datetime('now') to, well, the date and time as of, er, now, so you don't have to build any SQL statements on-the-fly. (This is also very effective for querying sub's Recording_Schedule table to see if something is recording.)

As for the next show. Hm. How about:

Code:
Select {Stuff} From Programmes Where start_time > datetime('now') Order By start_time Limit 1

That should give you one record, with the details of the next programme, and no stepping through rows required.

caveat: it will still depend on what format the start and end times are in the database. "Additional futzing may be required."
bgowland
Offline

Posting Freak

West Yorkshire, UK
Posts: 4,589
Threads: 385
Joined: Dec 2004
#5
2008-05-25, 07:08 AM
Ommina Wrote:No stored procedures in SQLite -- so you're off the hook for figuring out how to make them. Smile
I thought I'd read somewhere that SQLite doesn't support stored procedures - thanks for confirming.

Quote:How are start_time and end_time stored in the database? Depending on what format they are in, you maybe be able to get away with something like:

Now we're talking!!!!

Yep, the start_time and end_time fields are DATETIME data types so your datetime('now') example works like a charm. Also for the 'Next' stuff, I still need to check the start time coincides with the end time of the Now programme but you're right - I don't need to cycle through loads of results when using 'Order By start_time Limit 1'. Thanks.


Cheers,
Brian
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  New web service clarification needed bgowland 6 3,341 2013-10-19, 02:36 AM
Last Post: bgowland
  Skin help needed for EventDetails.xml bgowland 7 3,435 2011-06-26, 11:55 PM
Last Post: Jaggy
  MVP/NMT testers needed for Weather2 scb147 46 12,315 2010-03-03, 08:12 PM
Last Post: scb147
  Csharp Event help needed.. psycik 4 2,152 2008-05-25, 06:19 AM
Last Post: psycik
  Whats needed for recording -Oz- 24 7,664 2008-01-24, 03:59 AM
Last Post: zehd
  TV guide data needed reboot 35 10,582 2007-08-06, 11:04 PM
Last Post: mvallevand
  Help needed with error in config.exe.log idkpmiller 3 1,871 2007-01-24, 06:08 AM
Last Post: sub
  VB compile needed pBS 22 5,860 2006-11-28, 09:39 PM
Last Post: Chris Reynolds
  Image Location in FireFox Help Needed UncleJohnsBand 13 4,185 2006-11-22, 11:40 PM
Last Post: UncleJohnsBand
  UML & Design Patterns - advice needed ubu 3 2,099 2006-07-10, 07:04 AM
Last Post: stryder

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode