Changeset 586


Ignore:
Timestamp:
Oct 4, 2007, 7:08:10 PM (12 years ago)
Author:
Nick Burch
Message:

Handle the database going away better

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/geocoder.fcgi

    r461 r586  
    141141                my ($easting,$northing,$matched,$pc);
    142142                my ($outward,$inward) = ($request{outward},$request{inward});
     143                sleep 5;
    143144
    144145                # Work out until we find a match
    145146                ($easting,$northing,$matched,$pc) = execute_ptl($full_matcher,$outward,$inward);
     147
     148                # Ensure the search worked, and the db isn't broken
     149                unless(defined $easting) {
     150                        warn("Search failed to execute, is the database server down?");
     151                        ($full_matcher,$postcode_matcher,$pc_area_matcher) = (undef,undef,undef);
     152                        print_internal_err('Error setting up database connection');
     153                        next REQUEST;
     154                }
     155
     156                # Keep looking for a match
    146157                unless($matched) {
    147158                        ($easting,$northing,$matched,$pc) =
     
    260271        my ($easting,$northing,$matched,$pc);
    261272
    262         $matcher->execute(@args);
     273        my $res = $matcher->execute(@args);
     274        # Should have got something back, unless it's broken
     275        unless(defined $res) {
     276                warn("Nothing received from execute, is the connection open?");
     277                return undef;
     278        }
     279
    263280        while( my @row = $matcher->fetchrow_array ) {
    264281                ($easting,$northing,$matched,$pc) = @row;
     
    275292        my @results;
    276293
    277         $matcher->execute(@args);
     294        my $res = $matcher->execute(@args);
     295        # Should have got something back, unless it's broken
     296        unless(defined $res) {
     297                warn("Nothing received from execute, is the connection open?");
     298                return undef;
     299        }
     300
    278301        while( my @row = $matcher->fetchrow_array ) {
    279302                my %res = (
Note: See TracChangeset for help on using the changeset viewer.