Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 'no LastInsertId available' when mock UPDATE using gorm #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

qiulimao
Copy link

@qiulimao qiulimao commented Jan 3, 2019

//return driver.RowsAffected(fResp.RowsAffected), nil
/*******************************************
* the code in jinzhu/scope line 360~374    *
********************************************
/ Exec perform generated SQL
func (scope *Scope) Exec() *Scope {
    defer scope.trace(NowFunc())

    if !scope.HasError() {
        if result, err := scope.SQLDB().Exec(scope.SQL, scope.SQLVars...); scope.Err(err) == nil {

            if count, err := result.RowsAffected(); scope.Err(err) == nil {
                scope.db.RowsAffected = count
            }
            if lastInsertId, err := result.LastInsertId(); scope.Err(err) == nil {
                scope.db.LastInsertId = lastInsertId
            }
        }
    }
    return scope
}
// ********************************************
// here we can see that,if the sql.Result has any error in getting RowsAffected() or
// LastInsertId() the gorm will result an error.
// driver.RowsAffected's  LastInsertId() method will get error.That would case "no LastInsertId available"
// error tips,when mock UPDATE
    */
    // SO: let the user decide when get error,and how many rowsAffected and lastInsetID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant