How do I trap DBI errors?

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default How do I trap DBI errors?

    Good day all,

    I have a program that receives files from another machine and then must
    update an audit trail to show bytes received, date and time of receipt
    etc etc... The audit trail is updated as the file moves through my
    system so that I can always determine if I received a file and how and
    when I disposed of it.

    One of the requirements, of course, is that if the program cannot
    connect to or cannot update the audit trail table then the program
    should generate an error condition and not accept the file that is
    being sent.

    Below is some of the code from the program, an in particular the
    subroutine that updates the audit trail. I have established that as
    things currently stand it is possible for my system to receive a file
    even though the audit trail cannot be updated. The receiving program
    connects to the database for each receipt, so it SHOULD be constantly
    checking if it can connect to the audit trail and if it can write.
    Unfortunately it is NOT detecting situations where it can't connect to
    the database (EG when the table is corrupted).

    First the actual call to the subroutine and the checking of the
    results....

    my @results = updateAuditTrail($valString);
    # could we update the audit trail?
    if($results[0] == 0)
    {
    # audit trail was updated...
    $trackNo = $results[2];

    # check whether to queue for transmission or
    transformation
    my $auditValue = "";
    if($transformSet){
    # insert the data into the WaitingTransforms table,

    # the ID in the audit table will be returned
    $auditValue =
    insertWaitingTransforms("File=>$filePath", "Rule=>$fileType");
    }
    else
    {
    # insert the data into the WaitingSends and
    SendDetails tables,
    # the ID in the audit table will be returned
    $auditValue = insertWaitingSends("File=>$filePath",
    "Rule=>$fileType");
    }
    # check if the insert operation failed...
    $auditValue =~ s/.+\(AuditEntry: ([0-9]+)\)/$1/;
    # remaining message should now be numeric
    (Audittrail.audit ID)
    # if the insert succeeded.
    unless($auditValue =~ /^\d+$/)
    {
    $errorStatus += 512;
    $whatHappened = "Error from QueuesDatabase.pm!
    ($auditValue)";
    }
    }
    else
    {
    # there was an error when we tried to update the audit
    trail
    $errorStatus += $results[0];
    $whatHappened = "$results[1] File not uploaded\!";
    }
    # if no error, report the tracking number, else delete the
    uploaded file...
    unless($errorStatus)
    {
    print "NCMtrack: $trackNo\n";
    }
    else
    {
    unlink $filePath;
    }

    Then actual routine that updates the audit trail.

    sub updateAuditTrail
    {
    my $stringToInsert = shift;

    # initialise return values
    my $ref = '';
    my $errorCode = '';
    my $errorMsg = '';

    # now update the audit trail
    # connect to the Database...
    if(my $audit =
    DBI->connect('DBI:mysql:Audittrail','transformer','peb cak'))
    {
    my $fieldsString =
    '(INPUT_FILENAME,OUTPUT_FILENAME,DATE_TIME,ORIGIN, PROCESS_NAME,TYPE,STATUS,MESSAGE,TFR_START,TFR_END ,BYTES)';

    # create the SQL command
    my $cmdString = 'INSERT INTO audit '.$fieldsString.' values
    '.$stringToInsert;

    # perform the query...
    my $cmd = $audit->prepare($cmdString);
    $cmd->execute;

    # now get the value of the auto increment field for the row we
    have just inserted
    $ref = $audit->{mysql_insertid};

    # if the write to the audit table was unsuccessful, returnand
    error message
    unless ($ref)
    {
    $errorCode = 512;
    $errorMsg = "Cannot write to the audit table in the Audit
    Trail database.";
    }

    # disconnect from the db
    $audit->disconnect;
    }
    else
    {
    $errorCode = 512;
    $errorMsg = "Cannot connect to the Audit Trail database.";
    }
    return($errorCode,$errorMsg,$ref);
    }

    megapode@gmail.com Guest

  2. Similar Questions and Discussions

    1. Knockout and trap
      When I create a graphic in Illustrator 10.3(Win) I can't seem to get the graphic to knockout or trap. I have try flattening it but I still have no...
    2. Trap Knocks Out
      Hi all. On AI CS for PC, I create a trap using the trap command on artwork with two pms colors. Everything looks great on the screen. The top...
    3. how does one trap for out-of-memory errors?
      I'm not sure how this is normally done, on a large site, perhaps one running Phorum. Occassionally a thread will have hundreds of entries, perhaps...
    4. Trap "connection pool" errors
      We have implemented unhandled error trapping at the application level and log these errors to our database. One error, however, the does not get...
    5. using SNMP to send a trap
      mike_stephanos@yahoo.com (mike_stephanos@yahoo.com) writes: The program you are running--have you tried running it as root? I'm far from a...
  3. #2

    Default Re: How do I trap DBI errors?


    [email]megapode@gmail.com[/email] wrote:
    > One of the requirements, of course, is that if the program cannot
    > connect to or cannot update the audit trail table then the program
    > should generate an error condition and not accept the file that is
    > being sent.
    snip!

    And thanks for the off-list reply. It seems that checking $DBI::errstr
    does the trick.

    megapode@gmail.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139