Changeset 197


Ignore:
Timestamp:
Oct 26, 2006, 10:43:45 PM (13 years ago)
Author:
Nick Burch
Message:

Finish script, seems to work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/get-distant-postcodes.fcgi

    r196 r197  
    6060        }
    6161
    62         # Tidy up from another run
     62        # Tidy up from another run, if required
    6363        my $checksql = "SELECT tablename FROM pg_tables WHERE tablename = 'averages'";
    64         my $check = $dbh->prepare($checksql);
    65         $check->execute;
    66         if($check->fetchrow_array) {
    67                 $dbh->do("DROP TABLE averages");
     64        my @has_table = $dbh->selectrow_array($checksql);
     65        if(@has_table) {
     66                $dbh->do("DROP TABLE averages;");
    6867        }
    6968
    7069        # Get our sql
    7170        # First calculate the average
    72         my $prepsql = "CREATE TABLE averages (pcpart VARCHAR(10),avg_easting INTEGER, avg_northing INTEGER);";
    73         $prepsql .= "SELECT $pcpart AS pcpart, AVG(easting) AS avg_easting, AVG(northing) AS avg_northing INTO averages FROM postcodes GROUP BY $pcgroup ";
     71        my $prepsql .= "SELECT $pcpart AS pcpart, AVG(easting) AS avg_easting, AVG(northing) AS avg_northing INTO TEMP TABLE averages FROM postcodes GROUP BY $pcgroup ";
    7472
    7573        # Then join to find problem ones
     
    8583        # Do the query
    8684    my $sth = $dbh->prepare($sql);
    87         print $sql."\n";
    88    
    8985    if ($sth->execute()) {
    9086        print "Content-type: text/javascript\n\n";
     
    10399
    104100        # Tidy up
    105         $check->execute;
    106         if($check->fetchrow_array) {
     101        @has_table = $dbh->selectrow_array($checksql);
     102        if(@has_table) {
    107103                $dbh->do("DROP TABLE averages");
    108104        }
Note: See TracChangeset for help on using the changeset viewer.