2
sub loadFileRecon {
    my $self = shift;
    my $days = shift;
    if($days eq '') {
        $days = 1;
    }
    my $insert = $self->{rba}->rbdb->prepare(q{
        insert into rba.filerecon (
            filename,
            records,
            start_dtm,
            file_type,
            managed_file_id,
            mf_dtm,
            processed_tidemark,
            mm_records,
            mm_dropped,
            mm_erred,
            mm_duplicate,
            file_source
        )
        select
            i.filename,
            i.records,
            i.file_dtm start_dtm,
            i.file_type,
            mf.managed_file_id,
            mf.created_dtm mf_dtm,
            NULL,
            i.orig_records,
            i.dropped,
            i.erred,
            i.duplicate,
            i.file_source
        from rba.mmfilestats i, managedfile mf, filelog fl
        where
            i.filename = fl.file_name and
            trunc(i.file_dtm) = trunc(sysdate - ?) and
            mf.managed_file_id = fl.managed_file_id
    }) or die $DBI::errstr;
    $insert->execute($days);
    $insert->finish;
    $self->{rba}->rbdb->commit;
    my $update = $self->{rba}->rbdb->prepare(q{
        update rba.filerecon fr
        set processed_tidemark = (
            select processed_tidemark
            from jobhasfile j
            where j.managed_file_id = fr.managed_file_id
        )
        where
            trunc(start_dtm) = trunc(sysdate - ?) and
            processed_tidemark is null
    });
    $update->execute($days);
    $insert->finish;
    $self->{rba}->rbdb->commit;
}

如果上面的准备语句由于表或视图不存在而失败,那么它应该向 perl 模块返回一个值

4

3 回答 3

1

如果prepare返回错误,您正在告诉您的程序死亡:

   }) or die $DBI::errstr;

将其替换为您要查找的内容:

   }) or return $somevalue;

或完全删除or并检查您的语句句柄的值;

   my $insert = $self->{rba}->rbdb->prepare(q{       
      ...
   });
   return $somevalue if ( !$insert ); 
于 2012-12-15T15:54:52.927 回答
0

您需要做的是返回 DBI::errstr。不要死于错误。所以做这样的事情(从你的准备开始,到你的位置结束,但摆脱“或死”):

    ...prepare( ......

    where
        i.filename = fl.file_name and
        trunc(i.file_dtm) = trunc(sysdate - ?) and
        mf.managed_file_id = fl.managed_file_id
    });

    if ($DBI::errstr) {
        # oops something is wrong
        print $DBI::errstr;
        call_error($DBI::errstr);
    }

祝你好运

于 2012-12-18T11:42:23.807 回答
0

您发布的错误日志显示您的错误是在执行点而不是在准备点引发的。所以这就是你在执行后所做的:

    #your execute statement first
    $insert->execute($days);
    #Now the check on the execute
    if ($DBI::errstr) {
       # oops something is wrong
       return -1;
    }

请让我知道这是否有效

于 2012-12-23T10:40:00.787 回答