MySQL操作程序三十二(零件選擇程序,mscshowparts10.pl)
返回
[Sun Sep 12 21:25:37 2010] [error] [client 127.0.0.1] Use of uninitialized value in pattern match (m//) at ./pro/mscshowparts.pl line 122, line
[Sun Sep 12 21:25:37 2010] [error] [client 127.0.0.1] Use of uninitialized value in join or string at ./pro/mscshowparts.pl line 201, line 11.,
[Sun Sep 12 21:24:43 2010] [error] [client 127.0.0.1] splice() offset past end of array at ./pro/mscshowparts.pl line 324, line 11., referer:
sub is_positive_integer {
my $s = shift;
122: return ($s =~ /^\+?\d+$/ && $s > 0 );
}
修改如下
if ($t{p11s}[4]) {
$t{valid} = is_positive_integer($t{p11s}[4]);
if ( $t{valid} == 1 && $t{p11s}[4] <= $t{owner_maxid} ) {
$t{owner} = $self->dbh->selectrow_array("SELECT company FROM owners WHERE id = $t{p11s}[4]");
} else {
$t{owner} = 'X';
}
} else {
$t{owner} = 'X';
}
201: $t{p13} = join('/',@{ $t{p12} });
324:@{ $t{percents} } = splice(@{ $t{percent_all} },$t{N1},$t{N2});;
為解決「ENQ畫面點擊"零件選擇"失敗問題」(mscshowparts10.pl),編一個離線的showprice.pl程序檢查數(shù)據(jù)庫數(shù)據(jù)
問題解決,price1的初期設(shè)定長度和后來寫入價格數(shù)據(jù)的長度不一致!見下面show_price1的增加。
mscshowprts10.pl,取消=>恢復(fù)
mscparts10.htm,商社價格,船東價格取消=>恢復(fù)
# showprice.pl
# 程序檢查數(shù)據(jù)庫數(shù)據(jù)
use strict;
use DBI;
my(%t,$n,@fld,@rec,$pref);
print "This is showprice.pl.\n";
# 輸入表格ID
print "Please input type id=";
chop($t{typeid}=);
print "$t{typeid}\n";
# 連接數(shù)據(jù)庫
$$pref{dsn} = "DBI:mysql:host=localhost;database=cookbook";
$$pref{dbh} = DBI->connect($$pref{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n";
$$pref{dbh}->do("SET NAMES utf8");
if(!$$pref{dbh}){
print "SQL read ERROR!\n";
exit;
}
# 取出DWG圖號
$t{DWG} = $$pref{dbh}->selectrow_array("SELECT DWG FROM main_type1 WHERE id = $t{typeid}");
@{ $t{DWGs} } = split(/=/,$t{DWG});
# 零件表名
$t{ptable} = sprintf("%06d",$t{typeid});
$t{ptable} = 'a' . $t{ptable};
# 最大廠家id
$t{maker_maxid} = $$pref{dbh}->selectrow_array("SELECT max(id) FROM makers");
# 取出零件
$t{sth} = $$pref{dbh}->prepare("select * from $t{ptable}");
$t{sth}->execute;
while (@rec = $t{sth}->fetchrow_array) {
$t{dwg} = $t{DWGs}[$rec[3]-1];
$t{Nuid1} = $rec[4];
$t{Nuid} = $$pref{dbh}->selectrow_array("select parts_Unit from parts_nu where id = $t{Nuid1}");
$t{p1} = $rec[6];
$t{p2} = $rec[7];
@{ $t{p1s} } = split(/==/,$t{p1});
for $n ( 0 .. $#{ $t{p1s} } ) {
$t{p11} = $t{p1s}[$n];
@{ $t{p11s} } = split(/=/,$t{p11});
@{ $t{p12} } = @{ $t{p11s} }[0..1];
$t{valid} = is_positive_integer($t{p11s}[2]);
if ( $t{valid} == 1 && $t{p11s}[2] <= 5 ) {
$t{money1} = $$pref{dbh}->selectrow_array("SELECT English FROM money WHERE id = $t{p11s}[2]");
} else {
$t{money1} = 'X';
}
push(@{ $t{p12} },$t{money1});
push(@{ $t{p12} },$t{p11s}[3]);
push(@{ $t{p12} },$t{p11s}[4]);
$t{valid} = is_positive_integer($t{p11s}[5]);
if ( $t{valid} == 1 && $t{p11s}[5] <= $t{maker_maxid} ) {
$t{maker1} = $$pref{dbh}->selectrow_array("SELECT company FROM makers WHERE id = $t{p11s}[5]");
} else {
$t{maker1} = 'X';
}
push(@{ $t{p12} },$t{maker1});
if ( $t{p11s}[6] ) {
push(@{ $t{p12} },$t{p11s}[6]);
} else {
push(@{ $t{p12} },'Y');
}
print $rec[0],'--',"@{ $t{p11s} }\n";
print $rec[0],'==',"@{ $t{p12} }\n";
}
}
$t{sth}->finish;
#print "ptable=$t{ptable}\n";
# 關(guān)閉數(shù)據(jù)庫
$$pref{dbh}->disconnect;
exit;
sub is_positive_integer {
my $s = shift;
return ($s =~ /^\+?\d+$/ && $s > 0 );
}
mscshorparts.pl
sub is_positive_integer {
my $s = shift;
return ($s =~ /^\+?\d+$/ && $s > 0 );
}
sub show_price1 {
my($row_ref,$self,$pref) = @_;
my(%t,@members,%price1);
$price1{p1} = '';
@{ $t{p1s} } = split(/==/,$$pref{p1});
$t{maker_maxid} = $self->dbh->selectrow_array("SELECT max(id) FROM makers");
for $n ( 0 .. $#{ $t{p1s} } ) {
$t{p11} = $t{p1s}[$n];
@{ $t{p11s} } = split(/=/,$t{p11});
@{ $t{p12} } = @{ $t{p11s} }[0..1];
$t{valid} = is_positive_integer($t{p11s}[2]);
if ( $t{valid} == 1 && $t{p11s}[2] <= 5 ) {
$t{money1} = $self->dbh->selectrow_array("SELECT English FROM money WHERE id = $t{p11s}[2]");
} else {
$t{money1} = 'X';
}
push(@{ $t{p12} },$t{money1});
# push(@{ $t{p12} },$t{p11s}[2]);
push(@{ $t{p12} },$t{p11s}[3]);
push(@{ $t{p12} },$t{p11s}[4]);
if ( $t{p11s}[5] ) { # 增加
$t{valid} = is_positive_integer($t{p11s}[5]);
if ( $t{valid} == 1 && $t{p11s}[5] <= $t{maker_maxid} ) {
$t{maker1} = $self->dbh->selectrow_array("SELECT company FROM makers WHERE id = $t{p11s}[5]");
} else {
$t{maker1} = 'X';
}
} else {
$t{maker1} = 'X';
}
push(@{ $t{p12} },$t{maker1});
# push(@{ $t{p12} },$t{p11s}[5]);
if ( $t{p11s}[6] ) { # 增加
push(@{ $t{p12} },$t{p11s}[6]);
} else {
push(@{ $t{p12} },'Y');
}
$t{p13} = join('/',@{ $t{p12} });
$price1{p1} .= '' . $t{p13} . ' ';
@members = ();
push @members, { %price1 };
$row_ref->{PRICE1} = [ @members ];
}
return($row_ref,$self,$pref);
}
sub show_price2 {
my($row_ref,$self,$pref) = @_;
my(%t,@members,%price1);
$price1{p1} = '';
@{ $t{p1s} } = split(/==/,$$pref{p1});
$t{owner_maxid} = $self->dbh->selectrow_array("SELECT max(id) FROM owners");
for $n ( 0 .. $#{ $t{p1s} } ) {
$t{p11} = $t{p1s}[$n];
@{ $t{p11s} } = split(/=/,$t{p11});
@{ $t{p12} } = @{ $t{p11s} }[0..1];
$t{valid} = is_positive_integer($t{p11s}[2]);
if ( $t{valid} == 1 && $t{p11s}[2] <= 5 ) {
$t{money1} = $self->dbh->selectrow_array("SELECT English FROM money WHERE id = $t{p11s}[2]");
} else {
$t{money1} = 'X';
}
push(@{ $t{p12} },$t{money1});
# push(@{ $t{p12} },$t{p11s}[2]);
push(@{ $t{p12} },$t{p11s}[3]);
$t{valid} = is_positive_integer($t{p11s}[4]);
if ( $t{valid} == 1 && $t{p11s}[4] <= $t{owner_maxid} ) {
$t{owner} = $self->dbh->selectrow_array("SELECT company FROM owners WHERE id = $t{p11s}[4]");
} else {
$t{owner} = 'X';
}
push(@{ $t{p12} },$t{owner});
# push(@{ $t{p12} },$t{p11s}[4]);
$t{p13} = join('/',@{ $t{p12} });
$price1{p1} .= '' . $t{p13} . ' ';
@members = ();
push @members, { %price1 };
$row_ref->{PRICE2} = [ @members ];
}
return($row_ref,$self,$pref);
}
mscparts10.htm
-----------------------------------------------------------------
搬家=>恢復(fù)
-----------------------------------------------------------------
取消=>恢復(fù)
">
">
-----------------------------------------------------------------
mscshowparts10.pl,show_price1/show_price2放在mscshowparts.pl里面
$$row_ref{NO_P1} = 'price1_' . $rec[0]; # PRICE1
$$row_ref{NO_P2} = 'price2_' . $rec[0]; # PRICE2
# $$pref{p1} = $rec[6];
# ($row_ref,$self,$pref) = show_price1($row_ref,$self,$pref);
# $$pref{p1} = $rec[7];
# ($row_ref,$self,$pref) = show_price2($row_ref,$self,$pref);
sub show_price1 {
my($row_ref,$self,$pref) = @_;
my(%t,@members,%price1);
$price1{p1} = '';
@{ $t{p1s} } = split(/==/,$$pref{p1});
for $n ( 0 .. $#{ $t{p1s} } ) {
$t{p11} = $t{p1s}[$n];
@{ $t{p11s} } = split(/=/,$t{p11});
@{ $t{p12} } = @{ $t{p11s} }[0..1];
$t{money1} = $self->dbh->selectrow_array("SELECT English FROM money WHERE id = $t{p11s}[2]");
push(@{ $t{p12} },$t{money1});
push(@{ $t{p12} },$t{p11s}[3]);
push(@{ $t{p12} },$t{p11s}[4]);
$t{maker1} = $self->dbh->selectrow_array("SELECT company FROM makers WHERE id = $t{p11s}[5]");
push(@{ $t{p12} },$t{maker1});
push(@{ $t{p12} },$t{p11s}[6]);
$t{p13} = join('/',@{ $t{p12} });
$price1{p1} .= '' . $t{p13} . ' ';
@members = ();
push @members, { %price1 };
$row_ref->{PRICE1} = [ @members ];
}
return($row_ref,$self,$pref);
}
sub show_price2 {
my($row_ref,$self,$pref) = @_;
my(%t,@members,%price1);
$price1{p1} = '';
@{ $t{p1s} } = split(/==/,$$pref{p1});
for $n ( 0 .. $#{ $t{p1s} } ) {
$t{p11} = $t{p1s}[$n];
@{ $t{p11s} } = split(/=/,$t{p11});
@{ $t{p12} } = @{ $t{p11s} }[0..1];
$t{money1} = $self->dbh->selectrow_array("SELECT English FROM money WHERE id = $t{p11s}[2]");
push(@{ $t{p12} },$t{money1});
push(@{ $t{p12} },$t{p11s}[3]);
$t{owner} = $self->dbh->selectrow_array("SELECT company FROM owners WHERE id = $t{p11s}[4]");
push(@{ $t{p12} },$t{owner});
$t{p13} = join('/',@{ $t{p12} });
$price1{p1} .= '' . $t{p13} . ' ';
@members = ();
push @members, { %price1 };
$row_ref->{PRICE2} = [ @members ];
}
return($row_ref,$self,$pref);
}
返回
双鸭山市 |
江阴市 |
鲁山县 |
富源县 |
汕尾市 |
云浮市 |
吉首市 |
扶绥县 |
汶川县 |
类乌齐县 |
汕尾市 |
霍山县 |
都昌县 |
磐安县 |
珲春市 |
芦山县 |
米易县 |
邵阳市 |
东宁县 |
广河县 |
山西省 |
宜良县 |
浮梁县 |
澄城县 |
枣庄市 |
甘谷县 |
和顺县 |
武城县 |
修文县 |
闵行区 |
高州市 |
博罗县 |
镇远县 |
河西区 |
鞍山市 |
进贤县 |
望都县 |
富裕县 |
仪征市 |
大厂 |
赫章县 |