Logo
It is currently September 6th, 2010, 10:32 am

All times are UTC - 6 hours [ DST ]


Forum rules


In order to provide you with the best support possible please read the following topics before posting:
Forum Rules can be found here. Ignorance is not bliss.



Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 9:37 am 
Offline
Senior User
Senior User
User avatar

Joined: January 31st, 2004, 10:28 pm
Posts: 192
Location: Carrboro, North Carolina
What's the best way to discover the TDataSet for the last item in queue. EG: I want to add a promo to the QueueBottom iff the last item in queue is of songtype = "S" so as not to play a promo after songs only, not after other Ps or Is or Js, etc...

Song := Queue.NextInQueue; works well to discover the first item in queue... but how to discover the last item?

Thanks,
K

_________________
-Keith (Lumper5)
Visit http://www.deeperintomusic.net
Facebook: Become a "fan"
Twitter: Follow the leader


Top
 Profile  
 
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 9:52 am 
Offline
SVS Member
SVS Member
User avatar

Joined: October 14th, 2006, 9:38 am
Posts: 4447
Location: Deep in the heart of the PRNJ
Query the queuelist, examine the last item in the data set.

q.v. TDataSet in the Help files.

_________________
- Stan Olochwoszcz
- SVS (Spacial Volunteer Support)
A proud licensed SAM user since 2003

Raritan Bay Radio
Follow us on Twitter


Top
 Profile E-mail  
 
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 11:50 am 
Offline
Senior User
Senior User
User avatar

Joined: January 31st, 2004, 10:28 pm
Posts: 192
Location: Carrboro, North Carolina
Problem is that queuelist doesn't store songtype.

_________________
-Keith (Lumper5)
Visit http://www.deeperintomusic.net
Facebook: Become a "fan"
Twitter: Follow the leader


Top
 Profile  
 
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 12:08 pm 
Offline
Junior User
Junior User
User avatar

Joined: October 4th, 2008, 12:35 pm
Posts: 39
Location: Kaufbeuren, Germany
You might want to use something like the code snippet below. Just bear in mind that the function »SongList« only returns the fields ID, songID, sortID, requestID, artist, title, and duration in the TDataSet returned.

Code:
PAL.LockExecution;
var Q, QInfo: TDataSet;

if (not Queue.IsEmpty) then
begin
  // Queue not empty, get last song in Queue
  Q := Queue.SongList;
  Q.Last;

  if (not Q.EOF) then
  begin
    // need to get extra info that is not in »queuelist« table, so read »songlist« table
    QInfo := Query('SELECT * FROM songlist WHERE songID = :id',[Q['songID']], True); // r/o query
    QInfo.First;
    // you should now have all songlist info in »QInfo['…']«
    if (QInfo['songtype'] = 'S') then
    begin
      // add promo to Queue Bottom
    end;
  end;

  Q.Free;
  QInfo.Free;
end;

PAL.UnlockExecution;

Untested, but I guess it should work.

_________________
Moonbase: The Problem Solver
I will not give any support for unlicensed or pirated software.


Top
 Profile E-mail  
 
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 12:24 pm 
Offline
Senior User
Senior User
User avatar

Joined: January 31st, 2004, 10:28 pm
Posts: 192
Location: Carrboro, North Carolina
Thanks - that was the right idea. A small tweak and it worked great. Seems odd that queuelist wouldn't store a little more info like songtype, but so it goes. Thanks for the helps.

_________________
-Keith (Lumper5)
Visit http://www.deeperintomusic.net
Facebook: Become a "fan"
Twitter: Follow the leader


Top
 Profile  
 
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 1:13 pm 
Offline
Cygnus X-1
Cygnus X-1
User avatar

Joined: March 11th, 2003, 1:34 pm
Posts: 9656
Location: Maui, HI
This could also be done without the outer check:
Code:
PAL.LockExecution;

