@@ -39,3 +39,34 @@ func TestExec(t *testing.T) {
3939 assert .Equal (t , int64 (4 ), affected , "the rows affected should be 4" )
4040 }
4141}
42+ func TestExecWrite (t * testing.T ) {
43+ NewTableForQueryTest ()
44+ qb := getTestBuilder ()
45+ rows := qb .From ("table_test_query as t" ).
46+ Where ("email" , "like" , "%@yao.run" ).
47+ OrderBy ("id" ).
48+ MustGet ()
49+
50+ assert .Equal (t , 4 , len (rows ), "the return rows should have 4 items" )
51+ if len (rows ) == 4 {
52+ assert .Equal (t , "96.32" , fmt .Sprintf ("%.2f" , rows [0 ].Get ("score" )), "the return value should be true" )
53+ assert .Equal (t , "64.56" , fmt .Sprintf ("%.2f" , rows [1 ].Get ("score" )), "the return value should be true" )
54+ assert .Equal (t , "99.27" , fmt .Sprintf ("%.2f" , rows [2 ].Get ("score" )), "the return value should be true" )
55+ assert .Equal (t , "48.12" , fmt .Sprintf ("%.2f" , rows [3 ].Get ("score" )), "the return value should be true" )
56+ }
57+
58+ // Exec
59+ if unit .Is ("postgres" ) {
60+ res , err := qb .ExecWrite ("update table_test_query set score = 100 where email like $1" , "%@yao.run" )
61+ assert .Nil (t , err , "the error should be nil" )
62+ affected , err := res .RowsAffected ()
63+ assert .Nil (t , err , "the error should be nil" )
64+ assert .Equal (t , int64 (4 ), affected , "the rows affected should be 4" )
65+ } else {
66+ res , err := qb .ExecWrite ("update table_test_query set score = 100 where email like ?" , "%@yao.run" )
67+ assert .Nil (t , err , "the error should be nil" )
68+ affected , err := res .RowsAffected ()
69+ assert .Nil (t , err , "the error should be nil" )
70+ assert .Equal (t , int64 (4 ), affected , "the rows affected should be 4" )
71+ }
72+ }
0 commit comments