⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbis.pm

📁 Perl开发的数据采集工具 基于UNIX
💻 PM
📖 第 1 页 / 共 5 页
字号:
    $tfmt =~ s/[D]+/\\d\+/;    $tfmt =~ s/[h]+/\\d\+/;    $tfmt =~ s/[m]+/\(\\d\+\)/;    $tfmt =~ s/[s]+/\\d\+/;        if($ftime =~ /$tfmt/)    {    	$smin = $1;    	if (!$smin)     	{    		$smin = '00';    	}    	elsif(length($smin) == 1)    	{    		$smin = '0'.$smin;    	}    	if(length($smin) != 2)    	{    		$smin = '00';    	}    }    $tfmt = $tformat;    $tfmt =~ s/[Y]+/\\d\+/;    $tfmt =~ s/[M]+/\\d\+/;    $tfmt =~ s/[D]+/\\d\+/;    $tfmt =~ s/[h]+/\\d\+/;    $tfmt =~ s/[m]+/\\d\+/;    $tfmt =~ s/[s]+/\(\\d\+\)/;        if($ftime =~ /$tfmt/)    {    	$ssec = $1;    	if (!$ssec)     	{    		$ssec = '00';    	}    	elsif(length($ssec) == 1)    	{    		$ssec = '0'.$ssec;    	}    	if(length($ssec) != 2)    	{    		$ssec = '00';    	}    }    $ftime = $syear."-".$smon."-".$sday." ".$shour.":".$smin.":".$ssec;    return $ftime;}############################################################### Function: 	CFtime# Description: 	Formation current time# Input:#     1.Format	-- "YYYY-MM-DD hh:mm:ss"#     2.TIME	-- CURRENT(NULL) or "YYYY-MM-DD hh:mm:ss"# Output: 	Null# Return: 	Format Time##############################################################sub CFtime{    my (@ctime,$tformat,$result,$ftime,$pattern,$num,$substr_time);    $tformat 	= shift;    $ftime 	= shift;    $pattern = "[-:. ]";       if ($ftime eq "CURRENT" or $ftime eq "current" or $ftime eq "")    {    	@ctime = localtime;    	$ctime[5] += 1900;    	$ctime[4] += 1;    }    else    {    	@ctime = split(/$pattern/,$ftime);	if ($ctime[0] !~ /^\d+$/)    		{		$ctime[0] = 1970;	}	if ($ctime[1] !~ /^\d+$/)    		{		$ctime[1] = 1;	}	if ($ctime[2] !~ /^\d+$/)    		{		$ctime[2] = 1;	}	if ($ctime[3] !~ /^\d+$/)    		{		$ctime[3] = 1;	}	if ($ctime[4] !~ /^\d+$/)    		{		$ctime[4] = 0;	}	if ($ctime[5] !~ /^\d+$/)    		{		$ctime[5] = 0;	}	my $i;  	for ($i=0;$i<3;$i++)  	{        	$num = $ctime[5 - $i];        	$ctime[5 - $i] = $ctime[$i];        	$ctime[$i] = $num;	}    }   my $i;						    for ($i=0;$i<5;$i++) {        if ($ctime[$i] < 10 and length($ctime[$i]) == 1) {	    $ctime[$i] = "0" . $ctime[$i];	}    }        $tformat =~ s/YYYY/$ctime[5]/g;    $substr_time = substr($ctime[5],1,3);    $tformat =~ s/YYY/$substr_time/g;    $substr_time = substr($ctime[5],2,2);        $tformat =~ s/YY/$substr_time/g;    $substr_time = substr($ctime[5],3,1);        $tformat =~ s/Y/$substr_time/g;      $tformat =~ s/MM/$ctime[4]/g;    $substr_time = substr($ctime[4],1,1);         $tformat =~ s/M/$substr_time/g;    $tformat =~ s/DD/$ctime[3]/g;    $substr_time = substr($ctime[3],1,1);         $tformat =~ s/D/$substr_time/g;    $tformat =~ s/hh/$ctime[2]/g;    $substr_time = substr($ctime[2],1,1);         $tformat =~ s/h/$substr_time/g;        $tformat =~ s/mm/$ctime[1]/g;    $substr_time = substr($ctime[1],1,1);        $tformat =~ s/m/$substr_time/g;    $tformat =~ s/ss/$ctime[0]/g;    $substr_time = substr($ctime[0],1,1);        $tformat =~ s/s/$substr_time/g;    $tformat =~ s/f/0/g;                     return $tformat;}############################################################### Function: 	Set_Trace_Modes# Description: 	Set TraceModes# Input:#     1.string  --SRC|LOG|REP# Output: 	Null# Return: 	Null##############################################################sub Set_Trace_Modes {	$TraceModes = @_[0];}    ############################################################### Function: 	Get_Trace_Filename# Description: 	Get $TraceFileName# Input:#     # Output: 	$TraceFileName# Return: 	Null##############################################################sub Get_Trace_Filename {	return $TraceFileName;}    ############################################################### Function: 	Set_Mpl_Version# Description: 	Set_Mpl_Version# Input:## Output: 	Null# Return: 	Null##############################################################sub Set_Mpl_Version{	$MPL_VERSION = @_[0];	my $map_ver = @_[1];	Trim($map_ver);	if ($map_ver)	{		$MAP_VERSION = $map_ver;	}}############################################################### Function: 	Init_Trace# Description: 	Initiates trace information including # Input:#     1.Trace Module#     2.Trace Dir	  -- first with "/" absoluteness dir else relatively#     3.argv ref positin# Output: 	Null# Return: 	Null##############################################################sub Init_Trace {    my ($trace_mod,$trace_dir,$argv_ref) = @_;    my (@trace_subdir,$sub_dir,$fetchdir,$tracetime,$filetime);    my $PROG_NAME = $0.' '.$argv_ref;    $TraceModes = "LOG|SRC";	    if ($trace_dir !~ /\/$/){	$trace_dir .= "/";    }    if ($trace_dir !~ /^\//){	$trace_dir = "$DAL_HOME/NPM/trace/$trace_dir";    }    if (-e $trace_dir && -d $trace_dir)    {	unless (-w $trace_dir)	{	    print "Err: Write trace failed because of $^E\n";	    NPM_Send_Message(203);	    NPM_Write_DalLog(ERROR_MESSAGE=>"Err: Write trace failed because of $^E");	    exit 0;	}    }    else    {	@trace_subdir = split (/\//,$trace_dir);	foreach $sub_dir (@trace_subdir)	{	    if ($sub_dir)	    {	        $fetchdir = $fetchdir."/".$sub_dir;	    	if (!-e $fetchdir)	    	{	    	    my $result;		    unless ($result = mkdir($fetchdir,0755))		    {	    		print "Err: Create trace directory --$fetchdir failed because of $^E\n";        		NPM_Send_Message(204);	    	        NPM_Write_DalLog(ERROR_MESSAGE=>"Err: Create trace directory --$fetchdir failed because of $^E");	    		exit 0;        	    }		}	    }	}   	    }    $tracetime = CFtime("YYYY-MM-DD hh:mm:ss");    $filetime = CFtime("YYYYMMDDhhmmss");         $TraceFileName = $trace_dir."$trace_mod.$filetime.log";#    $RepFileName = $trace_dir."$trace_mod.$filetime.report";    $RepFileName = "/dev/null";    $Data_Load_TmpDir = $trace_dir.$filetime;    open (OUTPUT, ">>$TraceFileName");    select((select(OUTPUT), $| = 1)[0]);    open (REPORT, ">>$RepFileName");    select((select(REPORT), $| = 1)[0]);    my $init_inf =<<EOF;=================================================Command:\t$0Input:\t\t$argv_refExecute Time:\t$tracetimeProcess ID:\t$$User ID:\t$<DBIs VERSION:\t$DBIs_VERSIONmPerl VERSION:\t$MPL_VERSIONMapping VERSION:$MAP_VERSION=================================================REPORT:EOF    print REPORT $init_inf;    if ($WriteOlog)    {    	my $task_id;	if ($argv_ref =~ /-j\s+(\w+)\s*/)	{		$task_id = $1;	}	$DMMMT_DCMSG_TASK_ID = $task_id if(defined($task_id));	$DMMMT_DCMSG_INSTANCE_RDN = 'DATA_ASM:'.$argv_ref;	Write_OlogDB();	    }    if ($MsgSend)    {	my $msg = FmtMsg($init_inf);	MQSend($msg);    }        return $TraceFileName;}############################################################################ Function: Trace# Description: It writes the trace   # Input:#     1.  Trace String#     2.  WithTime# Output: Null# Return: Null###########################################################################sub Trace{	my ($withtime,$wtrace,$datetime,$strace,$tracefile,$datetime,$line,$lines,$output,$len,$withtime);	$strace = shift;	$withtime = shift;	$wtrace = $TraceModes;	$datetime = CFtime("YYYY-MM-DD hh:mm:ss");	my @lines = split(/\n/, $strace);	foreach $line (@lines) 	{		if (length($line) > 70 )		{			$len = 0;			while ($len < length($line))			{				$output .= "\t".substr($line,$len,70)."\n";				$len += 70;			}		}		else 		{			$output .= "\t".$line."\n";		}	}	if ($withtime == 1 or $withtime eq "")	{		$output = "\n".$datetime.":\n--------------------\n".$output;	}	if ($wtrace =~/SRC/i)	{		print $output;	}	if ($wtrace =~/LOG/i)	{		print OUTPUT $output;	}	if ($wtrace =~/REP/i)	{		print REPORT $output;		if ($MsgSend)		{			my $msg = FmtMsg($output);			MQSend($msg);		}	}		#	$~ = "PRINTFORMAT";#format PRINTFORMAT =##@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<#$datetime#-------------------------#~~  ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<#$strace#.	}############################################################################ Function: End_Trace# Description: the trace end# Input:  Null# Output: Null# Return: Null###########################################################################sub End_Trace {	my $datetime = CFtime("YYYY-MM-DD hh:mm:ss");#	print REPORT "\n******************************************";	#	print REPORT "\nExecute End Time:\t$datetime";#	print REPORT "\n******************************************";	    my $init_inf =<<EOF;******************************************	Execute End Time:\t$datetime******************************************EOF    	print REPORT $init_inf;	if ($WriteOlog)	{		Write_OlogDB(1);	}	if ($MsgSend)	{		my $msg = FmtMsg($init_inf);		MQSend($msg);	} 			close (OUTPUT);	close (REPORT);}############################################################################ Function: Connect_DB# Description: Connect Database# Input:  #	1.dbh pointer#	2.auto commit flag# Output: Null# Return: Null###########################################################################sub Connect_DB{	my ($subdbh,$auotcommit);	$subdbh = shift;	$auotcommit = shift;		if (!$auotcommit)	{		$auotcommit = 0;		}		my ($sub_dbd,$sub_dbn,$sub_uid,$sub_pwd,$sub_mark)=Get_DBMS();		if(!$sub_dbn or !$sub_dbd)	{		Trace("Err:Please Set_DBMS\($sub_mark\)\n\tCONN_DBD\t=\t$sub_dbd\n\tCONN_DBN\t=\t$sub_dbn\n\tCONN_UID\t=\t$sub_uid\n\tCONN_PWD\t=\t*****");		NPM_Send_Message(201);		NPM_Write_DalLog(ERROR_MESSAGE=>"Err: Incorrect db_type or db_name in LDAP");		exit 0;	}	Trace("Connecting Database DBI:$sub_dbd:$sub_dbn $sub_uid/*****\n");		if ($DeBug)	{		Trace("***Programming Debug!! return!!!\n");		return 0;	} 	if($$subdbh=DBI->connect("DBI:$sub_dbd:$sub_dbn",$sub_uid,$sub_pwd,	{RaiseError => 0,PrintError => 0, AutoCommit => $auotcommit }))	{		Trace("Connect Database DBI:$sub_dbd:$sub_dbn success!\n");		return 1;	}	else	{		Trace("Err:Connect Database DBI:$sub_dbd:$sub_dbn error!\nErr Info:$DBI::errstr\n");		NPM_Send_Message(202);		NPM_Write_DalLog(ERROR_MESSAGE=>"$DBI::errstr");		Write_Dchk_Err("Err:Connect Database DBI:$sub_dbd:$sub_dbn error!\nErr Info:$DBI::errstr\n") if $PM_DCHK;		exit 0;		return 0;	}}############################################################################ Function: Disonnect_DB# Description: Disonnect Database# Input:  #	1.dbh pointer# Output: Null# Return: Null###########################################################################sub Disonnect_DB{   my ($rc,$subdbh);      $subdbh = shift;   if ($DeBug)   {   	Trace("Disconnect Database!\n");   	Trace("***Programming Debug!! return!!!\n");   	return 0;   }   $rc = $$subdbh->disconnect;   if($rc)   {	Trace("Disconnect Database!\n");	return 1;   }   else   { 	Trace("Err:Disconnect Database error!\nErr Info:$DBI::errstr\n");	return 0;   }}############################################################################ Function: Commit_DB# Description: Commit Database# Input:  #	1.dbh pointer# Output: Null# Return: Null###########################################################################sub Commit_DB{   my ($rc,$subdbh);      $subdbh = shift;   if ($DeBug)   {   	Trace("Commited Transecation To Database!\n");   	Trace("***Programming Debug!! return!!!\n");   	return 0;   }        $rc = $$subdbh->commit;   if($rc)   {	Trace("Commited Transecation To Database!\n");	return 1;   }   else   {	Trace("Err:Commited Transecation To Database Error!\nErr Info:$DBI::errstr\n");	return 0;   }}############################################################################ Function: Rollback_DB# Description: Rollback_DB# Input:  #	1.dbh pointer# Output: Null# Return: Null###########################################################################sub Rollback_DB{   my ($rc,$subdbh);      $subdbh = shift;   if ($DeBug)   {   	Trace("Rollbacked Transecation From Database !\n");   	Trace("***Programming Debug!! return!!!\n");   	return 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -