mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 13:55:42 +03:00
31 lines
565 B
Go
Vendored
31 lines
565 B
Go
Vendored
// +build !go1.10
|
|
|
|
package mssql
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"errors"
|
|
)
|
|
|
|
func (r *Result) LastInsertId() (int64, error) {
|
|
s, err := r.c.Prepare("select cast(@@identity as bigint)")
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer s.Close()
|
|
rows, err := s.Query(nil)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer rows.Close()
|
|
dest := make([]driver.Value, 1)
|
|
err = rows.Next(dest)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
if dest[0] == nil {
|
|
return -1, errors.New("There is no generated identity value")
|
|
}
|
|
lastInsertId := dest[0].(int64)
|
|
return lastInsertId, nil
|
|
}
|