Fix CommandTag RowsAffected for INSERT

scan-io
Jack Christensen 2014-06-20 13:38:01 -05:00
parent 51cada7b74
commit 247fd3be53
2 changed files with 3 additions and 6 deletions

View File

@ -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
}

View File

@ -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},