@@ -915,35 +915,43 @@ func writeReplaceRowValues(
915915 tblStuff tableStuff ,
916916 row []any ,
917917 buf * bytes.Buffer ,
918- ) {
918+ ) error {
919919 buf .WriteString ("(" )
920920 for i , idx := range tblStuff .def .visibleIdxes {
921- formatValIntoString (ses , row [idx ], tblStuff .def .colTypes [idx ], buf )
921+ if err := formatValIntoString (ses , row [idx ], tblStuff .def .colTypes [idx ], buf ); err != nil {
922+ return err
923+ }
922924 if i != len (tblStuff .def .visibleIdxes )- 1 {
923925 buf .WriteString ("," )
924926 }
925927 }
926928 buf .WriteString (")" )
929+
930+ return nil
927931}
928932
929933func writeDeleteRowValues (
930934 ses * Session ,
931935 tblStuff tableStuff ,
932936 row []any ,
933937 buf * bytes.Buffer ,
934- ) {
938+ ) error {
935939 if len (tblStuff .def .pkColIdxes ) > 1 {
936940 buf .WriteString ("(" )
937941 }
938942 for i , colIdx := range tblStuff .def .pkColIdxes {
939- formatValIntoString (ses , row [colIdx ], tblStuff .def .colTypes [colIdx ], buf )
943+ if err := formatValIntoString (ses , row [colIdx ], tblStuff .def .colTypes [colIdx ], buf ); err != nil {
944+ return err
945+ }
940946 if i != len (tblStuff .def .pkColIdxes )- 1 {
941947 buf .WriteString ("," )
942948 }
943949 }
944950 if len (tblStuff .def .pkColIdxes ) > 1 {
945951 buf .WriteString (")" )
946952 }
953+
954+ return nil
947955}
948956
949957func appendBatchRowsAsSQLValues (
@@ -1011,9 +1019,13 @@ func appendBatchRowsAsSQLValues(
10111019
10121020 tmpValsBuffer .Reset ()
10131021 if wrapped .kind == diffDelete {
1014- writeDeleteRowValues (ses , tblStuff , row , tmpValsBuffer )
1022+ if err = writeDeleteRowValues (ses , tblStuff , row , tmpValsBuffer ); err != nil {
1023+ return
1024+ }
10151025 } else {
1016- writeReplaceRowValues (ses , tblStuff , row , tmpValsBuffer )
1026+ if err = writeReplaceRowValues (ses , tblStuff , row , tmpValsBuffer ); err != nil {
1027+ return
1028+ }
10171029 }
10181030
10191031 if tmpValsBuffer .Len () == 0 {
@@ -2588,7 +2600,12 @@ func hashDiffIfHasLCA(
25882600 }
25892601
25902602 buf := acquireBuffer (tblStuff .bufPool )
2591- formatValIntoString (ses , tarRow [0 ], tblStuff .def .colTypes [tblStuff .def .pkColIdx ], buf )
2603+ if err3 = formatValIntoString (
2604+ ses , tarRow [0 ], tblStuff .def .colTypes [tblStuff .def .pkColIdx ], buf ,
2605+ ); err3 != nil {
2606+ releaseBuffer (tblStuff .bufPool , buf )
2607+ return
2608+ }
25922609
25932610 err3 = moerr .NewInternalErrorNoCtxf (
25942611 "conflict: %s %s and %s %s on pk(%v) with different values" ,
@@ -3017,7 +3034,10 @@ func checkConflictAndAppendToBat(
30173034 case tree .CONFLICT_FAIL :
30183035 buf := acquireBuffer (tblStuff .bufPool )
30193036 for i , idx := range tblStuff .def .pkColIdxes {
3020- formatValIntoString (ses , tarTuple [idx ], tblStuff .def .colTypes [idx ], buf )
3037+ if err2 = formatValIntoString (ses , tarTuple [idx ], tblStuff .def .colTypes [idx ], buf ); err2 != nil {
3038+ releaseBuffer (tblStuff .bufPool , buf )
3039+ return err2
3040+ }
30213041 if i < len (tblStuff .def .pkColIdxes )- 1 {
30223042 buf .WriteString ("," )
30233043 }
@@ -3325,7 +3345,11 @@ func handleDelsOnLCA(
33253345 valsBuf .WriteString (fmt .Sprintf ("row(%d," , i ))
33263346
33273347 for j := range tuple {
3328- formatValIntoString (ses , tuple [j ], colTypes [expandedPKColIdxes [j ]], valsBuf )
3348+ if err = formatValIntoString (
3349+ ses , tuple [j ], colTypes [expandedPKColIdxes [j ]], valsBuf ,
3350+ ); err != nil {
3351+ return nil , err
3352+ }
33293353 if j != len (tuple )- 1 {
33303354 valsBuf .WriteString (", " )
33313355 }
@@ -3473,10 +3497,10 @@ func handleDelsOnLCA(
34733497 return
34743498}
34753499
3476- func formatValIntoString (ses * Session , val any , t types.Type , buf * bytes.Buffer ) {
3500+ func formatValIntoString (ses * Session , val any , t types.Type , buf * bytes.Buffer ) error {
34773501 if val == nil {
34783502 buf .WriteString ("NULL" )
3479- return
3503+ return nil
34803504 }
34813505
34823506 var scratch [64 ]byte
@@ -3507,30 +3531,30 @@ func formatValIntoString(ses *Session, val any, t types.Type, buf *bytes.Buffer)
35073531 strVal = x .String ()
35083532 case * bytejson.ByteJson :
35093533 if x == nil {
3510- panic ( moerr .NewInternalErrorNoCtx ("formatValIntoString: nil *bytejson.ByteJson" ) )
3534+ return moerr .NewInternalErrorNoCtx ("formatValIntoString: nil *bytejson.ByteJson" )
35113535 }
35123536 strVal = x .String ()
35133537 case []byte :
35143538 strVal = string (x )
35153539 case string :
35163540 strVal = x
35173541 default :
3518- panic ( moerr .NewInternalErrorNoCtxf ("formatValIntoString: unexpected json type %T" , val ) )
3542+ return moerr .NewInternalErrorNoCtxf ("formatValIntoString: unexpected json type %T" , val )
35193543 }
35203544 jsonLiteral := escapeJSONControlBytes ([]byte (strVal ))
35213545 if ! json .Valid (jsonLiteral ) {
3522- panic ( moerr .NewInternalErrorNoCtxf ("formatValIntoString: invalid json input %q" , strVal ) )
3546+ return moerr .NewInternalErrorNoCtxf ("formatValIntoString: invalid json input %q" , strVal )
35233547 }
35243548 writeEscapedSQLString (buf , jsonLiteral )
3525- return
3549+ return nil
35263550 }
35273551 switch x := val .(type ) {
35283552 case []byte :
35293553 writeEscapedSQLString (buf , x )
35303554 case string :
35313555 writeEscapedSQLString (buf , []byte (x ))
35323556 default :
3533- panic ( moerr .NewInternalErrorNoCtxf ("formatValIntoString: unexpected string type %T" , val ) )
3557+ return moerr .NewInternalErrorNoCtxf ("formatValIntoString: unexpected string type %T" , val )
35343558 }
35353559 case types .T_timestamp :
35363560 buf .WriteString ("'" )
@@ -3585,8 +3609,10 @@ func formatValIntoString(ses *Session, val any, t types.Type, buf *bytes.Buffer)
35853609 buf .WriteString (types.ArrayToString [float64 ](val .([]float64 )))
35863610 buf .WriteString ("'" )
35873611 default :
3588- panic ( moerr .NewInternalErrorNoCtxf ("formatValIntoString: unsupported type %v" , t .Oid ) )
3612+ return moerr .NewNotSupportedNoCtxf ("formatValIntoString: not support type %v" , t .Oid )
35893613 }
3614+
3615+ return nil
35903616}
35913617
35923618// writeEscapedSQLString escapes special and control characters for SQL literal output.
0 commit comments