Mercurial > gemma
annotate cmd/bottlenecks/main.go @ 1259:f80d1fd54806
removed duplicated css
and added comment
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Wed, 21 Nov 2018 12:44:04 +0100 |
parents | a244b18cb916 |
children |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
591
diff
changeset
|
13 |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package main |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
17 "database/sql" |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "flag" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "fmt" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "log" |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
21 "regexp" |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
22 "strconv" |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
23 "strings" |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
24 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
25 "github.com/jackc/pgx" |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
26 "github.com/jackc/pgx/stdlib" |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 "gemma.intevation.de/gemma/pkg/soap/ifbn" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 ) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
31 const insertSQL = `INSERT INTO waterway.bottlenecks ( |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
32 bottleneck_id, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
33 fk_g_fid, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
34 objnam, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
35 nobjnm, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
36 stretch, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
37 area, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
38 rb, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
39 lb, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
40 responsible_country, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
41 revisiting_time, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
42 limiting, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
43 date_info, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
44 source_organization |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
45 ) VALUES( |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
46 $1, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
47 isrs_fromText($2), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
48 $3, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
49 $4, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
50 isrsrange(isrs_fromText($5), isrs_fromText($6)), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
51 ST_MakePolygon(ST_ExteriorRing(ST_Buffer(ST_SetSRID(ST_Makepoint(13.05501, 47.80949), 4326), 0.01)))::Geography, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
52 $7, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
53 $8, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
54 $9, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
55 $10, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
56 $11, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
57 $12, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
58 $13 |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
59 ) ON CONFLICT (bottleneck_id) DO NOTHING` |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
60 |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
61 const insertDumpSQL = `INSERT INTO waterway.bottlenecks ( |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
62 bottleneck_id, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
63 fk_g_fid, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
64 objnam, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
65 nobjnm, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
66 stretch, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
67 area, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
68 rb, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
69 lb, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
70 responsible_country, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
71 revisiting_time, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
72 limiting, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
73 date_info, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
74 source_organization |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
75 ) VALUES( |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
76 %s, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
77 isrs_fromText(%s), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
78 %s, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
79 %s, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
80 isrsrange(isrs_fromText(%s), isrs_fromText(%s)), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
81 ST_MakePolygon(ST_ExteriorRing(ST_Buffer(ST_SetSRID(ST_Makepoint(13.05501, 47.80949), 4326), 0.01)))::Geography, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
82 %s, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
83 %s, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
84 %s, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
85 %d, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
86 %s, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
87 %s::timestamp with time zone, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
88 %s |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
89 ) ON CONFLICT (bottleneck_id) DO NOTHING; |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
90 ` |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
91 |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
92 var ( |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
93 url = flag.String("url", "", "the IFBN service") |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
94 dump = flag.Bool("dump", false, "dump SQL insert statements") |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
95 |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
96 insecure = flag.Bool("insecure", false, "skip SSL verification") |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
97 dbhost = flag.String("dbhost", "localhost", "database host") |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
98 dbport = flag.Uint("dbport", 5432, "database port") |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
99 dbname = flag.String("dbname", "gemma", "database user") |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
100 dbuser = flag.String("dbuser", "scott", "database user") |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
101 dbpassword = flag.String("dbpw", "tiger", "database password") |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
102 dbssl = flag.String("dbssl", "prefer", "database SSL mode") |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
103 ) |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
105 func run(fn func(*sql.DB) error) error { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
106 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
107 // To ease SSL config ride a bit on parsing. |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
108 cc, err := pgx.ParseConnectionString("sslmode=" + *dbssl) |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
109 if err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
110 return err |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
111 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
112 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
113 // Do the rest manually to allow whitespace in user/password. |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
114 cc.Host = *dbhost |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
115 cc.Port = uint16(*dbport) |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
116 cc.User = *dbuser |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
117 cc.Password = *dbpassword |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
118 cc.Database = *dbname |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
119 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
120 db := stdlib.OpenDB(cc) |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
121 defer db.Close() |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
122 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
123 return fn(db) |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
124 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
125 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
126 var rblbRe = regexp.MustCompile(`(..)_(..)`) |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
127 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
128 func splitRBLB(s string) (string, string) { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
129 m := rblbRe.FindStringSubmatch(s) |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
130 if len(m) == 0 { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
131 return "", "" |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
132 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
133 return m[1], m[2] |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
134 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
135 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
136 func revisitingTime(s string) int { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
137 v, err := strconv.Atoi(s) |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
138 if err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
139 v = 0 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
140 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
141 return v |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
142 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
143 |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
144 func quote(s string) string { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
145 return "'" + strings.Replace(s, "'", "'''", -1) + "'" |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
146 } |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
148 func dumpSQLStatements(bns []*ifbn.BottleNeckType) error { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
149 |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
150 fmt.Println("BEGIN;") |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
152 for i := range bns { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
153 bn := bns[i] |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
154 rb, lb := splitRBLB(bn.Rb_lb) |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
155 |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
156 var limiting, country string |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
158 if bn.Limiting_factor != nil { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
159 limiting = string(*bn.Limiting_factor) |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
160 } |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
161 |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
162 if bn.Responsible_country != nil { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
163 country = string(*bn.Responsible_country) |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
164 } |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
166 if _, err := fmt.Printf(insertDumpSQL, |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
167 quote(bn.Bottleneck_id), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
168 quote(bn.Fk_g_fid), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
169 quote(bn.OBJNAM), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
170 quote(bn.NOBJNM), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
171 quote(bn.From_ISRS), quote(bn.To_ISRS), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
172 quote(rb), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
173 quote(lb), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
174 quote(country), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
175 revisitingTime(bn.Revisiting_time), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
176 quote(limiting), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
177 quote(bn.Date_Info.Format("2006-01-02 15:04:05.999 MST")), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
178 quote(bn.Source), |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
179 ); err != nil { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
180 return err |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
181 } |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 } |
591
d013fa5554cc
bottlenecks: Even if END is a synonym for COMMIT in PostgreSQL use COMMIT instead.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
589
diff
changeset
|
183 _, err := fmt.Println("COMMIT;") |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
184 return err |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
185 } |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
187 func storeInDatabase(bns []*ifbn.BottleNeckType) error { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
188 return run(func(db *sql.DB) error { |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
189 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
190 stmt, err := db.Prepare(insertSQL) |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
191 if err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
192 return err |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
193 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
194 defer stmt.Close() |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
195 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
196 tx, err := db.Begin() |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
197 if err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
198 return err |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
199 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
200 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
201 st := tx.Stmt(stmt) |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
202 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
203 for i := range bns { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
204 bn := bns[i] |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
205 rb, lb := splitRBLB(bn.Rb_lb) |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
206 |
575
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
207 var limiting, country string |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
208 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
209 if bn.Limiting_factor != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
210 limiting = string(*bn.Limiting_factor) |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
211 } |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 |
575
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
213 if bn.Responsible_country != nil { |
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
214 country = string(*bn.Responsible_country) |
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
215 } |
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
216 |
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
217 fmt.Printf("%s '%s' %s %s\n", bn.Fk_g_fid, bn.OBJNAM, bn.From_ISRS, bn.To_ISRS) |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
218 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
219 if _, err := st.Exec( |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
220 bn.Bottleneck_id, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
221 bn.Fk_g_fid, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
222 bn.OBJNAM, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
223 bn.NOBJNM, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
224 bn.From_ISRS, bn.To_ISRS, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
225 rb, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
226 lb, |
575
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
227 country, |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
228 revisitingTime(bn.Revisiting_time), |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
229 limiting, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
230 bn.Date_Info, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
231 bn.Source, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
232 ); err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
233 tx.Rollback() |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
234 return err |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
235 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
236 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
237 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
238 return tx.Commit() |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
239 }) |
589
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
240 } |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
241 |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
242 func main() { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
243 |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
244 flag.Parse() |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
245 |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
246 client := ifbn.NewIBottleneckService(*url, *insecure, nil) |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
247 |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
248 req := &ifbn.Export_bn_by_isrs{} |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
249 |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
250 resp, err := client.Export_bn_by_isrs(req) |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
251 if err != nil { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
252 log.Fatalf("error: %v\n", err) |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
253 } |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
254 |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
255 if resp.Export_bn_by_isrsResult == nil { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
256 return |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
257 } |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
258 bns := resp.Export_bn_by_isrsResult.BottleNeckType |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
259 |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
260 if *dump { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
261 err = dumpSQLStatements(bns) |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
262 } else { |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
263 err = storeInDatabase(bns) |
26cdc43ff977
bottlenecks: Add a -dump flag to dump INSERT statements instead of writing directly to the database.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
576
diff
changeset
|
264 } |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
265 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
266 if err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
267 log.Fatalf("error: %v\n", err) |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 } |