@@ -1036,6 +1036,51 @@ func TestConcurrent(t *testing.T) {
1036
1036
})
1037
1037
}
1038
1038
1039
+ func TestFoundRows (t * testing.T ) {
1040
+ runTests (t , "TestFoundRows1" , dsn , func (dbt * DBTest ) {
1041
+ dbt .mustExec ("CREATE TABLE test (id INT NOT NULL ,data INT NOT NULL)" )
1042
+ dbt .mustExec ("INSERT INTO test (id, data) VALUES (0, 0),(0, 0),(1, 0),(1, 0),(1, 1)" )
1043
+
1044
+ res := dbt .mustExec ("UPDATE test SET data = 1 WHERE id = 0" )
1045
+ count , err := res .RowsAffected ()
1046
+ if err != nil {
1047
+ dbt .Fatalf ("res.RowsAffected() returned error: %v" , err )
1048
+ }
1049
+ if count != 2 {
1050
+ dbt .Fatalf ("Expected 2 affected rows, got %d" , count )
1051
+ }
1052
+ res = dbt .mustExec ("UPDATE test SET data = 1 WHERE id = 1" )
1053
+ count , err = res .RowsAffected ()
1054
+ if err != nil {
1055
+ dbt .Fatalf ("res.RowsAffected() returned error: %v" , err )
1056
+ }
1057
+ if count != 2 {
1058
+ dbt .Fatalf ("Expected 2 affected rows, got %d" , count )
1059
+ }
1060
+ })
1061
+ runTests (t , "TestFoundRows2" , dsn + "&clientFoundRows=true" , func (dbt * DBTest ) {
1062
+ dbt .mustExec ("CREATE TABLE test (id INT NOT NULL ,data INT NOT NULL)" )
1063
+ dbt .mustExec ("INSERT INTO test (id, data) VALUES (0, 0),(0, 0),(1, 0),(1, 0),(1, 1)" )
1064
+
1065
+ res := dbt .mustExec ("UPDATE test SET data = 1 WHERE id = 0" )
1066
+ count , err := res .RowsAffected ()
1067
+ if err != nil {
1068
+ dbt .Fatalf ("res.RowsAffected() returned error: %v" , err )
1069
+ }
1070
+ if count != 2 {
1071
+ dbt .Fatalf ("Expected 2 matched rows, got %d" , count )
1072
+ }
1073
+ res = dbt .mustExec ("UPDATE test SET data = 1 WHERE id = 1" )
1074
+ count , err = res .RowsAffected ()
1075
+ if err != nil {
1076
+ dbt .Fatalf ("res.RowsAffected() returned error: %v" , err )
1077
+ }
1078
+ if count != 3 {
1079
+ dbt .Fatalf ("Expected 3 matched rows, got %d" , count )
1080
+ }
1081
+ })
1082
+ }
1083
+
1039
1084
// BENCHMARKS
1040
1085
var sample []byte
1041
1086
0 commit comments