@@ -488,6 +488,7 @@ typedef struct {
488488 PyObject * _next_seq_id ;
489489 PyObject * rows ;
490490 } py_str ;
491+ char * encoding_errors ;
491492} StateObject ;
492493
493494static void read_options (MySQLAccelOptions * options , PyObject * dict );
@@ -502,6 +503,7 @@ static void State_clear_fields(StateObject *self) {
502503 DESTROY (self -> type_codes );
503504 DESTROY (self -> encodings );
504505 DESTROY (self -> structsequence_desc .fields );
506+ DESTROY (self -> encoding_errors );
505507 if (self -> py_converters ) {
506508 for (unsigned long i = 0 ; i < self -> n_cols ; i ++ ) {
507509 Py_CLEAR (self -> py_converters [i ]);
@@ -574,6 +576,17 @@ static int State_init(StateObject *self, PyObject *args, PyObject *kwds) {
574576 if (py_unbuffered && PyObject_IsTrue (py_unbuffered )) {
575577 self -> unbuffered = 1 ;
576578 }
579+ PyObject * py_encoding_errors = PyDict_GetItemString (py_options , "encoding_errors" );
580+ if (py_encoding_errors ) {
581+ self -> encoding_errors = PyUnicode_AsUTF8 (py_encoding_errors );
582+ if (!self -> encoding_errors ) goto error ;
583+ }
584+ }
585+
586+ if (!self -> encoding_errors ) {
587+ self -> encoding_errors = calloc (7 , 1 );
588+ if (!self -> encoding_errors ) goto error ;
589+ memcpy (self -> encoding_errors , "strict" , 6 );
577590 }
578591
579592 if (self -> unbuffered ) {
@@ -1371,7 +1384,7 @@ static PyObject *read_row_from_packet(
13711384 py_str = PyBytes_FromStringAndSize (out , out_l );
13721385 if (!py_str ) goto error ;
13731386 } else {
1374- py_str = PyUnicode_Decode (out , out_l , py_state -> encodings [i ], "strict" );
1387+ py_str = PyUnicode_Decode (out , out_l , py_state -> encodings [i ], py_state -> encoding_errors );
13751388 if (!py_str ) goto error ;
13761389 }
13771390 py_item = PyObject_CallFunctionObjArgs (py_state -> py_converters [i ], py_str , NULL );
@@ -1384,7 +1397,7 @@ static PyObject *read_row_from_packet(
13841397 switch (py_state -> type_codes [i ]) {
13851398 case MYSQL_TYPE_NEWDECIMAL :
13861399 case MYSQL_TYPE_DECIMAL :
1387- py_str = PyUnicode_Decode (out , out_l , py_state -> encodings [i ], "strict" );
1400+ py_str = PyUnicode_Decode (out , out_l , py_state -> encodings [i ], py_state -> encoding_errors );
13881401 if (!py_str ) goto error ;
13891402
13901403 py_item = PyObject_CallFunctionObjArgs (PyFunc .decimal_Decimal , py_str , NULL );
@@ -1431,7 +1444,7 @@ static PyObject *read_row_from_packet(
14311444 py_item = py_state -> py_invalid_values [i ];
14321445 Py_INCREF (py_item );
14331446 } else {
1434- py_item = PyUnicode_Decode (orig_out , orig_out_l , "utf8 " , "strict" );
1447+ py_item = PyUnicode_Decode (orig_out , orig_out_l , "ascii " , py_state -> encoding_errors );
14351448 if (!py_item ) goto error ;
14361449 }
14371450 break ;
@@ -1451,7 +1464,7 @@ static PyObject *read_row_from_packet(
14511464 year , month , day , hour , minute , second , microsecond );
14521465 if (!py_item ) {
14531466 PyErr_Clear ();
1454- py_item = PyUnicode_Decode (orig_out , orig_out_l , "utf8 " , "strict" );
1467+ py_item = PyUnicode_Decode (orig_out , orig_out_l , "ascii " , py_state -> encoding_errors );
14551468 }
14561469 if (!py_item ) goto error ;
14571470 break ;
@@ -1468,7 +1481,7 @@ static PyObject *read_row_from_packet(
14681481 py_item = py_state -> py_invalid_values [i ];
14691482 Py_INCREF (py_item );
14701483 } else {
1471- py_item = PyUnicode_Decode (orig_out , orig_out_l , "utf8 " , "strict" );
1484+ py_item = PyUnicode_Decode (orig_out , orig_out_l , "ascii " , py_state -> encoding_errors );
14721485 if (!py_item ) goto error ;
14731486 }
14741487 break ;
@@ -1483,7 +1496,7 @@ static PyObject *read_row_from_packet(
14831496 year , month , day );
14841497 if (!py_item ) {
14851498 PyErr_Clear ();
1486- py_item = PyUnicode_Decode (orig_out , orig_out_l , "utf8 " , "strict" );
1499+ py_item = PyUnicode_Decode (orig_out , orig_out_l , "ascii " , py_state -> encoding_errors );
14871500 }
14881501 if (!py_item ) goto error ;
14891502 break ;
@@ -1495,7 +1508,7 @@ static PyObject *read_row_from_packet(
14951508 py_item = py_state -> py_invalid_values [i ];
14961509 Py_INCREF (py_item );
14971510 } else {
1498- py_item = PyUnicode_Decode (orig_out , orig_out_l , "utf8 " , "strict" );
1511+ py_item = PyUnicode_Decode (orig_out , orig_out_l , "ascii " , py_state -> encoding_errors );
14991512 if (!py_item ) goto error ;
15001513 }
15011514 break ;
@@ -1533,7 +1546,7 @@ static PyObject *read_row_from_packet(
15331546 sign * microsecond );
15341547 if (!py_item ) {
15351548 PyErr_Clear ();
1536- py_item = PyUnicode_Decode (orig_out , orig_out_l , "utf8 " , "strict" );
1549+ py_item = PyUnicode_Decode (orig_out , orig_out_l , "ascii " , py_state -> encoding_errors );
15371550 }
15381551 if (!py_item ) goto error ;
15391552 break ;
@@ -1568,7 +1581,7 @@ static PyObject *read_row_from_packet(
15681581 break ;
15691582 }
15701583
1571- py_item = PyUnicode_Decode (out , out_l , py_state -> encodings [i ], "strict" );
1584+ py_item = PyUnicode_Decode (out , out_l , py_state -> encodings [i ], py_state -> encoding_errors );
15721585 if (!py_item ) goto error ;
15731586
15741587 // Parse JSON string.
0 commit comments