diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-08-05 20:36:41 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-08-05 20:36:41 +0100 |
commit | e913fe28e7f9009ff18194dd5cece3eae067a7c4 (patch) | |
tree | 794f1111014a1921f5888915710ac7c1bfacdfe3 | |
parent | bc795edf4ff146d204aa08786572e27d4323866d (diff) |
debugging numberformat issues
-rw-r--r-- | pkg/datamaps/db.go | 11 | ||||
-rw-r--r-- | pkg/datamaps/writer.go | 10 | ||||
-rw-r--r-- | pkg/datamaps/writer_test.go | 6 |
3 files changed, 16 insertions, 11 deletions
diff --git a/pkg/datamaps/db.go b/pkg/datamaps/db.go index 80724ce..d95bfd7 100644 --- a/pkg/datamaps/db.go +++ b/pkg/datamaps/db.go @@ -49,6 +49,7 @@ func setupDB(path string) (*sql.DB, error) { filename TEXT, value TEXT, numfmt TEXT, + vFormatted TEXT, FOREIGN KEY (dml_id) REFERENCES datamap_line(id) ON DELETE CASCADE @@ -236,14 +237,18 @@ func importXLSXtoDB(dmName string, returnName string, file string, db *sql.DB) e log.Println(err.Error()) } - // TODO - here we need to store the c.NumFmt string value in a new field - insertStmt, err := db.Prepare("insert into return_data (dml_id, ret_id, filename, value, numfmt) values(?,?,?,?,?)") + insertStmt, err := db.Prepare("insert into return_data (dml_id, ret_id, filename, value, numfmt, vFormatted) values(?,?,?,?,?,?)") if err != nil { log.Fatal(err) } defer insertStmt.Close() - _, err = insertStmt.Exec(dmlID, retID, filename, cellData.Value, cellData.NumFmt) + fValue, err := cellData.FormattedValue() + if err != nil { + return err + } + + _, err = insertStmt.Exec(dmlID, retID, filename, cellData.Value, cellData.NumFmt, fValue) if err != nil { log.Fatal(err) } diff --git a/pkg/datamaps/writer.go b/pkg/datamaps/writer.go index a3c3698..9595132 100644 --- a/pkg/datamaps/writer.go +++ b/pkg/datamaps/writer.go @@ -71,7 +71,7 @@ func CreateMaster(opts *Options) error { return err } - getDataSQL := `SELECT datamap_line.key, return_data.value, return_data.filename + getDataSQL := `SELECT datamap_line.key, return_data.vFormatted, return_data.filename FROM (((return_data INNER JOIN datamap_line ON return_data.dml_id=datamap_line.id) INNER JOIN datamap ON datamap_line.dm_id=datamap.id) @@ -89,11 +89,11 @@ func CreateMaster(opts *Options) error { return err } for masterData.Next() { - var key, filename, value, numFmt string - if err := masterData.Scan(&key, &value, &filename, &numFmt); err != nil { - return err + var key, filename, fmttedValue string + if err := masterData.Scan(&key, &fmttedValue, &filename); err != nil { + fmt.Errorf("Problem scanning data from database for master: %v", err) } - values, err = appendValueMap(key, value, values) + values, err = appendValueMap(key, fmttedValue, values) if _, ok := seen[filename]; !ok { headerSlice = append(headerSlice, filename) seen[filename] = struct{}{} diff --git a/pkg/datamaps/writer_test.go b/pkg/datamaps/writer_test.go index 412d7ba..e16ce10 100644 --- a/pkg/datamaps/writer_test.go +++ b/pkg/datamaps/writer_test.go @@ -71,7 +71,7 @@ func TestWriteMaster(t *testing.T) { {"A String 1", "test_template.xlsx", "Another Sheet", "B4", "This is a string"}, {"A Float 1", "test_template.xlsx", "Another Sheet", "B5", "2.2"}, {"An Integer 1", "test_template.xlsx", "Another Sheet", "B6", "10"}, - {"A Date 2", "test_template.xlsx", "Another Sheet", "D3", "20/10/19"}, + {"A Date 2", "test_template.xlsx", "Another Sheet", "D3", "21/10/19"}, {"A String 2", "test_template.xlsx", "Another Sheet", "D4", "This is a string"}, {"A Float 3", "test_template.xlsx", "Another Sheet", "D5", "3.2"}, {"An Integer 3", "test_template.xlsx", "Another Sheet", "D6", "11"}, @@ -90,7 +90,7 @@ func TestWriteMaster(t *testing.T) { {"A String 1", "test_template.xlsm", "Another Sheet", "B4", "This is a string"}, {"A Float 1", "test_template.xlsm", "Another Sheet", "B5", "2.2"}, {"An Integer 1", "test_template.xlsm", "Another Sheet", "B6", "10"}, - {"A Date 2", "test_template.xlsm", "Another Sheet", "D3", "20/10/19"}, + {"A Date 2", "test_template.xlsm", "Another Sheet", "D3", "21/10/19"}, {"A String 2", "test_template.xlsm", "Another Sheet", "D4", "This is a string"}, {"A Float 3", "test_template.xlsm", "Another Sheet", "D5", "3.2"}, {"An Integer 3", "test_template.xlsm", "Another Sheet", "D6", "11"}, @@ -103,7 +103,7 @@ func TestWriteMaster(t *testing.T) { // Regular testing of import // TODO fix date formatting for _, test := range tests { - sql := fmt.Sprintf(`SELECT return_data.value FROM return_data, datamap_line + sql := fmt.Sprintf(`SELECT return_data.vFormatted FROM return_data, datamap_line WHERE (return_data.filename=%q AND datamap_line.cellref=%q |