mirror of https://github.com/jackc/pgx.git
Use LastIndex instead of Split for better performance getting the number of rows affected from CommandTag
parent
d857f18454
commit
04b54f03a5
8
conn.go
8
conn.go
|
@ -74,8 +74,12 @@ type CommandTag string
|
||||||
// RowsAffected returns the number of rows affected. If the CommandTag was not
|
// RowsAffected returns the number of rows affected. If the CommandTag was not
|
||||||
// for a row affecting command (such as "CREATE TABLE") then it returns 0
|
// for a row affecting command (such as "CREATE TABLE") then it returns 0
|
||||||
func (ct CommandTag) RowsAffected() int64 {
|
func (ct CommandTag) RowsAffected() int64 {
|
||||||
words := strings.Split(string(ct), " ")
|
s := string(ct)
|
||||||
n, _ := strconv.ParseInt(words[len(words)-1], 10, 64)
|
index := strings.LastIndex(s, " ")
|
||||||
|
if index == -1 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
n, _ := strconv.ParseInt(s[index+1:], 10, 64)
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue