Joined: January 31st, 2004, 10:28 pm Posts: 194 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?
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.
Joined: January 31st, 2004, 10:28 pm Posts: 194 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.
Joined: March 11th, 2003, 1:34 pm Posts: 9661 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
Joined: October 14th, 2006, 9:38 am Posts: 4453 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
Joined: March 11th, 2003, 1:34 pm Posts: 9661 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
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