From c1d4230a6699ea9b41855a7f233ff1bd546d2949 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 10 Feb 2016 05:08:33 +0100 Subject: updated to new library version diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index 1be87ac..64837da 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -30,7 +30,7 @@ use RHRD::utils; ########################### constants ########################### use constant { - DB_VERSION => 245, + DB_VERSION => 250, RD_CONFIG_FILE => '/etc/rd.conf', RD_INVALID_CART => 0, RD_MIN_CART => 1, @@ -1473,26 +1473,20 @@ sub get_musicpools_clocks { my ($ctx) = @_; - my @reqs; - for my $day (0 .. 6){ - for my $hour (0 .. 23){ - my $dow = $day + 1; - $dow = 0 if $dow >=7; - push @reqs, 'select ' . $dow . ' as DOW ,' . $hour . ' as HOUR,CLOCK' . (($day*24) + $hour) . - ' as CLOCK from SERVICES where NAME=' . $ctx->{'dbh'}->quote($ctx->{'config'}{'shows'}{'service'}); - } - } - - my $sql = 'select GRID.DOW,GRID.HOUR,CLOCKS.SHORT_NAME,CLOCKS.COLOR,GROUPS.DESCRIPTION from DROPBOXES,GROUPS,CLOCKS,(' . join(' UNION ' , @reqs) . ") as GRID where GRID.CLOCK = CLOCKS.NAME and CLOCKS.SHORT_NAME = DROPBOXES.PATH and DROPBOXES.GROUP_NAME = GROUPS.NAME;"; + my $sql = 'select SVC_CLOCKS.HOUR,CLOCKS.SHORT_NAME,CLOCKS.COLOR,GROUPS.DESCRIPTION from DROPBOXES,GROUPS,CLOCKS,SVC_CLOCKS where SVC_CLOCKS.SERVICE_NAME = ? and SVC_CLOCKS.CLOCK_NAME = CLOCKS.NAME and CLOCKS.SHORT_NAME = DROPBOXES.PATH and DROPBOXES.GROUP_NAME = GROUPS.NAME order by SVC_CLOCKS.HOUR;'; my $sth = $ctx->{'dbh'}->prepare($sql) or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); - my $cnt = $sth->execute() + my $cnt = $sth->execute($ctx->{'config'}{'shows'}{'service'}) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); my @clocks; - while(my ($dow, $hour, $shortname, $color, $title) = $sth->fetchrow_array()) { + while(my ($idx, $shortname, $color, $title) = $sth->fetchrow_array()) { + my $dow = int($idx / 24) + 1; + $dow = 0 if $dow > 6; + my $hour = $idx % 24; + my $clock = {}; $clock->{'DOW'} = $dow; $clock->{'HOUR'} = $hour; @@ -1529,12 +1523,15 @@ sub set_musicpools_clock my $day = $dow - 1; $day = 6 if $dow == 0; my $idx = (($day*24) + $hour); - $sql = 'update SERVICES set CLOCK' . $idx . ' = ? where NAME = ?'; + $sql = 'update SVC_CLOCKS set CLOCK_NAME = ? where SERVICE_NAME = ? and HOUR = ?'; - my $rows = $ctx->{'dbh'}->do($sql, undef, $name, $ctx->{'config'}{'shows'}{'service'}) + $sth = $ctx->{'dbh'}->prepare($sql) or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); - unless($rows == 1) { + my $cnt = $sth->execute($name, $ctx->{'config'}{'shows'}{'service'}, $idx) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + unless($cnt == 1) { return (undef, 'ERROR', "clock does not exist") } return (1, 'OK', 'success'); diff --git a/test/set-music-clocks b/test/set-music-clocks new file mode 100755 index 0000000..65814a9 --- /dev/null +++ b/test/set-music-clocks @@ -0,0 +1,42 @@ +#!/usr/bin/perl -w +# +# rhrdlibs +# +# Copyright (C) 2015 Christian Pointner +# +# This file is part of rhrdlibs. +# +# rhrdlibs is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# rhrdlibs is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with rhrdlibs. If not, see . +# + +use strict; +use POSIX; +use lib "../lib/"; +use RHRD::rddb; + + +my @clocks = (); +my ($ctx, $status, $errorstring) = RHRD::rddb::init(); +if(defined $ctx) { + my ($result, $status, $errorstring) = RHRD::rddb::set_musicpools_clock($ctx, 0, 14, "P01"); + if(!defined $result) { + print STDERR "$errorstring\n"; + } else { + print "Success.\n"; + } + RHRD::rddb::destroy($ctx); +} else { + print STDERR "$errorstring\n"; + exit 1; +} -- cgit v0.10.2