From 62354f07c96ef0e0edc13c867447bbdbdbc2c1a5 Mon Sep 17 00:00:00 2001 From: Mark Chadwick Date: Sat, 23 Nov 2024 19:25:28 +1300 Subject: [PATCH] update --- meta/sqlite/station.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/meta/sqlite/station.go b/meta/sqlite/station.go index 283db142f..4136e77dd 100644 --- a/meta/sqlite/station.go +++ b/meta/sqlite/station.go @@ -18,7 +18,7 @@ var datum = Table{ return "SELECT datum_id FROM datum WHERE datum = ?" }, Insert: func() string { - return "INSERT OR IGNORE INTO datum (datum) VALUES (?);" + return "INSERT INTO datum (datum) VALUES (?) ON CONFLICT(datum) DO NOTHING;" }, Fields: []string{"Datum"}, } @@ -37,7 +37,7 @@ var method = Table{ return "SELECT method_id FROM method WHERE method = ?" }, Insert: func() string { - return "INSERT OR IGNORE INTO method (method) VALUES (?);" + return "INSERT INTO method (method) VALUES (?) ON CONFLICT(method) DO NOTHING;" }, Fields: []string{"Method"}, } @@ -59,7 +59,7 @@ var network = Table{ return "SELECT network_id FROM network WHERE network = ?" }, Insert: func() string { - return "INSERT OR IGNORE INTO network (network, external, description, restricted) VALUES (?, ?, ?, ?);" + return "INSERT INTO network (network, external, description, restricted) VALUES (?, ?, ?, ?);" }, Fields: []string{"Network", "External", "Description", "Restricted"}, } @@ -87,7 +87,7 @@ var station = Table{ return "SELECT station_id FROM station WHERE station = ?" }, Insert: func() string { - return fmt.Sprintf("INSERT OR IGNORE INTO station (datum_id, station, name, latitude, longitude, elevation, depth, start_date, end_date) VALUES ((%s), ?, ?, ?, ?, ?, ?, ?, ?);", datum.Select()) + return fmt.Sprintf("INSERT INTO station (datum_id, station, name, latitude, longitude, elevation, depth, start_date, end_date) VALUES ((%s), ?, ?, ?, ?, ?, ?, ?, ?);", datum.Select()) }, Fields: []string{"Datum", "Station", "Name", "Latitude", "Longitude", "Elevation", "Depth", "Start Date", "End Date"}, } @@ -110,6 +110,7 @@ var stationNetwork = Table{ station.Select(), network.Select()) }, Insert: func() string { + // not all networks are in the networks table so simply ignore any that fail return fmt.Sprintf("INSERT OR IGNORE INTO station_network (station_id, network_id) VALUES ((%s), (%s));", station.Select(), network.Select()) }, @@ -152,7 +153,7 @@ var site = Table{ return fmt.Sprintf("SELECT site_id FROM site WHERE station_id = (%s) AND location = ?", station.Select()) }, Insert: func() string { - return fmt.Sprintf("INSERT OR IGNORE INTO site (station_id, datum_id, location, latitude, longitude, elevation, depth, survey, start_date, end_date) VALUES ((%s), (%s), ?, ?, ?, ?, ?, ?, ?, ?);", + return fmt.Sprintf("INSERT INTO site (station_id, datum_id, location, latitude, longitude, elevation, depth, survey, start_date, end_date) VALUES ((%s), (%s), ?, ?, ?, ?, ?, ?, ?, ?);", station.Select(), datum.Select()) }, @@ -193,7 +194,7 @@ var sample = Table{ return "SELECT sample_id FROM sample WHERE station = ?" }, Insert: func() string { - return fmt.Sprintf("INSERT OR IGNORE INTO sample (datum_id, station, name, latitude, longitude, elevation, depth, start_date, end_date) VALUES ((%s), ?, ?, ?, ?, ?, ?, ?, ?);", + return fmt.Sprintf("INSERT INTO sample (datum_id, station, name, latitude, longitude, elevation, depth, start_date, end_date) VALUES ((%s), ?, ?, ?, ?, ?, ?, ?, ?);", datum.Select()) }, Fields: []string{"Datum", "Station", "Name", "Latitude", "Longitude", "Elevation", "Depth", "Start Date", "End Date"}, @@ -232,7 +233,7 @@ END; var point = Table{ Create: pointCreate, Insert: func() string { - return fmt.Sprintf("INSERT OR IGNORE INTO point (sample_id, datum_id, location, latitude, longitude, elevation, depth, survey, start_date, end_date) VALUES ((%s), (%s), ?, ?, ?, ?, ?, ?, ?, ?);", + return fmt.Sprintf("INSERT INTO point (sample_id, datum_id, location, latitude, longitude, elevation, depth, survey, start_date, end_date) VALUES ((%s), (%s), ?, ?, ?, ?, ?, ?, ?, ?);", sample.Select(), datum.Select()) }, Fields: []string{"Point", "Datum", "Location", "Latitude", "Longitude", "Elevation", "Depth", "Survey", "Start Date", "End Date"}, @@ -271,6 +272,7 @@ END; var feature = Table{ Create: featureCreate, Insert: func() string { + // currently a feature could reference a site or a point or a sample, solution is consolidation. return fmt.Sprintf("INSERT OR IGNORE INTO feature (site_id, sublocation, property, description, aspect, start_date, end_date) VALUES ((%s), ?, ?, ?, ?, ?, ?);", site.Select()) }, @@ -303,6 +305,7 @@ var class = Table{ return fmt.Sprintf("SELECT class_id FROM class WHERE station_id = (%s)", station.Select()) }, Insert: func() string { + // not all stations are in the stations file, ignore any conflicts for now return fmt.Sprintf("INSERT OR IGNORE INTO class (station_id, site_class, vs30, vs30_quality, tsite, tsite_method, tsite_quality, basement_depth, depth_quality, link, notes) VALUES ((%s), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", station.Select()) }, Fields: []string{"Station", "Site Class", "Vs30", "Vs30 Quality", "Tsite", "Tsite Method", "Tsite Quality", "Basement Depth", "Depth Quality", "Link", "Notes"},