Skip to content

Distinguish ambiguous column value of None #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add constants/NONE_SOURCE.py
  • Loading branch information
heehehe committed Sep 29, 2023
commit be89cc511bca9f87ad514d9250564159a497e671
6 changes: 6 additions & 0 deletions pymysqlreplication/constants/NONE_SOURCE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NULL = "null"
OUT_OF_DATE_RANGE = "out of date range"
OUT_OF_DATETIME_RANGE = "out of datetime range"
OUT_OF_DATETIME2_RANGE = "out of datetime2 range"
EMPTY_SET = "empty set"
COLS_BITMAP = "cols bitmap"
17 changes: 9 additions & 8 deletions pymysqlreplication/row_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .constants import FIELD_TYPE
from .constants import BINLOG
from .constants import CHARSET
from .constants import NONE_SOURCE
from .column import Column
from .table import Table
from .bitmap import BitCount, BitGet
Expand Down Expand Up @@ -135,11 +136,11 @@ def __read_values_name(
if BitGet(cols_bitmap, i) == 0:
# This block is only executed when binlog_row_image = MINIMAL.
# When binlog_row_image = FULL, this block does not execute.
self.__none_sources[name] = "cols_bitmap"
self.__none_sources[name] = NONE_SOURCE.COLS_BITMAP
return None

if self._is_null(null_bitmap, null_bitmap_index):
self.__none_sources[name] = "null"
self.__none_sources[name] = NONE_SOURCE.NULL
return None

if column.type == FIELD_TYPE.TINY:
Expand Down Expand Up @@ -185,14 +186,14 @@ def __read_values_name(
elif column.type == FIELD_TYPE.DATETIME:
ret = self.__read_datetime()
if ret is None:
self.__none_sources[name] = "out of datetime range"
self.__none_sources[name] = NONE_SOURCE.OUT_OF_DATETIME_RANGE
return ret
elif column.type == FIELD_TYPE.TIME:
return self.__read_time()
elif column.type == FIELD_TYPE.DATE:
ret = self.__read_date()
if ret is None:
self.__none_sources[name] = "out of date range"
self.__none_sources[name] = NONE_SOURCE.OUT_OF_DATE_RANGE
return ret
elif column.type == FIELD_TYPE.TIMESTAMP:
return datetime.datetime.utcfromtimestamp(self.packet.read_uint32())
Expand All @@ -201,7 +202,7 @@ def __read_values_name(
elif column.type == FIELD_TYPE.DATETIME2:
ret = self.__read_datetime2(column)
if ret is None:
self.__none_sources[name] = "out of datetime2 range"
self.__none_sources[name] = NONE_SOURCE.OUT_OF_DATETIME2_RANGE
return ret
elif column.type == FIELD_TYPE.TIME2:
return self.__read_time2(column)
Expand Down Expand Up @@ -232,10 +233,10 @@ def __read_values_name(
if bit_mask & (1 << idx)
}
if not ret:
self.__none_sources[column.name] = "empty set"
self.__none_sources[column.name] = NONE_SOURCE.EMPTY_SET
return None
return ret
self.__none_sources[column.name] = "empty set"
self.__none_sources[column.name] = NONE_SOURCE.EMPTY_SET
return None
elif column.type == FIELD_TYPE.BIT:
return self.__read_bit(column)
Expand All @@ -244,7 +245,7 @@ def __read_values_name(
elif column.type == FIELD_TYPE.JSON:
return self.packet.read_binary_json(column.length_size)
else:
raise NotImplementedError("Unknown MySQL column type: %d" % (column.type))
raise NotImplementedError("Unknown MySQL column type: %d" % column.type)

def __add_fsp_to_time(self, time, column):
"""Read and add the fractional part of time
Expand Down