aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-07-26 15:19:01 +0100
committerMatthew Lemon <matt@matthewlemon.com>2020-07-26 15:19:01 +0100
commit20d81808c238c5556c42b846cafcb2403e691ccf (patch)
tree9857a6f7f998159531bfd2be67a6e27269d76b69
parentbfa5f8f86104fedfe4fe4b54abcfe660b077cd14 (diff)
removed hard-coded SQL statment
-rw-r--r--pkg/datamaps/db.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/pkg/datamaps/db.go b/pkg/datamaps/db.go
index 2501da8..ee934c4 100644
--- a/pkg/datamaps/db.go
+++ b/pkg/datamaps/db.go
@@ -80,7 +80,14 @@ func DatamapToDB(opts *Options) error {
if err != nil {
return err
}
- _, err = stmtDm.Exec(opts.DMName, time.Now())
+ res, err := stmtDm.Exec(opts.DMName, time.Now())
+ if err != nil {
+ return err
+ }
+ lastId, err := res.LastInsertId()
+ if err != nil {
+ return err
+ }
stmtDml, err := tx.Prepare("INSERT INTO datamap_line (dm_id, key, sheet, cellref) VALUES(?,?,?,?);")
if err != nil {
@@ -89,7 +96,7 @@ func DatamapToDB(opts *Options) error {
defer stmtDm.Close()
defer stmtDml.Close()
for _, dml := range data {
- _, err = stmtDml.Exec(1, dml.Key, dml.Sheet, dml.Cellref)
+ _, err = stmtDml.Exec(lastId, dml.Key, dml.Sheet, dml.Cellref)
if err != nil {
return err
}