Skip to content

Commit

Permalink
Merge pull request #117 from js-ojus/js
Browse files Browse the repository at this point in the history
Correct `tx` variable shadowing error throughout the code base
  • Loading branch information
js-ojus authored Feb 27, 2019
2 parents a4bc409 + c852b61 commit 0785833
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 73 deletions.
38 changes: 23 additions & 15 deletions access_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ func (_AccessContexts) New(otx *sql.Tx, name string) (AccessContextID, error) {
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -296,8 +297,9 @@ func (_AccessContexts) Rename(otx *sql.Tx, id AccessContextID, name string) erro
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -311,7 +313,7 @@ func (_AccessContexts) Rename(otx *sql.Tx, id AccessContextID, name string) erro
SET name = ?
WHERE id = ?
`
_, err := tx.Exec(q, name, id)
_, err = tx.Exec(q, name, id)
if err != nil {
return err
}
Expand All @@ -335,8 +337,9 @@ func (_AccessContexts) SetActive(otx *sql.Tx, id AccessContextID, active bool) e
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -350,7 +353,7 @@ func (_AccessContexts) SetActive(otx *sql.Tx, id AccessContextID, active bool) e
SET active = ?
WHERE id = ?
`
_, err := tx.Exec(q, act, id)
_, err = tx.Exec(q, act, id)
if err != nil {
return err
}
Expand Down Expand Up @@ -445,8 +448,9 @@ func (_AccessContexts) AddGroupRole(otx *sql.Tx, id AccessContextID, gid GroupID
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -455,7 +459,7 @@ func (_AccessContexts) AddGroupRole(otx *sql.Tx, id AccessContextID, gid GroupID
tx = otx
}

_, err := tx.Exec(`INSERT INTO wf_ac_group_roles(ac_id, group_id, role_id) VALUES(?, ?, ?)`, id, gid, rid)
_, err = tx.Exec(`INSERT INTO wf_ac_group_roles(ac_id, group_id, role_id) VALUES(?, ?, ?)`, id, gid, rid)
if err != nil {
return err
}
Expand All @@ -477,8 +481,9 @@ func (_AccessContexts) RemoveGroupRole(otx *sql.Tx, id AccessContextID, gid Grou
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -487,7 +492,7 @@ func (_AccessContexts) RemoveGroupRole(otx *sql.Tx, id AccessContextID, gid Grou
tx = otx
}

_, err := tx.Exec(`DELETE FROM wf_ac_group_roles WHERE ac_id = ? AND group_id = ? AND role_id = ?`, id, gid, rid)
_, err = tx.Exec(`DELETE FROM wf_ac_group_roles WHERE ac_id = ? AND group_id = ? AND role_id = ?`, id, gid, rid)
if err != nil {
return err
}
Expand Down Expand Up @@ -552,8 +557,9 @@ func (_AccessContexts) AddGroup(otx *sql.Tx, id AccessContextID, gid, reportsTo
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -563,7 +569,7 @@ func (_AccessContexts) AddGroup(otx *sql.Tx, id AccessContextID, gid, reportsTo
}

q := `INSERT INTO wf_ac_group_hierarchy(ac_id, group_id, reports_to) VALUES (?, ?, ?)`
_, err := tx.Exec(q, id, gid, reportsTo)
_, err = tx.Exec(q, id, gid, reportsTo)
if err != nil {
return err
}
Expand All @@ -585,8 +591,9 @@ func (_AccessContexts) DeleteGroup(otx *sql.Tx, id AccessContextID, gid GroupID)
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -596,7 +603,7 @@ func (_AccessContexts) DeleteGroup(otx *sql.Tx, id AccessContextID, gid GroupID)
}

q := `DELETE FROM wf_ac_group_hierarchy WHERE ac_id = ? AND group_id = ?`
_, err := tx.Exec(q, id, gid)
_, err = tx.Exec(q, id, gid)
if err != nil {
return err
}
Expand Down Expand Up @@ -669,8 +676,9 @@ func (_AccessContexts) ChangeReporting(otx *sql.Tx, id AccessContextID, gid, rep
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -685,7 +693,7 @@ func (_AccessContexts) ChangeReporting(otx *sql.Tx, id AccessContextID, gid, rep
WHERE ac_id = ?
AND group_id = ?
`
_, err := tx.Exec(q, reportsTo, id, gid)
_, err = tx.Exec(q, reportsTo, id, gid)
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions docaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ func (_DocActions) New(otx *sql.Tx, name string, reconfirm bool) (DocActionID, e
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return 0, err
}
Expand All @@ -73,7 +74,6 @@ func (_DocActions) New(otx *sql.Tx, name string, reconfirm bool) (DocActionID, e
}

var res sql.Result
var err error
if reconfirm {
res, err = tx.Exec("INSERT INTO wf_docactions_master(name, reconfirm) VALUES(?, ?)", name, 1)
} else {
Expand Down Expand Up @@ -182,8 +182,9 @@ func (_DocActions) Rename(otx *sql.Tx, id DocActionID, name string) error {
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -192,7 +193,7 @@ func (_DocActions) Rename(otx *sql.Tx, id DocActionID, name string) error {
tx = otx
}

_, err := tx.Exec("UPDATE wf_docactions_master SET name = ? WHERE id = ?", name, id)
_, err = tx.Exec("UPDATE wf_docactions_master SET name = ? WHERE id = ?", name, id)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion docevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ func (_DocEvents) New(otx *sql.Tx, input *DocEventsNewInput) (DocEventID, error)
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return 0, err
}
Expand Down
8 changes: 5 additions & 3 deletions docstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ func (_DocStates) New(otx *sql.Tx, name string) (DocStateID, error) {
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -177,8 +178,9 @@ func (_DocStates) Rename(otx *sql.Tx, id DocStateID, name string) error {
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -187,7 +189,7 @@ func (_DocStates) Rename(otx *sql.Tx, id DocStateID, name string) error {
tx = otx
}

_, err := tx.Exec("UPDATE wf_docstates_master SET name = ? WHERE id = ?", name, id)
_, err = tx.Exec("UPDATE wf_docstates_master SET name = ? WHERE id = ?", name, id)
if err != nil {
return err
}
Expand Down
18 changes: 11 additions & 7 deletions doctype.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ func (_DocTypes) New(otx *sql.Tx, name string) (DocTypeID, error) {
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -211,8 +212,9 @@ func (_DocTypes) Rename(otx *sql.Tx, id DocTypeID, name string) error {
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -221,7 +223,7 @@ func (_DocTypes) Rename(otx *sql.Tx, id DocTypeID, name string) error {
tx = otx
}

_, err := tx.Exec("UPDATE wf_doctypes_master SET name = ? WHERE id = ?", name, id)
_, err = tx.Exec("UPDATE wf_doctypes_master SET name = ? WHERE id = ?", name, id)
if err != nil {
return err
}
Expand Down Expand Up @@ -342,8 +344,9 @@ func (_DocTypes) _Transitions(dtype DocTypeID, state DocStateID) (map[DocActionI
func (_DocTypes) AddTransition(otx *sql.Tx, dtype DocTypeID, state DocStateID,
action DocActionID, toState DocStateID) error {
var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -356,7 +359,7 @@ func (_DocTypes) AddTransition(otx *sql.Tx, dtype DocTypeID, state DocStateID,
INSERT INTO wf_docstate_transitions(doctype_id, from_state_id, docaction_id, to_state_id)
VALUES(?, ?, ?, ?)
`
_, err := tx.Exec(q, dtype, state, action, toState)
_, err = tx.Exec(q, dtype, state, action, toState)
if err != nil {
return err
}
Expand All @@ -375,8 +378,9 @@ func (_DocTypes) AddTransition(otx *sql.Tx, dtype DocTypeID, state DocStateID,
// document action performed on documents in the given current state.
func (_DocTypes) RemoveTransition(otx *sql.Tx, dtype DocTypeID, state DocStateID, action DocActionID) error {
var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -391,7 +395,7 @@ func (_DocTypes) RemoveTransition(otx *sql.Tx, dtype DocTypeID, state DocStateID
AND from_state_id =?
AND docaction_id = ?
`
_, err := tx.Exec(q, dtype, state, action)
_, err = tx.Exec(q, dtype, state, action)
if err != nil {
return err
}
Expand Down
23 changes: 13 additions & 10 deletions document.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (_Documents) New(otx *sql.Tx, input *DocumentsNewInput) (DocumentID, error)

var tx *sql.Tx
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -490,7 +490,7 @@ func (_Documents) SetTitle(otx *sql.Tx, dtype DocTypeID, id DocumentID, title st

var tx *sql.Tx
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand Down Expand Up @@ -523,8 +523,9 @@ func (_Documents) SetData(otx *sql.Tx, dtype DocTypeID, id DocumentID, data stri
tbl := DocTypes.docStorName(dtype)

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -534,7 +535,7 @@ func (_Documents) SetData(otx *sql.Tx, dtype DocTypeID, id DocumentID, data stri
}

q := `UPDATE ` + tbl + ` SET data = ?, ctime = NOW() WHERE id = ?`
_, err := tx.Exec(q, data, id)
_, err = tx.Exec(q, data, id)
if err != nil {
return err
}
Expand Down Expand Up @@ -667,7 +668,7 @@ func (_Documents) AddBlob(otx *sql.Tx, dtype DocTypeID, id DocumentID, blob *Blo

var tx *sql.Tx
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand Down Expand Up @@ -705,8 +706,9 @@ func (_Documents) DeleteBlob(otx *sql.Tx, dtype DocTypeID, id DocumentID, sha1 s
}

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -722,7 +724,7 @@ func (_Documents) DeleteBlob(otx *sql.Tx, dtype DocTypeID, id DocumentID, sha1 s
`
var count int64
row := tx.QueryRow(q, sha1)
err := row.Scan(&count)
err = row.Scan(&count)
if err != nil {
return err
}
Expand Down Expand Up @@ -826,7 +828,7 @@ func (_Documents) AddTags(otx *sql.Tx, dtype DocTypeID, id DocumentID, tags ...s

var tx *sql.Tx
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand Down Expand Up @@ -869,8 +871,9 @@ func (_Documents) RemoveTag(otx *sql.Tx, dtype DocTypeID, id DocumentID, tag str
tag = strings.ToLower(tag)

var tx *sql.Tx
var err error
if otx == nil {
tx, err := db.Begin()
tx, err = db.Begin()
if err != nil {
return err
}
Expand All @@ -886,7 +889,7 @@ func (_Documents) RemoveTag(otx *sql.Tx, dtype DocTypeID, id DocumentID, tag str
AND doc_id = ?
AND tag = ?
`
_, err := tx.Exec(q, dtype, id, tag)
_, err = tx.Exec(q, dtype, id, tag)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 0785833

Please sign in to comment.