Skip to Content
It is currently December 10th, 2023, 7:24 pm

All times are UTC - 6 hours [ DST ]




 [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: January 26th, 2010, 12:21 pm 
Offline
Senior User
Senior User

Joined: November 19th, 2008, 8:56 am
Posts: 78
Location: Sweden
Hi

I'm writing my first SQL-PAL script, but has ran in to some problem!

I'm trying to get the time from the database, to allow SAM to play a remote show, but I can't figure out the appropirate syntax for an SQL query. How do i corrent the code below?

It's based on the "remoteshow.pal" script!

(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):

   { SQL Get time }
   {==================================================}
   {Get current day}
   if DayOfWeek(Now) = Sunday   then    {NumDay = 0; NumWeekend = 8;};
   if DayOfWeek(Now) = Monday       then    {NumDay = 1; NumWeek = 7;};
   if DayOfWeek(Now) = Tuesday    then    {NumDay = 2; NumWeek = 7;};
   if DayOfWeek(Now) = Wednesday    then    {NumDay = 3; NumWeek = 7;};
   if DayOfWeek(Now) = Thursday    then    {NumDay = 4; NumWeek = 7;};
   if DayOfWeek(Now) = Friday       then    {NumDay = 5; NumWeekend = 8;};
   if DayOfWeek(Now) = Saturday    then    {NumDay = 6; NumWeekend = 8;};   
   
   {Make SQL Query}
   D := Query('SELECT t_program_tid_start, t_program_tid_slut FROM tabla WHERE (t_program_tid_start < :now) and (t_dag = :NumDay) or (t_dag = :NumWeek) or (t_dag = :NumWeekend) ORDER BY time ASC LIMIT 1',[NumDay,NumWeekend],True);
   D.First;


_________________

I'm a Customized Radio Automation Support System Specialist who have among other things developed:
- Shared database solution for use of 15 simultaneous remote users using streaming content as their only source of media, using SAM Broadcaster.
- PHP-Based clock wheel customized for SAM Broadcaster.
- Remote VoiceTracking Solution built in PHP and HTML5 upon SAM Broadcaster.

Questions? Contact me! Have a listen to my work at: http://powerfm.se


Top
 Profile  
 
PostPosted: January 26th, 2010, 12:57 pm 
Offline
Alumni
Alumni

Joined: March 11th, 2003, 1:34 pm
Posts: 9959
Location: Maui, HI
Is t_program_tid_start a date column?

If so, use (t_program_tid_start < now())

See also the MySQL documentation on now(): http://dev.mysql.com/doc/refman/5.1/en/ ... nction_now

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

Image
Image


Top
 Profile  
 
PostPosted: January 26th, 2010, 1:08 pm 
Offline
Senior User
Senior User

Joined: November 19th, 2008, 8:56 am
Posts: 78
Location: Sweden
Tank you for the answer, of course i will use Now() instead! What about the "NumDay" and "NumWeek" variables? They dosen't work veray well, i got the following error:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
Invalid instruction - function or assignment expected.


The problem occurs when I try to assign a value to TimeBegin (string).
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
   D := Query('SELECT t_program_tid_start, t_program_tid_slut FROM tabla WHERE (t_program_tid_start <= now()) and (t_dag = :NumDay) or (t_dag = :NumWeek) or (t_dag = :NumWeekend) ORDER BY time ASC LIMIT 1',[NumDay, NumWeek,NumWeekend],True);
   D.First;
   while not D.EOF do
      begin
         TimeBegin = D['starttime'];
         TimeEnd = D['endtime'];
         D.Next;
      end;
   D.Free;
   

_________________

I'm a Customized Radio Automation Support System Specialist who have among other things developed:
- Shared database solution for use of 15 simultaneous remote users using streaming content as their only source of media, using SAM Broadcaster.
- PHP-Based clock wheel customized for SAM Broadcaster.
- Remote VoiceTracking Solution built in PHP and HTML5 upon SAM Broadcaster.

Questions? Contact me! Have a listen to my work at: http://powerfm.se


Top
 Profile  
 
PostPosted: January 26th, 2010, 2:55 pm 
Offline
Alumni
Alumni

Joined: March 11th, 2003, 1:34 pm
Posts: 9959
Location: Maui, HI
Spelling counts :wink:
tabla -> table

The loop uses "starttime" and "endtime" which are not part of the SQL select.
Try running the SQL in something the Workbench or Query Browser before jumping into the PAL.

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

Image
Image


Top
 Profile  
 
PostPosted: January 26th, 2010, 4:20 pm 
Offline
Senior User
Senior User

Joined: November 19th, 2008, 8:56 am
Posts: 78
Location: Sweden
The word "tabla" is the Swedish word for "Schedule", but thanks anyway!

I see now that the assignment of the variables are all wrong, and empty of course!

Tanks, will be back whit futher questions, trust me!

_________________

I'm a Customized Radio Automation Support System Specialist who have among other things developed:
- Shared database solution for use of 15 simultaneous remote users using streaming content as their only source of media, using SAM Broadcaster.
- PHP-Based clock wheel customized for SAM Broadcaster.
- Remote VoiceTracking Solution built in PHP and HTML5 upon SAM Broadcaster.

Questions? Contact me! Have a listen to my work at: http://powerfm.se


Top
 Profile  
 
PostPosted: January 26th, 2010, 4:38 pm 
Offline
Senior User
Senior User

Joined: November 19th, 2008, 8:56 am
Posts: 78
Location: Sweden
Okay, the next problem is a IF-Statement, what's wrong whit the following code?
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
   
        if DayOfWeek(Now) = Sunday   then    NumDay = 0; NumWeekend = 8; end;   
   if DayOfWeek(Now) = Monday       then    NumDay = 1; NumWeek = 7; end;   
   if DayOfWeek(Now) = Tuesday    then    NumDay = 2; NumWeek = 7; end;   
   if DayOfWeek(Now) = Wednesday    then    NumDay = 3; NumWeek = 7; end;   
   if DayOfWeek(Now) = Thursday    then    NumDay = 4; NumWeek = 7; end;   
   if DayOfWeek(Now) = Friday       then    NumDay = 5; NumWeekend = 8; end;   
   if DayOfWeek(Now) = Saturday    then    NumDay = 6; NumWeekend = 8; end;   


Isen't here a function to return a numerical representation of the week, as i have done above?

The error i got was:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
Syntax error: Invalid Instruction - function or assignment expected


//Sebbe

_________________

I'm a Customized Radio Automation Support System Specialist who have among other things developed:
- Shared database solution for use of 15 simultaneous remote users using streaming content as their only source of media, using SAM Broadcaster.
- PHP-Based clock wheel customized for SAM Broadcaster.
- Remote VoiceTracking Solution built in PHP and HTML5 upon SAM Broadcaster.

Questions? Contact me! Have a listen to my work at: http://powerfm.se


Top
 Profile  
 
PostPosted: January 26th, 2010, 4:55 pm 
Offline
Alumni
Alumni

Joined: March 11th, 2003, 1:34 pm
Posts: 9959
Location: Maui, HI
Gotcha on the "tabla"; sorry about that.

PAL assignments are done with := not just =.

Example (assume foo is an Integer variable):
foo := 4;


Also, the value of NumWeekend will always be 8 regardless of the day of week.
Here's the first two statements on separate lines and spaced for blocks:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
if DayOfWeek(Now) = Sunday then   
  NumDay := 0;

NumWeekend := 8;
end;   

if DayOfWeek(Now) = Monday then   
  NumDay := 1;

NumWeek := 7;
end; 


If the idea is to do a NumDay and NumWeekend assignment per day of week check then do this:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
if DayOfWeek(Now) = Sunday then   
  begin
    NumDay := 0;
    NumWeekend := 8;
  end;

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

Image
Image


Top
 Profile  
 
PostPosted: January 26th, 2010, 5:33 pm 
Offline
Senior User
Senior User

Joined: November 19th, 2008, 8:56 am
Posts: 78
Location: Sweden
Okay, I made a new if-statement as you proposed, but there's an error at the "end;" of this whit the following syntax error:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
Syntax error: ";" expected. [line:29, column: 2]



The code:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
if DayOfWeek(Now) = Monday then    
    NumDay := 1;
    NumWeek := 7;
end;   


Why is there an syntexerror, and why at "end;"?
Is there any way of getting more detailed error messages?

Tank you so mutch for the help so far!

_________________

I'm a Customized Radio Automation Support System Specialist who have among other things developed:
- Shared database solution for use of 15 simultaneous remote users using streaming content as their only source of media, using SAM Broadcaster.
- PHP-Based clock wheel customized for SAM Broadcaster.
- Remote VoiceTracking Solution built in PHP and HTML5 upon SAM Broadcaster.

Questions? Contact me! Have a listen to my work at: http://powerfm.se


Top
 Profile  
 
PostPosted: January 26th, 2010, 6:05 pm 
Offline
SVS Member
SVS Member

Joined: May 8th, 2004, 9:00 am
Posts: 10572
Location: Denver, CO
You need a begin
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
if DayOfWeek(Now) = Monday then   
begin
    NumDay := 1;
    NumWeek := 7;
end;   

_________________
- Rob Oyler, SVS
Image


Top
 Profile  
 
PostPosted: January 26th, 2010, 6:10 pm 
Offline
SVS Member
SVS Member

Joined: May 8th, 2004, 9:00 am
Posts: 10572
Location: Denver, CO
Might I suggest you spend some time with the PAL quick start guide? http://support.spacialaudio.com/wiki/PAL_Quick_Start

_________________
- Rob Oyler, SVS
Image


Top
 Profile  
 
PostPosted: January 26th, 2010, 7:20 pm 
Offline
Senior User
Senior User

Joined: November 19th, 2008, 8:56 am
Posts: 78
Location: Sweden
Thank you again for sutch quick answers! I have the PAL beginner manual here and I'm reading it all time!

Well, I got the script working... but there is still one question to be answerd:

The SQL returns a value of 12:00:00 AM, but there is no row in the database that holds that information, why do i keep getting this information?

Here is the full version of the script:
(!empty($user->lang['CODE'])) ? $user->lang['CODE'] : ucwords(strtolower(str_replace('_', ' ', 'CODE'))):
   { About:
      This script will play a remote show inside SAM
      The show starts at a specified time, and then ends at
      another specified time.
      
      The script also contains some error-correction code
      that will attempt to connect to the stream up to 20 times
      in case it goes down. We schedule one song between each attempt.
   }
   
   {Declare variables}
   var NumWeekend, NumWeek, NumDay : Integer;
   var TimeBegin, TimeEnd : datetime;
   NumWeekend := 100;
   NumWeek := 100;
   var D : TDataSet;
   
   
   { CONFIGURATION }
   {==================================================}
   const ShowURL   = 'http://url.org:6600/';

   { SQL Get time }
   {==================================================}
   {Get current day}
   if DayOfWeek(Now) = Sunday   then
 begin   
    NumDay := 0;
    NumWeekend := 8;
 end;
    
   if DayOfWeek(Now) = Monday       then    
 begin
    NumDay := 1;
    NumWeek := 7;
 end;   
 
   if DayOfWeek(Now) = Tuesday    then    
 begin    
    NumDay := 2;
    NumWeek := 7;
 end;   
   if DayOfWeek(Now) = Wednesday    then    
 begin    
    NumDay := 3;
    NumWeek := 7;
 end;   
   if DayOfWeek(Now) = Thursday    then    
 begin    
    NumDay := 4;
    NumWeek := 7;
 end;   
   if DayOfWeek(Now) = Friday       then    
 begin    
    NumDay := 5; NumWeekend := 8;
 end;   
   if DayOfWeek(Now) = Saturday    then    
 begin    
    NumDay := 6;
    NumWeekend := 8;
 end;   
   
   {Make SQL Query}
   D := Query('SELECT t_program_tid_start, t_program_tid_slut FROM tabla WHERE (t_dag = :NumDay) or (t_dag = :NumWeek) or (t_dag = :NumWeekend) ORDER BY t_program_tid_start ASC LIMIT 1',[NumDay, NumWeek,NumWeekend],True);
   D.First;
   while not D.EOF do
      begin
         TimeBegin := D['t_program_tid_start'];
         WriteLn(TimeBegin);
         TimeEnd := D['t_program_tid_slut'];
         D.Next;
      end;
   D.Free;
   
   if(TimeBegin > T['-00:00:30']) and (TimeBegin < T['+00:00:30']) then    
 begin
      { Wait for next broadcast }
      {==================================================}
      PAL.WaitForTime(TimeBegin);

      { IMPLEMENTATION }
      {--------------------------------------------------}
      var T : Integer;
      PAL.Loop := True;

      {Wait for the show to start}
      PAL.WaitForTime(TimeBegin);

      {Add show to queue}
      Queue.Clear;
      Queue.AddURL(ShowURL,ipTop);

      {Fade to show}
      ActivePlayer.FadeToNext;

      {Precautions - if there is a brief disconnect or server problem,
      then we would want to retry a few times to get back to the show.
      To do this we place the URL quite a few times in the queue, followed
      by some normal programmming. That way we will try and reconnect until
      the end of the show}

      T := 0;
      while T < 20 do
      begin
        Queue.AddURL(ShowURL,ipBottom);
        CAT['New'].QueueBottom(smLRP,EnforceRules);
        T := T + 1;
      end;
      
      {Wait for show to end}
      PAL.WaitForTime(TimeEnd);
      
      {Add show to queue}
      Queue.Clear;

      {Fade to normal programming}
      ActivePlayer.FadeToNext;
      
      
   {End of if-time}
   end;
      
   { Loop this script }
   PAL.Loop := True;



//Sebbe

_________________

I'm a Customized Radio Automation Support System Specialist who have among other things developed:
- Shared database solution for use of 15 simultaneous remote users using streaming content as their only source of media, using SAM Broadcaster.
- PHP-Based clock wheel customized for SAM Broadcaster.
- Remote VoiceTracking Solution built in PHP and HTML5 upon SAM Broadcaster.

Questions? Contact me! Have a listen to my work at: http://powerfm.se


Top
 Profile  
 
PostPosted: January 26th, 2010, 8:24 pm 
Offline
SVS Member
SVS Member

Joined: May 8th, 2004, 9:00 am
Posts: 10572
Location: Denver, CO
Most obvious question is the database table tabla is that something you populate from another source? It is not a standard samdb table.

_________________
- Rob Oyler, SVS
Image


Top
 Profile  
 
PostPosted: January 26th, 2010, 8:32 pm 
Offline
Senior User
Senior User

Joined: November 19th, 2008, 8:56 am
Posts: 78
Location: Sweden
Yes it is a database from my current radiosite, if it's possible can I connect to that database from PAL directly whiyout copying it to SAMDB?

_________________

I'm a Customized Radio Automation Support System Specialist who have among other things developed:
- Shared database solution for use of 15 simultaneous remote users using streaming content as their only source of media, using SAM Broadcaster.
- PHP-Based clock wheel customized for SAM Broadcaster.
- Remote VoiceTracking Solution built in PHP and HTML5 upon SAM Broadcaster.

Questions? Contact me! Have a listen to my work at: http://powerfm.se


Top
 Profile  
 
PostPosted: January 26th, 2010, 9:47 pm 
Offline
Alumni
Alumni

Joined: March 11th, 2003, 1:34 pm
Posts: 9959
Location: Maui, HI
PAL will only connect to the SAM database; it will not make connections to other databases (local or remote).

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

Image
Image


Top
 Profile  
 
PostPosted: January 27th, 2010, 8:41 am 
Offline
Senior User
Senior User

Joined: November 19th, 2008, 8:56 am
Posts: 78
Location: Sweden
Okay, that's to bad. Any clue about why it returns the value of 12:00:00 AM?

_________________

I'm a Customized Radio Automation Support System Specialist who have among other things developed:
- Shared database solution for use of 15 simultaneous remote users using streaming content as their only source of media, using SAM Broadcaster.
- PHP-Based clock wheel customized for SAM Broadcaster.
- Remote VoiceTracking Solution built in PHP and HTML5 upon SAM Broadcaster.

Questions? Contact me! Have a listen to my work at: http://powerfm.se


Top
 Profile  
 
Display posts from previous:  Sort by  
 [ 18 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 7 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:  
cron
Powered by phpBB® Forum Software © phpBB Group