var QInfo : TDataSet = Query( 'select sl.songinfo from songlist sl, queuelist ql where sl.id = ql.songid order by ql.id desc limit 1', [], True);
if ( QInfo[ 'songtype' ] = 'S' ) then
begin
  // add promo to Queue Bottom
end;

QInfo.Free;
PAL.UnlockExecution;


SQL validated on MySQL; salt to taste for other dialects

_________________
- Steve Kunitzer
- SVS (Spacial Volunteer Support) / Forum Administrator

Image
Image


Top
 Profile  
 
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 1:18 pm 
Offline
SVS Member
SVS Member
User avatar

Joined: October 14th, 2006, 9:38 am
Posts: 4447
Location: Deep in the heart of the PRNJ
Thanks, Moonbase. Tweaked it a bit and this does work:
Code:
//PAL.LockExecution;
var Q, QInfo: TDataSet;
var SI : String;

if (not Queue.IsEmpty) then
  begin
     Q := Queue.SongList;
     Q.Last;
  end;
  WriteLn(Q['SongID']);
  WriteLn(Q['title']);
  SI := Q['songID'];
  WriteLn(SI);
  //Get additional info about song
    QInfo := Query('SELECT * FROM songlist WHERE ID = :ID',[Q['songID']], True);
    WriteLn(QInfo['ID']);
    WriteLn(QInfo['title']);
    WriteLn(QInfo['songtype']);
    // You should now have all songlist info in »QInfo['…']«
    //Put a jingle in the queue
    if (QInfo['songtype'] = 'S') then
    begin
      CAT['Jingles (All)'].QueueBottom(smLemmingLogic,NoRules);
    end;


  Q.Free;
  QInfo.Free;
//end;

//PAL.UnlockExecution;

@lumper
Throw out the obvious check lines, tweak accordingly, you should be good to go.

_________________
- Stan Olochwoszcz
- SVS (Spacial Volunteer Support)
A proud licensed SAM user since 2003

Raritan Bay Radio
Follow us on Twitter


Top
 Profile E-mail  
 
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 1:23 pm 
Offline
SVS Member
SVS Member
User avatar

Joined: October 14th, 2006, 9:38 am
Posts: 4447
Location: Deep in the heart of the PRNJ
Or you could do it Steve's way. :lol:

_________________
- Stan Olochwoszcz
- SVS (Spacial Volunteer Support)
A proud licensed SAM user since 2003

Raritan Bay Radio
Follow us on Twitter


Top
 Profile E-mail  
 
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 2:09 pm 
Offline
Junior User
Junior User
User avatar

Joined: October 4th, 2008, 12:35 pm
Posts: 39
Location: Kaufbeuren, Germany
Steve, my PAL hero :)
Always a way to optimize things. Great code.

_________________
Moonbase: The Problem Solver
I will not give any support for unlicensed or pirated software.


Top
 Profile E-mail  
 
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 2:20 pm 
Offline
Senior User
Senior User
User avatar

Joined: January 31st, 2004, 10:28 pm
Posts: 192
Location: Carrboro, North Carolina
Here's what worked for me... based on Steve's code:

QInfo := Query( 'select songtype from songlist AS sl, queuelist AS ql where sl.id = ql.songid order by ql.id desc limit 1', [], True);

while NOT (QInfo['songtype'] = 'S')

wait
else
add to QueueBottom

_________________
-Keith (Lumper5)
Visit http://www.deeperintomusic.net
Facebook: Become a "fan"
Twitter: Follow the leader


Top
 Profile  
 
 Post subject: Re: Queue.LastInQueue ?
PostPosted: November 13th, 2008, 6:49 pm 
Offline
Cygnus X-1
Cygnus X-1
User avatar

Joined: March 11th, 2003, 1:34 pm
Posts: 9656
Location: Maui, HI
Both return a TDataSet but one has the option to return the songtype field while the other does not.
As we say in Hawaii: if can, can; if no can, no can.

_________________
- Steve Kunitzer
- SVS (Spacial Volunteer Support) / Forum Administrator

Image
Image


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group