Mercurial > gemma
annotate cmd/bottlenecks/main.go @ 718:c0bba602b60e octree
octree: define a type for LineStringZ.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 21 Sep 2018 14:47:44 +0200 |
parents | d013fa5554cc |
children | a244b18cb916 |
rev | line source |
---|---|
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package main |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import ( |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
4 "database/sql" |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 "flag" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 "fmt" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 "log" |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
8 "regexp" |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
9 "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
|
10 "strings" |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
11 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
12 "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
|
13 "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
|
14 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 "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
|
16 ) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 source_organization |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
32 ) 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
|
33 $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
|
34 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
|
35 $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
|
36 $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
|
37 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
|
38 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
|
39 $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
|
40 $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
|
41 $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
|
42 $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
|
43 $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
|
44 $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
|
45 $13 |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
46 ) 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
|
47 |
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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 ) 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
|
63 %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
|
64 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
|
65 %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
|
66 %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
|
67 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
|
68 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
|
69 %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
|
70 %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
|
71 %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
|
72 %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
|
73 %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
|
74 %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
|
75 %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
|
76 ) 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
|
77 ` |
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 |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 ) |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
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 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
|
93 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
94 // 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
|
95 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
|
96 if err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
97 return err |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
98 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
99 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
100 // 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
|
101 cc.Host = *dbhost |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
102 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
|
103 cc.User = *dbuser |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
104 cc.Password = *dbpassword |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
105 cc.Database = *dbname |
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 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
|
108 defer db.Close() |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
109 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
110 return fn(db) |
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 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
|
114 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 return "", "" |
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 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
|
121 } |
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 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
|
124 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
|
125 if err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
126 v = 0 |
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 return v |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
129 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
130 |
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
|
131 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
|
132 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
|
133 } |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 |
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
|
135 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
|
136 |
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
|
137 fmt.Println("BEGIN;") |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 |
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
|
139 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
|
140 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
|
141 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
|
142 |
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
|
143 var limiting, country string |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 |
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
|
145 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
|
146 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
|
147 } |
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 |
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 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
|
150 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
|
151 } |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 |
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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 ); 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
|
167 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
|
168 } |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 } |
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
|
170 _, 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
|
171 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
|
172 } |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 |
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
|
174 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
|
175 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
|
176 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
177 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
|
178 if err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
179 return err |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
180 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
181 defer stmt.Close() |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
182 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
183 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
|
184 if err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
185 return err |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
186 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
187 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
188 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
|
189 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
190 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
|
191 bn := bns[i] |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
192 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
|
193 |
575
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
194 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
|
195 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
196 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
|
197 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
|
198 } |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 |
575
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
200 if bn.Responsible_country != nil { |
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
201 country = string(*bn.Responsible_country) |
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
202 } |
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
203 |
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
204 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
|
205 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
206 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
|
207 bn.Bottleneck_id, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
208 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
|
209 bn.OBJNAM, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
210 bn.NOBJNM, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
211 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
|
212 rb, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
213 lb, |
575
5484558e1b50
Fixed statements to insert bottlenecks.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
574
diff
changeset
|
214 country, |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
215 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
|
216 limiting, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
217 bn.Date_Info, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
218 bn.Source, |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
219 ); err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
220 tx.Rollback() |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
221 return err |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
222 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
223 } |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
224 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
225 return tx.Commit() |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
226 }) |
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
|
227 } |
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
|
228 |
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
|
229 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
|
230 |
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
|
231 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
|
232 |
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
|
233 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
|
234 |
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
|
235 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
|
236 |
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
|
237 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
|
238 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
|
239 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
|
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 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
|
243 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
|
244 } |
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 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
|
246 |
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 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
|
248 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
|
249 } 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
|
250 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
|
251 } |
574
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
252 |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
253 if err != nil { |
18c007104106
Try to insert bottlenecks from IFBN service into database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
254 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
|
255 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 } |