Changeset 149 for trunk/npemap.org.uk/scripts/exporter/export.pl
- Timestamp:
- Oct 24, 2006, 4:59:04 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/npemap.org.uk/scripts/exporter/export.pl
r148 r149 90 90 ############################################################################ 91 91 92 # Get a query returning 93 # outer, inner, easting, northing 94 # for the given mode 92 95 sub getQuery($$) { 93 96 my ($mode,$conn) = @_; 94 97 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 } 97 105 98 106 my $sql = … … 106 114 $sth->bind_param(1, $source); 107 115 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; 112 134 } else { 113 135 die("Invalid mode '$mode'"); … … 123 145 124 146 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!"); 130 150 } 131 unless($s) { 151 152 unless(@row) { 132 153 die("Can't find id for source with name '$source'"); 133 154 } 134 155 135 return $ s;156 return $row[0]; 136 157 }
Note: See TracChangeset
for help on using the changeset viewer.