1
1
import io
2
2
import time
3
3
import unittest
4
+ from unittest .mock import patch
5
+
6
+ import pytest
7
+ from pymysql .protocol import MysqlPacket
4
8
5
- from pymysqlreplication .json_binary import JsonDiff , JsonDiffOperation
6
- from pymysqlreplication .tests import base
7
9
from pymysqlreplication import BinLogStreamReader
8
- from pymysqlreplication .gtid import GtidSet , Gtid
9
- from pymysqlreplication .event import *
10
10
from pymysqlreplication .constants .BINLOG import *
11
11
from pymysqlreplication .constants .NONE_SOURCE import *
12
- from pymysqlreplication .row_event import *
12
+ from pymysqlreplication .event import *
13
+ from pymysqlreplication .gtid import Gtid , GtidSet
14
+ from pymysqlreplication .json_binary import JsonDiff , JsonDiffOperation
13
15
from pymysqlreplication .packet import BinLogPacketWrapper
14
- from pymysql .protocol import MysqlPacket
15
- from unittest .mock import patch
16
- import pytest
17
-
16
+ from pymysqlreplication .row_event import *
17
+ from pymysqlreplication .tests import base
18
18
19
19
__all__ = [
20
20
"TestBasicBinLogStreamReader" ,
@@ -601,6 +601,7 @@ def create_binlog_packet_wrapper(pkt):
601
601
self .stream ._BinLogStreamReader__ignored_schemas ,
602
602
self .stream ._BinLogStreamReader__freeze_schema ,
603
603
self .stream ._BinLogStreamReader__ignore_decode_errors ,
604
+ self .stream ._BinlogStreamReader__force_encoding ,
604
605
self .stream ._BinLogStreamReader__verify_checksum ,
605
606
self .stream ._BinLogStreamReader__optional_meta_data ,
606
607
)
@@ -808,7 +809,7 @@ def test_delete_multiple_row_event(self):
808
809
self .assertEqual (event .rows [1 ]["values" ]["id" ], 2 )
809
810
self .assertEqual (event .rows [1 ]["values" ]["data" ], "World" )
810
811
811
- def test_ignore_decode_errors (self ):
812
+ def test_force_encoding (self ):
812
813
if self .isMySQL80AndMore ():
813
814
self .skipTest ("MYSQL 8 Version Pymysql Data Error Incorrect string value" )
814
815
problematic_unicode_string = (
@@ -821,29 +822,40 @@ def test_ignore_decode_errors(self):
821
822
)
822
823
self .execute ("COMMIT" )
823
824
824
- # Initialize with ignore_decode_errors=False
825
+
826
+ def test_ignore_decode_errors (self ):
827
+ if self .isMySQL80AndMore ():
828
+ self .skipTest ("MYSQL 8 Version Pymysql Data Error Incorrect string value" )
829
+ problematic_unicode_string = "ó" .encode ("latin-1" )
830
+ self .stream .close ()
831
+ self .execute ("CREATE TABLE test (data VARCHAR(50) CHARACTER SET latin1)" )
832
+ self .execute_with_args (
833
+ "INSERT INTO test (data) VALUES (%s)" , (problematic_unicode_string )
834
+ )
835
+ self .execute ("COMMIT" )
836
+
825
837
self .stream = BinLogStreamReader (
826
838
self .database ,
827
839
server_id = 1024 ,
828
840
only_events = (WriteRowsEvent ,),
829
- ignore_decode_errors = False ,
841
+ force_encoding = None ,
830
842
)
831
843
with self .assertRaises (UnicodeError ):
832
844
event = self .stream .fetchone ()
833
845
data = event .rows [0 ]["values" ]["data" ]
834
846
835
- # Initialize with ignore_decode_errors=True
836
847
self .stream = BinLogStreamReader (
837
848
self .database ,
838
849
server_id = 1024 ,
839
850
only_events = (WriteRowsEvent ,),
840
- ignore_decode_errors = True ,
851
+ force_encoding = "latin-1" ,
841
852
)
842
853
event = self .stream .fetchone ()
843
854
if event .table_map [event .table_id ].column_name_flag :
844
855
data = event .rows [0 ]["values" ]["data" ]
845
856
self .assertEqual (data , '[{"text":" Some string"}]' )
846
857
858
+
847
859
def test_drop_column (self ):
848
860
self .stream .close ()
849
861
self .execute ("CREATE TABLE test_drop_column (id INTEGER(11), data VARCHAR(50))" )
0 commit comments