Linux-DVB-DVBT-Apps-QuartzPVR
view release on metacpan or search on metacpan
lib/Linux/DVB/DVBT/Apps/QuartzPVR/Sql.pm view on Meta::CPAN
my ($rid) = @_ ;
print "\n\n[delete_recording $rid]\n" if $this->debug ;
$this->sql->debug($this->debug) ;
# prepare search vars
$this->sql_prepare_vals({'id' => $rid}) ;
# do delete
$this->sql->sth_query('delete_recording') ;
$this->sql->debug(0) ;
}
#---------------------------------------------------------------------------------------------------
# Insert new recording
sub insert_recording
{
my $this = shift ;
my ($rec_href) = @_ ;
print "\n\n[insert_recording]\n" if $this->debug ;
$this->sql->debug($this->debug) ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::startfn('insert_recording') ;
# prepare search vars
$this->sql_prepare_vals($rec_href) ;
my $sql_vars_href = $this->sql_vars ;
$this->prt_data("[insert_recording] sql_vars_href=", $sql_vars_href) if $this->debug ;
# do insert
$this->sql->sth_query('insert_recording') ;
# Don't know why, but this doesn't work!
# # get insert id
# my $dbh = $this->sql->connect() ;
# my $rid = $dbh->{'mysql_insertid'} ;
#print "dbh=$dbh rid=$rid\n" if $this->debug ;
# get insert id
my $rid = -2 ;
my @recordings = $this->sql->sth_query_all('select_latest_recording') ;
if (@recordings)
{
$rid = $recordings[0]{'id'} ;
}
print " + rid=$rid\n" if $this->debug ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::add_rec($rec_href, "inserted - new rid $rid") ;
$this->sql->debug(0) ;
return $rid ;
}
#---------------------------------------------------------------------------------------------------
# Update recording
sub update_recording
{
my $this = shift ;
my ($rec_href) = @_ ;
print "\n\n[update_recording]\n" if $this->debug ;
$this->sql->debug($this->debug) ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::startfn('update_recording') ;
# prepare search vars
$this->sql_prepare_vals($rec_href) ;
my $sql_vars_href = $this->sql_vars ;
$this->prt_data("[update_recording] sql_vars_href=", $sql_vars_href) if $this->debug ;
# do delete
$this->sql->sth_query('update_recording') ;
$this->sql->debug(0) ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::add_rec($rec_href, 'updated') ;
}
#---------------------------------------------------------------------------------------------------
# Return the scheduled recordings
sub select_scheduled
{
my $this = shift ;
print "\n\n[select_scheduled]\n" if $this->debug ;
$this->sql->debug($this->debug) ;
my @recordings = $this->sql->sth_query_all('select_schedule') ;
$this->prt_data("[select_scheduled] results=", \@recordings) if $this->debug ;
$this->sql->debug(0) ;
return @recordings ;
}
#---------------------------------------------------------------------------------------------------
# Return the scheduled iplay recordings
sub select_iplay
{
my $this = shift ;
print "\n\n[select_iplay]\n" if $this->debug ;
$this->sql->debug($this->debug) ;
my @recordings = $this->sql->sth_query_all('select_iplay') ;
$this->prt_data("[select_iplay] results=", \@recordings) if $this->debug ;
$this->sql->debug(0) ;
return @recordings ;
}
#---------------------------------------------------------------------------------------------------
# Select a single program based on channel/pid/title
sub select_program
{
lib/Linux/DVB/DVBT/Apps/QuartzPVR/Sql.pm view on Meta::CPAN
# Get sql query name
my $query_name = Linux::DVB::DVBT::Apps::QuartzPVR::Base::Constants::query_name($record_type) ;
print "Record=$record_type : Query name=$query_name\n" if $this->debug>=2 ;
# prepare search vars
$this->sql_prepare_vals($rec_href) ;
my $sql_vars_href = $this->sql_vars ;
$this->prt_data("sched_href=", $rec_href) if $this->debug ;
$this->prt_data("[$query_name] sql_vars_href=", $sql_vars_href) if $this->debug ;
# perform query
my @listings = $this->sql->sth_query_all($query_name) ;
$this->prt_data(" + Query=$query_name, Sched=", $rec_href) if $this->debug>=2 ;
$this->prt_data(" + Windowed : ", \@listings) if $this->debug>=2 ;
$this->sql->debug(0) ;
# return results
return @listings ;
}
#---------------------------------------------------------------------------------------------------
# Get a list of all dates from specified to the end of the EPG
sub select_listings_days
{
my $this = shift ;
my ($date) = @_ ;
$this->sql->debug($this->debug) ;
# prepare search vars
$this->sql_prepare_vals({'date' => $date}) ;
my $sql_vars_href = $this->sql_vars ;
$this->prt_data("[select_listings_days] sql_vars_href=", $sql_vars_href) if $this->debug ;
# perform query
my @listings = $this->sql->sth_query_all('select_listings_days') ;
$this->prt_data(" + Listings : ", \@listings) if $this->debug>=2 ;
$this->sql->debug(0) ;
# create a list of just the dates
my @days ;
foreach my $entry_href (@listings)
{
push @days, $entry_href->{'date'} ;
}
# return results
return @days ;
}
#---------------------------------------------------------------------
# Gets the latest scheduled recordings list from the database and also
# sets up various date/time values for later use
sub update_schedule_table
{
my $this = shift ;
my ($recording_aref) = @_ ;
$this->sql->debug($this->debug) ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::startfn('update_schedule_table') ;
my $tbl_schedule = $this->tbl_schedule ;
my $tbl_multirec = $this->tbl_multirec ;
$this->prt_data("[insert_schedule] recording_aref=", $recording_aref) if $this->debug ;
# clear tables
$this->sql->do("TRUNCATE TABLE $tbl_schedule") ;
$this->sql->do("TRUNCATE TABLE $tbl_multirec") ;
# Insert a line for each program
foreach my $href (@$recording_aref)
{
my @recs = ($href) ;
if ($href->{'type'} eq 'multiplex')
{
# insert multiplex container
$this->sql_prepare_vals($href) ;
my $sql_vars_href = $this->sql_vars ;
$this->prt_data("[insert_multirec] sql_vars_href=", $sql_vars_href) if $this->debug ;
$this->sql->sth_query('insert_multirec') ;
# insert the multiplex programs
@recs = @{$href->{'multiplex'}} ;
}
foreach my $rec_href (@recs)
{
# insert program details
$this->sql_prepare_vals($rec_href) ;
my $sql_vars_href = $this->sql_vars ;
$this->prt_data("[insert_schedule] sql_vars_href=", $sql_vars_href) if $this->debug ;
$this->sql->sth_query('insert_schedule') ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::add_rec($rec_href, 'updated') ;
}
}
## Update recording recording - prune out old jobs
$this->sql->sth_query('delete_old_recording') ;
$this->sql->debug(0) ;
}
#---------------------------------------------------------------------
# Gets the latest scheduled iplay recordings list from the database and also
# sets up various date/time values for later use
sub update_iplay_table
{
my $this = shift ;
my ($recording_aref) = @_ ;
$this->sql->debug($this->debug) ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::startfn('update_iplay_table') ;
my $tbl_iplay = $this->tbl_iplay ;
$this->prt_data("[insert_iplay] recording_aref=", $recording_aref) if $this->debug ;
# clear tables
$this->sql->do("TRUNCATE TABLE $tbl_iplay") ;
# Insert a line for each program
foreach my $rec_href (@$recording_aref)
{
# insert program details
$this->sql_prepare_vals($rec_href) ;
my $sql_vars_href = $this->sql_vars ;
$this->prt_data("[insert_iplay] sql_vars_href=", $sql_vars_href) if $this->debug ;
$this->sql->sth_query('insert_iplay') ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::add_rec($rec_href, 'updated') ;
}
$this->sql->debug(0) ;
}
#---------------------------------------------------------------------------------------------------
# Insert new recorded entry - tracks recordings
sub insert_recorded
{
my $this = shift ;
my ($rec_href) = @_ ;
print "\n\n[insert_recorded]\n" if $this->debug ;
$this->sql->debug($this->debug) ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::startfn('insert_recorded') ;
# prepare search vars
my $vars_href = {
%$rec_href,
} ;
$this->sql_prepare_vals($vars_href) ;
my $sql_vars_href = $this->sql_vars ;
$this->prt_data("[insert_recorded] sql_vars_href=", $sql_vars_href) if $this->debug ;
# do insert
$this->sql->sth_query('insert_recorded') ;
$this->sql->debug(0) ;
}
#---------------------------------------------------------------------------------------------------
# Delete existing recorded entry - tracks recordings
sub delete_recorded
{
my $this = shift ;
my ($rec_href) = @_ ;
print "\n\n[delete_recorded] pid=$rec_href->{pid}, rectype=$rec_href->{rectype}\n" if $this->debug ;
$this->sql->debug($this->debug) if $this->debug >= 2 ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::startfn('delete_recorded') ;
# prepare search vars
$this->sql_prepare_vals($rec_href) ;
my $sql_vars_href = $this->sql_vars ;
$this->prt_data("[delete_recorded] sql_vars_href=", $sql_vars_href) if $this->debug >= 2 ;
# do delete
$this->sql->sth_query('delete_recorded') ;
$this->sql->debug(0) if $this->debug >= 2 ;
}
#---------------------------------------------------------------------------------------------------
# Check for existence of recorded entry - tracks recordings
sub select_recorded
{
my $this = shift ;
my ($rec_href) = @_ ;
print "\n\n[select_recorded] pid=$rec_href->{pid}, rectype=$rec_href->{rectype}\n" if $this->debug ;
$this->sql->debug($this->debug) if $this->debug >= 2 ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::startfn('select_recorded') ;
# prepare search vars
$this->sql_prepare_vals($rec_href) ;
my $sql_vars_href = $this->sql_vars ;
$this->prt_data("[select_recorded] sql_vars_href=", $sql_vars_href) if $this->debug >= 2 ;
# do select
my @list = $this->sql->sth_query_all('select_recorded') ;
$this->prt_data("[select_recorded] results=", \@list) if $this->debug ;
$this->sql->debug(0) ;
return \@list ;
}
#---------------------------------------------------------------------------------------------------
# Update an existing recorded entry - tracks recordings
sub update_recorded
{
my $this = shift ;
my ($rec_href) = @_ ;
print "\n\n[update_recorded] pid=$rec_href->{pid}, rectype=$rec_href->{rectype}\n" if $this->debug ;
$this->sql->debug($this->debug) if $this->debug >= 2 ;
Linux::DVB::DVBT::Apps::QuartzPVR::Base::DbgTrace::startfn('update_recorded') ;
# prepare search vars
$this->sql_prepare_vals($rec_href) ;
my $sql_vars_href = $this->sql_vars ;
$this->prt_data("[update_recorded] sql_vars_href=", $sql_vars_href) if $this->debug >= 2 ;
# do update
$this->sql->sth_query('update_recorded') ;
$this->sql->debug(0) if $this->debug >= 2 ;
}
# ============================================================================================
# END OF PACKAGE
1;
__END__
( run in 2.177 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )