Cover V08, I07
Article
Figure 1
Listing 1
Listing 2
Listing 3
Sidebar 1

jul99.tar


Listing 3: Retrieve information: a report

        #!/usr/bin/perl

        ;# Format the output.

        format REPORT = 
        WO #: @<<<<<     Requester: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
              $wo,                  $requester
        Opened: @<<<<<<< Technician: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
              $opened,               $assigned
        Affected system: @<<<<<<<<<<<<<<<<<<<
                         $system
        Problem Description:
                ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                $description
        ~       ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                $description
        ~       ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                $description

        .

        use DBI;
        $dbh = DBI->connect('dbi:Oracle:wodb', 'user', 'password')
                or die "Unable to connect to database: $DBI::errstr\n";

        $sth = $dbh->prepare(q{
             SELECT       Work_order.id, Work_order.system,
                          Work_order.date_opened, Work_order.description,
                          requester.first_name, requester.last_name,
                          tech.first_name, tech.last_name,
                          System.name
                 FROM     Work_order, System,
                          Person requester, Person tech
                WHERE     requester.id = Work_order.requester.id
                      AND tech.id = Work_order.assigned_id
                      AND System.id = Work_order.system_id
             ORDER BY     tech.id
        });

        $rv = $sth->execute || die $dbh->errstr;
        $oldhandle = select(REPORT);
        while (($wo,
                $system,
                $opened,
                $description,
                $req_first,
                $req_last,
                $tech_first,
                $tech_last,
                $system)  = $sth->fetchrow_array) ;# end WHILE condition
           {
              $requester = "$req_first $req_last";
              $assigned  = "$tech_first $tech_last";
              write;
           }                                      ;# end WHILE loop
        select($oldhandle);

<end listing 3>