mirror of https://github.com/jackc/pgx.git
Fix CommandTag RowsAffected for INSERT
parent
51cada7b74
commit
247fd3be53
8
conn.go
8
conn.go
|
@ -83,12 +83,8 @@ type CommandTag string
|
|||
// 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
|
||||
func (ct CommandTag) RowsAffected() int64 {
|
||||
words := strings.SplitN(string(ct), " ", 2)
|
||||
if len(words) != 2 {
|
||||
return 0
|
||||
}
|
||||
|
||||
n, _ := strconv.ParseInt(words[1], 10, 64)
|
||||
words := strings.Split(string(ct), " ")
|
||||
n, _ := strconv.ParseInt(words[len(words)-1], 10, 64)
|
||||
return n
|
||||
}
|
||||
|
||||
|
|
|
@ -860,6 +860,7 @@ func TestCommandTag(t *testing.T) {
|
|||
commandTag pgx.CommandTag
|
||||
rowsAffected int64
|
||||
}{
|
||||
{commandTag: "INSERT 0 5", rowsAffected: 5},
|
||||
{commandTag: "UPDATE 0", rowsAffected: 0},
|
||||
{commandTag: "UPDATE 1", rowsAffected: 1},
|
||||
{commandTag: "DELETE 0", rowsAffected: 0},
|
||||
|
|
Loading…
Reference in New Issue