Fix CommandTag RowsAffected for INSERT
This commit is contained in:
@@ -83,12 +83,8 @@ 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.SplitN(string(ct), " ", 2)
|
words := strings.Split(string(ct), " ")
|
||||||
if len(words) != 2 {
|
n, _ := strconv.ParseInt(words[len(words)-1], 10, 64)
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
n, _ := strconv.ParseInt(words[1], 10, 64)
|
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -860,6 +860,7 @@ func TestCommandTag(t *testing.T) {
|
|||||||
commandTag pgx.CommandTag
|
commandTag pgx.CommandTag
|
||||||
rowsAffected int64
|
rowsAffected int64
|
||||||
}{
|
}{
|
||||||
|
{commandTag: "INSERT 0 5", rowsAffected: 5},
|
||||||
{commandTag: "UPDATE 0", rowsAffected: 0},
|
{commandTag: "UPDATE 0", rowsAffected: 0},
|
||||||
{commandTag: "UPDATE 1", rowsAffected: 1},
|
{commandTag: "UPDATE 1", rowsAffected: 1},
|
||||||
{commandTag: "DELETE 0", rowsAffected: 0},
|
{commandTag: "DELETE 0", rowsAffected: 0},
|
||||||
|
|||||||
Reference in New Issue
Block a user