Skip to content

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.

1 participant