Changeset 149


Ignore:
Timestamp:
Oct 24, 2006, 4:59:04 PM (13 years ago)
Author:
Nick Burch
Message:

Remaining modes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/scripts/exporter/export.pl

    r148 r149  
    9090############################################################################
    9191
     92# Get a query returning
     93#               outer, inner, easting, northing
     94# for the given mode
    9295sub getQuery($$) {
    9396        my ($mode,$conn) = @_;
    9497
    95         if($mode == "-gpsonly") {
    96                 my $source = getSource("FreeThePostcode.org Importer", $conn);
     98        if($mode eq "-gpsonly" || $mode eq "-npeonly") {
     99                my $source;
     100                if($mode eq "-gpsonly") {
     101                        $source = getSource("FreeThePostcode.org Importer", $conn);
     102                } else {
     103                        $source = getSource("NPE Postcode web submission", $conn);
     104                }
    97105
    98106                my $sql =
     
    106114                $sth->bind_param(1, $source);
    107115                return $sth;
    108         } elsif($mode == "-npeonly") {
    109                 my $source = getSource("NPE Postcode web submission", $conn);
    110         } elsif($mode == "-outer") {
    111         } elsif($mode == "-outer1") {
     116        } elsif($mode eq "-outer") {
     117                my $sql =
     118                        "SELECT outward, '###' AS inward, AVG(easting) AS avg_easting, AVG(northing) AS avg_northing ".
     119                        "FROM postcodes   ".
     120                        "GROUP BY outward ".
     121                        "ORDER BY outward ";
     122
     123                my $sth = $conn->prepare($sql);
     124                return $sth;
     125        } elsif($mode eq "-outer1") {
     126                my $sql =
     127                        "SELECT outward, substr(inward,1,1) || '##' AS inward, AVG(easting) AS avg_easting, AVG(northing) AS avg_northing ".
     128                        "FROM postcodes   ".
     129                        "GROUP BY outward, substr(inward,1,1) ".
     130                        "ORDER BY outward, inward";
     131
     132                my $sth = $conn->prepare($sql);
     133                return $sth;
    112134        } else {
    113135                die("Invalid mode '$mode'");
     
    123145
    124146        my $s = undef;
    125         while(my @row = $sth->fetchrow_array) {
    126                 if($s) {
    127                         die("Should only find one source with name '$source', got more than one!");
    128                 }
    129                 $s = $row[0];
     147        my @row = $sth->fetchrow_array;
     148        if($sth->fetchrow_array) {
     149                die("Should only find one source with name '$source', got more than one!");
    130150        }
    131         unless($s) {
     151
     152        unless(@row) {
    132153                die("Can't find id for source with name '$source'");
    133154        }
    134155
    135         return $s;     
     156        return $row[0];
    136157}
Note: See TracChangeset for help on using the changeset viewer.