@@ -48,6 +48,7 @@ import (
48
48
dto "github.com/prometheus/client_model/go"
49
49
"github.com/stretchr/testify/require"
50
50
"go.uber.org/zap"
51
+ "golang.org/x/text/encoding/simplifiedchinese"
51
52
)
52
53
53
54
//revive:disable:exported
@@ -2727,4 +2728,64 @@ func (cli *TestServerClient) RunTestConnectionCount(t *testing.T) {
2727
2728
})
2728
2729
}
2729
2730
2731
+ func (cli * TestServerClient ) RunTestTypeAndCharsetOfSendLongData (t * testing.T ) {
2732
+ cli .RunTests (t , func (config * mysql.Config ) {
2733
+ config .MaxAllowedPacket = 1024
2734
+ }, func (dbt * testkit.DBTestKit ) {
2735
+ ctx := context .Background ()
2736
+
2737
+ conn , err := dbt .GetDB ().Conn (ctx )
2738
+ require .NoError (t , err )
2739
+ _ , err = conn .ExecContext (ctx , "CREATE TABLE t (j JSON);" )
2740
+ require .NoError (t , err )
2741
+
2742
+ str := `"` + strings .Repeat ("a" , 1024 ) + `"`
2743
+ stmt , err := conn .PrepareContext (ctx , "INSERT INTO t VALUES (cast(? as JSON));" )
2744
+ require .NoError (t , err )
2745
+ _ , err = stmt .ExecContext (ctx , str )
2746
+ require .NoError (t , err )
2747
+ result , err := conn .QueryContext (ctx , "SELECT j FROM t;" )
2748
+ require .NoError (t , err )
2749
+
2750
+ for result .Next () {
2751
+ var j string
2752
+ require .NoError (t , result .Scan (& j ))
2753
+ require .Equal (t , str , j )
2754
+ }
2755
+ })
2756
+
2757
+ str := strings .Repeat ("你好" , 1024 )
2758
+ enc := simplifiedchinese .GBK .NewEncoder ()
2759
+ gbkStr , err := enc .String (str )
2760
+ require .NoError (t , err )
2761
+
2762
+ cli .RunTests (t , func (config * mysql.Config ) {
2763
+ config .MaxAllowedPacket = 1024
2764
+ config .Params ["charset" ] = "gbk"
2765
+ }, func (dbt * testkit.DBTestKit ) {
2766
+ ctx := context .Background ()
2767
+
2768
+ conn , err := dbt .GetDB ().Conn (ctx )
2769
+ require .NoError (t , err )
2770
+ _ , err = conn .ExecContext (ctx , "drop table t" )
2771
+ require .NoError (t , err )
2772
+ _ , err = conn .ExecContext (ctx , "CREATE TABLE t (t TEXT);" )
2773
+ require .NoError (t , err )
2774
+
2775
+ stmt , err := conn .PrepareContext (ctx , "INSERT INTO t VALUES (?);" )
2776
+ require .NoError (t , err )
2777
+ _ , err = stmt .ExecContext (ctx , gbkStr )
2778
+ require .NoError (t , err )
2779
+
2780
+ result , err := conn .QueryContext (ctx , "SELECT * FROM t;" )
2781
+ require .NoError (t , err )
2782
+
2783
+ for result .Next () {
2784
+ var txt string
2785
+ require .NoError (t , result .Scan (& txt ))
2786
+ require .Equal (t , gbkStr , txt )
2787
+ }
2788
+ })
2789
+ }
2790
+
2730
2791
//revive:enable:exported
0 commit comments