create rmName subroutine
This commit is contained in:
parent
91b0676343
commit
869a139809
|
@ -148,6 +148,21 @@ sub checkName
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Subroutine that deletes a name from a sql table
|
||||||
|
sub rmName
|
||||||
|
{
|
||||||
|
my $dbh = shift;
|
||||||
|
my $sqltable = shift;
|
||||||
|
my $sqlname = shift;
|
||||||
|
|
||||||
|
my $sql = "delete from $sqltable where Name = ?";
|
||||||
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
|
my $res = $sth->execute($sqlname) or die( "Can't execute: ".$sth->errstr() );
|
||||||
|
$sth->finish();
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
# Subroutine to import camera control & presets into the zoneminder dB
|
# Subroutine to import camera control & presets into the zoneminder dB
|
||||||
sub importsql
|
sub importsql
|
||||||
{
|
{
|
||||||
|
@ -189,49 +204,43 @@ sub importsql
|
||||||
foreach (keys %controls) {
|
foreach (keys %controls) {
|
||||||
if (!checkName($dbh,"Controls",$_)) {
|
if (!checkName($dbh,"Controls",$_)) {
|
||||||
# No existing Control was found. Add new control to dB.
|
# No existing Control was found. Add new control to dB.
|
||||||
$sql = $controls{$_};
|
my $sql = $controls{$_};
|
||||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
$res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
push @newcontrols, $_;
|
push @newcontrols, $_;
|
||||||
} elsif ($overwrite) {
|
} elsif ($overwrite) {
|
||||||
# An existing Control was found and the overwrite flag is set. Overwrite the control.
|
# An existing Control was found and the overwrite flag is set. Overwrite the control.
|
||||||
$sql = "delete from Controls where Name = ?";
|
rmName($dbh,"Controls",$_);
|
||||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sql = $controls{$_};
|
||||||
$res = $sth->execute($_) or die( "Can't execute: ".$sth->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
$sql = $controls{$_};
|
|
||||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
|
||||||
$res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
|
||||||
push @overwritecontrols, $_;
|
push @overwritecontrols, $_;
|
||||||
} else {
|
} else {
|
||||||
# An existing Control was found and the overwrite flag was not set. Do nothing.
|
# An existing Control was found and the overwrite flag was not set. Do nothing.
|
||||||
push @skippedcontrols, $_;
|
push @skippedcontrols, $_;
|
||||||
}
|
}
|
||||||
$sth->finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (keys %monitorpresets) {
|
foreach (keys %monitorpresets) {
|
||||||
if (!checkName($dbh,"MonitorPresets",$_)) {
|
if (!checkName($dbh,"MonitorPresets",$_)) {
|
||||||
# No existing MonitorPreset was found. Add new MonitorPreset to dB.
|
# No existing MonitorPreset was found. Add new MonitorPreset to dB.
|
||||||
$sql = $monitorpresets{$_};
|
my $sql = $monitorpresets{$_};
|
||||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
$res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
push @newpresets, $_;
|
push @newpresets, $_;
|
||||||
} elsif ($overwrite) {
|
} elsif ($overwrite) {
|
||||||
# An existing MonitorPreset was found and the overwrite flag is set. Overwrite the MonitorPreset.
|
# An existing MonitorPreset was found and the overwrite flag is set. Overwrite the MonitorPreset.
|
||||||
$sql = "delete from MonitorPresets where Name = ?";
|
rmName($dbh,"MonitorPresets",$_);
|
||||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
my $sql = $monitorpresets{$_};
|
||||||
$res = $sth->execute($_) or die( "Can't execute: ".$sth->errstr() );
|
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
|
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
$sql = $monitorpresets{$_};
|
|
||||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
|
||||||
$res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
|
||||||
push @overwritepresets, $_;
|
push @overwritepresets, $_;
|
||||||
} else {
|
} else {
|
||||||
# An existing MonitorPreset was found and the overwrite flag was not set. Do nothing.
|
# An existing MonitorPreset was found and the overwrite flag was not set. Do nothing.
|
||||||
push @skippedpresets, $_;
|
push @skippedpresets, $_;
|
||||||
}
|
}
|
||||||
$sth->finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@newcontrols) {
|
if (@newcontrols) {
|
||||||
|
|
Loading…
Reference in New Issue