Mercurial > gemma
changeset 4947:407103c299a0 fairway-marks-import
De-duped some attribute storing code in FM imports.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 19 Feb 2020 16:41:52 +0100 |
parents | b0dbc0f2c748 |
children | 821ae20b6a20 |
files | pkg/imports/fm.go |
diffstat | 1 files changed, 23 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/pkg/imports/fm.go Wed Feb 19 15:08:35 2020 +0100 +++ b/pkg/imports/fm.go Wed Feb 19 16:41:52 2020 +0100 @@ -399,6 +399,26 @@ return sql.NullInt64{} } +func storeAttribs(spc *SQLPointConsumer, id int64, attrs *string) { + if attrs == nil || *attrs == "" { + return + } + dirimps := strings.Split(*attrs, ",") + for _, dirimp := range dirimps { + if err := spc.savepoint(func() error { + _, err := spc.stmts[1].ExecContext( + spc.ctx, id, dirimp) + return err + }); err != nil { + spc.feedback.Warn( + pgxutils.ReadableError{Err: err}.Error()) + spc.feedback.Info( + "Tried to import '%s' as dirimp value", + dirimp) + } + } +} + func consumeBCNLAT( spc *SQLPointConsumer, points pointSlice, @@ -444,22 +464,7 @@ spc.feedback.Error(pgxutils.ReadableError{Err: err}.Error()) return ErrFeatureIgnored default: - if props.Dirimp != nil && *props.Dirimp != "" { - dirimps := strings.Split(*props.Dirimp, ",") - for _, dirimp := range dirimps { - if err := spc.savepoint(func() error { - _, err := spc.stmts[1].ExecContext( - spc.ctx, fmid, dirimp) - return err - }); err != nil { - spc.feedback.Warn( - pgxutils.ReadableError{Err: err}.Error()) - spc.feedback.Info( - "Tried to import '%s' as dirimp value", - dirimp) - } - } - } + storeAttribs(spc, fmid, props.Dirimp) } return nil } @@ -690,22 +695,7 @@ spc.feedback.Error(pgxutils.ReadableError{Err: err}.Error()) return ErrFeatureIgnored default: - if props.Dirimp != nil && *props.Dirimp != "" { - dirimps := strings.Split(*props.Dirimp, ",") - for _, dirimp := range dirimps { - if err := spc.savepoint(func() error { - _, err := spc.stmts[1].ExecContext( - spc.ctx, fmid, dirimp) - return err - }); err != nil { - spc.feedback.Warn( - pgxutils.ReadableError{Err: err}.Error()) - spc.feedback.Info( - "Tried to import '%s' as dirimp value", - dirimp) - } - } - } + storeAttribs(spc, fmid, props.Dirimp) } return nil } @@ -813,22 +803,7 @@ spc.feedback.Error(pgxutils.ReadableError{Err: err}.Error()) return ErrFeatureIgnored default: - if props.Dirimp != nil && *props.Dirimp != "" { - dirimps := strings.Split(*props.Dirimp, ",") - for _, dirimp := range dirimps { - if err := spc.savepoint(func() error { - _, err := spc.stmts[1].ExecContext( - spc.ctx, fmid, dirimp) - return err - }); err != nil { - spc.feedback.Warn( - pgxutils.ReadableError{Err: err}.Error()) - spc.feedback.Info( - "Tried to import '%s' as dirimp value", - dirimp) - } - } - } + storeAttribs(spc, fmid, props.Dirimp) } return nil }