Mercurial > gemma
changeset 2183:b27edd1f2353
Waterway profiles import: Issue warnings for lines in CSV file which ISRS codes which are not in the virtual distance marks.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 11 Feb 2019 16:16:35 +0100 |
parents | 7ae0b6be0203 |
children | 826fc7309370 |
files | pkg/imports/wp.go |
diffstat | 1 files changed, 31 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/imports/wp.go Mon Feb 11 15:57:20 2019 +0100 +++ b/pkg/imports/wp.go Mon Feb 11 16:16:35 2019 +0100 @@ -96,6 +96,11 @@ INSERT INTO wp_geoms (geom) VALUES ( ST_Transform(ST_GeomFromWKB($1, $2::int), 4326) )` + hasDistanceMarkSQL = ` +SELECT true FROM waterway.distance_marks_virtual +WHERE location_code = + ($1::char(2), $2::char(3), $3::char(5), $4::char(5), $5::int) +LIMIT 1` insertWaterwayProfileSQL = ` INSERT INTO waterway.waterway_profiles ( @@ -430,6 +435,12 @@ } defer trackStmt.Close() + hasDistanceMarkStmt, err := tx.PrepareContext(ctx, hasDistanceMarkSQL) + if err != nil { + return nil, err + } + defer hasDistanceMarkStmt.Close() + var ids []int64 lines: @@ -450,6 +461,26 @@ line, err) } + var dummy bool + err = hasDistanceMarkStmt.QueryRowContext( + ctx, + location.CountryCode, + location.LoCode, + location.FairwaySection, + location.Orc, + location.Hectometre, + ).Scan(&dummy) + + switch { + case err == sql.ErrNoRows: + feedback.Warn("No virtual distance mark found for %s.", location) + continue lines + case err != nil: + return nil, err + case !dummy: + return nil, errors.New("unexpected result form database") + } + validFromTime, err := parseDate(row[validFromIdx]) if err != nil { return nil, fmt.Errorf(