📄 insert_times.pl
字号:
#!/usr/bin/perl -w
use DBI;
my $DSN_tt; ##tt dsn
my $roll_file;
my %mobileno;
my $confile;
my $yy_tt;
my $zw_tt;
my $comm_tt;
sub Get_Parm
{
for(my $i = 0;$i < @ARGV; $i++)
{
if($ARGV[$i] eq "-c")
{
$confile = $ARGV[$i+1];
}
if($ARGV[$i] eq "-f")
{
$roll_file = $ARGV[$i+1];
}
}
}
sub Get_conf
{
open(CON,"$confile") || die"$!";
my @lines = <CON>;
for( my $i=0;$i<@lines;$i++)
{
if( $lines[$i] =~ m/\=/)
{
if( $lines[$i] =~ m/^DSN/)
{
$lines[$i] =~ s/ //g;
my @dsn_line = split /\=/,$lines[$i];
$DSN_tt = $dsn_line[1];
chomp $DSN_tt;
if( length($DSN_tt) <= 1)
{
die "\[ERROR\] timesten cs DSN not set","\n";
}
}
if( $lines[$i] =~ m/^BUSINESS/ )
{
$lines[$i] =~ s/ //g;
my @yy_line = split /\=/,$lines[$i];
$yy_tt = $yy_line[1];
chomp $yy_tt;
if( length($yy_tt) <= 1)
{
die "\[ERROR\] timesten BUSINESS table owner not set","\n";
}
}
if( $lines[$i] =~ m/^ACCOUNT/ )
{
$lines[$i] =~ s/ //g;
my @zw_line = split /\=/,$lines[$i];
$zw_tt = $zw_line[1];
chomp $zw_tt;
if( length($zw_tt) <= 1)
{
die "\[ERROR\] timesten ACCOUNT table owner not set","\n";
}
}
if( $lines[$i] =~ m/^COMMON/ )
{
$lines[$i] =~ s/ //g;
my @comm_line = split /\=/,$lines[$i];
$comm_tt = $comm_line[1];
chomp $comm_tt;
if( length($comm_tt) <= 1)
{
die "\[ERROR\] timesten COMMON table owner not set","\n";
}
}
}
else
{
next;
}
}
close(CON);
}
sub load_roll
{
open(ROLL,"$roll_file") || die"$!";
my @lines = <ROLL>;
for(my $i=0;$i<@lines;$i++)
{
my $mobileno_key = $lines[$i];
chomp $mobileno_key;
if( exists $mobileno{$mobileno_key})
{
print "\[WARN\] this $mobileno_key have more than twice","\n";
}
else
{
$mobileno{$mobileno_key} = 0;
}
}
close(ROLL);
}
sub main
{
if(@ARGV ne 4 || $ARGV[0] ne "-c" || $ARGV[2] ne "-f")
{
die "usage: perl $0 \{-c conf file -f roll mobileno filename\}\n";
}
&Get_Parm;
&Get_conf;
&load_roll;
my %db_attr = (
"RaiseError" => 1,
"PrintError" => 1,
"AutoCommit" => 0,
);
my $mydb = DBI->connect("DBI:TimesTen:DSN=$DSN_tt",undef,undef,\%db_attr) or die "Connect to TT error!\n";
$user = $mydb->prepare(qq{select acctid from $yy_tt.cm_subs_subscriber where servnumber = ? and status in ('US10','US30')});
$boxuser = $mydb->prepare(qq{select count(*) from $zw_tt.IB_CBA_EBOXUNITDET where eboxid = ? and EBOXUNITID = 1004});
$inserebox = $mydb->prepare(qq{insert into $zw_tt.IB_CBA_EBOXUNITDET values (?,1004,-1,0,sysdate,to_date('20991231','YYYYMMDD'),-10000, 0,0,0,sysdate)});
#开始执行
foreach $mobile ( keys %mobileno)
{
if( length($mobile) < 2)
{
next;
}
chomp $mobile;
print "\[INFO\] start deal $mobile ","\n";
$user->execute($mobile) || die $mydb->errstr ;
while(my @fetch1 = $user->fetchrow_array())
{
push @Eboxid,$fetch1[0] ;
}
my $count = NULL;
if( @Eboxid > 0)
{
for(my $i=0;$i<@Eboxid;$i++ )
{
print "\[INFO\] Eboxid $Eboxid[$i]","\n";
$boxuser->execute($Eboxid[$i]) || die $mydb->errstr;
while(my @fetch2 = $boxuser->fetchrow_array())
{
eval
{
$RowCnt = $fetch2[0];
};
if($@)
{
print "get count 1004 error!:$_\n";
}
}
if( $RowCnt == 0 )
{
print "\[INFO\] insert into $Eboxid[$i] 1004","\n";
$inserebox->execute($Eboxid[$i]) || die $mydb->errstr;
$mydb->commit;
}
elsif( $RowCnt > 0 )
{
print "\[INFO\] $Eboxid[$i] have 1004 eboxunitid ","\n";
}
}
@Eboxid = ();
}
}
$user->finish() ;
$boxuser->finish() ;
$inserebox->finish() ;
$mydb->disconnect() ;
}
&main;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -