-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin_code.go
71 lines (63 loc) · 979 Bytes
/
admin_code.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"database/sql"
"log"
)
type tmpAdmin1Codes struct {
code string
asciiname string
geonameid int
}
func adminCode(db *sql.DB) map[string]int {
var adminCodeMap = make(map[string]int)
_, err := db.Exec(`TRUNCATE "adminCode" CASCADE;`)
if err != nil {
log.Fatal(err)
}
rows, err := db.Query(`
SELECT
"code",
"asciiname",
"geonameid"
FROM "tmp_admin1Codes"
`)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var r tmpAdmin1Codes
err := rows.Scan(
&r.code,
&r.asciiname,
&r.geonameid,
)
adminCodeMap[r.code] = r.geonameid
if err != nil {
log.Fatal(err)
}
insertAdminCode(db, r.geonameid, r.asciiname)
}
return adminCodeMap
}
func insertAdminCode(
db *sql.DB,
geonameid int,
name string,
) {
_, err := db.Exec(`
INSERT INTO "adminCode" (
"id",
"name"
) VALUES (
$1,
$2
)
`,
geonameid,
fixName(name),
)
if err != nil {
log.Fatal(err)
}
}