mscdelete2
戻る
#!C:/perl/bin/perl
######################################
# mscdelete2.pl
######################################
use strict;
use DBI;
use CGI qw/:standard/;
use HTML::Template;
my ( %t, @rec, @loop, $n, $p_ref );
$t{q} = new CGI;
$t{enq1_id} = $t{q}->param("enq1_id");
$t{id2} = $t{q}->param("id2");
$t{NO1} = $t{q}->param("NO1"); # 主機タイプの順番
$t{template} = HTML::Template->new(filename => 'mscdelete2.htm');
$t{dsn} = "DBI:mysql:host=localhost;database=cookbook";
$t{dbh} = DBI->connect($t{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n";
$t{dbh}->do("SET NAMES utf8");
if(!$t{dbh}){
print "SQL read ERROR!\n";
exit;
}
$$p_ref{NO1} = $t{NO1};
$$p_ref{id2} = $t{id2};
$$p_ref{list2} = $t{dbh}->selectrow_array("select partsid from enq1 where id = $t{enq1_id}");
($p_ref) = parts2($p_ref);
$t{sql} = 'UPDATE enq1 set ' . 'partsid' . ' = "';
$t{sql} .= $$p_ref{list2new} . '" where id = ';
$t{sql} .= $t{enq1_id};
$t{DO} = $t{dbh}->do($t{sql});
$t{dbh}->disconnect;
$t{template}->param(enq1_id => $t{enq1_id});
$t{template}->param(id2 => $t{id2});
$t{template}->param(NO1 => $t{NO1});
$t{template}->param(DO => $t{DO});
$t{template}->param(sql => $t{sql});
# send the obligatory Content-Type and print the template output
print $t{template}->output;
sub parts2 { #パーツ削除処理
my($p_ref) = @_;
my(%t,$n,$n1);
$t{list2} = $$p_ref{list2};
$t{NO1} = $$p_ref{NO1};
$t{id2} = $$p_ref{id2};
@{ $t{list2s} } = split(/==/,$t{list2});
@{ $t{list2snew} } = ();
@{ $t{list2ssnew} } = ();
for $n ( 0 .. $#{ $t{list2s} }) {
$t{NO2} = $n + 1;
if ( $t{NO1} == $t{NO2} ) {
@{ $t{list2ss} } = split(/=/,$t{list2s}[$n]);
for $n1 ( 0 .. $#{ $t{list2ss} } ) {
next if ( $t{id2} == $t{list2ss}[$n1] );
push(@{ $t{list2ssnew} },$t{list2ss}[$n1]);
}
$t{list2new} = join('=',@{ $t{list2ssnew} });
push(@{ $t{list2snew} },$t{list2new});
} else {
push(@{ $t{list2snew} },$t{list2s}[$n]);
}
}
$$p_ref{list2new} = join('==',@{ $t{list2snew} });
return($p_ref);
}
1;
-------------------------------------------------------------------------------
mscdelete
mscdelete
http://localhost/scripts/mscenq1_p.pl
ENQ_ID==>
id2==>
NO1==>
DO==>
sql==>
戻る