2014-02-05 17:21:07 +03:00
|
|
|
package sqlmock
|
|
|
|
|
2014-02-08 18:51:58 +03:00
|
|
|
import (
|
2014-02-13 22:59:35 +03:00
|
|
|
"database/sql/driver"
|
2014-02-08 18:51:58 +03:00
|
|
|
)
|
|
|
|
|
2014-02-07 11:44:41 +03:00
|
|
|
// Result satisfies sql driver Result, which
|
2014-02-07 09:58:27 +03:00
|
|
|
// holds last insert id and rows affected
|
2014-02-07 11:44:41 +03:00
|
|
|
// by Exec queries
|
2014-02-08 18:51:58 +03:00
|
|
|
type result struct {
|
2014-02-13 22:59:35 +03:00
|
|
|
insertID int64
|
2014-02-05 17:21:07 +03:00
|
|
|
rowsAffected int64
|
2014-08-14 20:35:18 +03:00
|
|
|
err error
|
2014-02-05 17:21:07 +03:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:51:58 +03:00
|
|
|
// NewResult creates a new sql driver Result
|
|
|
|
// for Exec based query mocks.
|
|
|
|
func NewResult(lastInsertID int64, rowsAffected int64) driver.Result {
|
|
|
|
return &result{
|
2014-08-14 20:35:18 +03:00
|
|
|
insertID: lastInsertID,
|
|
|
|
rowsAffected: rowsAffected,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewErrorResult creates a new sql driver Result
|
|
|
|
// which returns an error given for both interface methods
|
|
|
|
func NewErrorResult(err error) driver.Result {
|
|
|
|
return &result{
|
|
|
|
err: err,
|
2014-02-05 17:21:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-08 18:51:58 +03:00
|
|
|
func (r *result) LastInsertId() (int64, error) {
|
2014-08-14 20:35:18 +03:00
|
|
|
return r.insertID, r.err
|
2014-02-05 17:21:07 +03:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:51:58 +03:00
|
|
|
func (r *result) RowsAffected() (int64, error) {
|
2014-08-14 20:35:18 +03:00
|
|
|
return r.rowsAffected, r.err
|
2014-02-05 17:21:07 +03:00
|
|
|
}
|