aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/datamaps
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-07-28 06:26:58 +0100
committerMatthew Lemon <matt@matthewlemon.com>2020-07-28 06:26:58 +0100
commitdc2f030758be0ace3f382982b30cd58fa552a2cc (patch)
tree5ac568ac9df8e0e934ccdf43e6023560750192e7 /pkg/datamaps
parent4409c6f1b9a84f55adbdac906cee4a8b1a157a6e (diff)
UNIQUE constrait on return.name implemented
Diffstat (limited to 'pkg/datamaps')
-rw-r--r--pkg/datamaps/db.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/pkg/datamaps/db.go b/pkg/datamaps/db.go
index c930500..9eac466 100644
--- a/pkg/datamaps/db.go
+++ b/pkg/datamaps/db.go
@@ -38,7 +38,8 @@ func setupDB(path string) (*sql.DB, error) {
CREATE TABLE return(
id INTEGER PRIMARY KEY,
name TEXT,
- date_created TEXT
+ date_created TEXT,
+ UNIQUE(name)
);
CREATE TABLE return_data(
@@ -172,7 +173,6 @@ func importXLSXtoDB(dm_name string, return_name string, file string, db *sql.DB)
return err
}
fmt.Printf("Extracting from %s\n", file)
- // fmt.Printf("Data is: %#v\n", d["Introduction"]["C17"].Value)
stmtReturn, err := db.Prepare("insert into return(name, date_created) values(?,?)")
if err != nil {
@@ -183,11 +183,12 @@ func importXLSXtoDB(dm_name string, return_name string, file string, db *sql.DB)
res, err := stmtReturn.Exec(return_name, time.Now())
if err != nil {
- log.Fatal(err)
+ err := fmt.Errorf("%v\nReturn '%s' already in database. Use a different name.", err, return_name)
+ fmt.Println(err.Error())
+ os.Exit(1)
}
retId, err := res.LastInsertId()
- fmt.Println(retId)
if err != nil {
log.Fatal(err)
}
@@ -209,12 +210,12 @@ func importXLSXtoDB(dm_name string, return_name string, file string, db *sql.DB)
}
defer dmlQuery.Close()
dmlIdRow := dmlQuery.QueryRow(sheetName, cellRef)
- fmt.Println(dmlIdRow)
var dmlId *int
if err := dmlIdRow.Scan(&dmlId); err != nil {
- fmt.Errorf("cannot find a datamap_line row for %s and %s: %s\n", sheetName, cellRef, err)
+ err := fmt.Errorf("cannot find a datamap_line row for %s and %s: %s\n", sheetName, cellRef, err)
+ fmt.Println(err.Error())
}
insertStmt, err := db.Prepare("insert into return_data (dml_id, ret_id, value) values(?,?,?)")