-
Notifications
You must be signed in to change notification settings - Fork 679
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
Parse NULL-bitmask in table map event #361
Merged
julien-duponchelle
merged 1 commit into
julien-duponchelle:main
from
dongwook-chan:null-bitmask
Oct 18, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,30 @@ def create_table(self, create_query): | |
|
||
return event | ||
|
||
def create_and_get_tablemap_event(self, bit): | ||
"""Create table and return tablemap event | ||
|
||
Returns: | ||
Table map event | ||
""" | ||
self.execute(create_query) | ||
self.execute(insert_query) | ||
self.execute("COMMIT") | ||
|
||
self.assertIsInstance(self.stream.fetchone(), RotateEvent) | ||
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent) | ||
#QueryEvent for the Create Table | ||
self.assertIsInstance(self.stream.fetchone(), QueryEvent) | ||
|
||
#QueryEvent for the BEGIN | ||
self.assertIsInstance(self.stream.fetchone(), QueryEvent) | ||
|
||
event = self.stream.fetchone() | ||
|
||
self.assertEqual(event.event_type, TABLE_MAP_EVENT) | ||
|
||
return event | ||
|
||
def test_decimal(self): | ||
create_query = "CREATE TABLE test (test DECIMAL(2,1))" | ||
insert_query = "INSERT INTO test VALUES(4.2)" | ||
|
@@ -669,16 +693,75 @@ def test_status_vars(self): | |
Note that if you change default db name 'pymysqlreplication_test', | ||
event.mts_accessed_db_names MUST be asserted against the changed db name. | ||
|
||
Returns: | ||
binary string parsed from __data_buffer | ||
|
||
Raises: | ||
AssertionError: if no | ||
AssertionError: if status variables not set correctly | ||
""" | ||
create_query = "CREATE TABLE test (id INTEGER)" | ||
event = self.create_table(create_query) | ||
self.assertEqual(event.catalog_nz_code, b'std') | ||
self.assertEqual(event.mts_accessed_db_names, [b'pymysqlreplication_test']) | ||
|
||
def test_null_bitmask(self) | ||
"""Test parse of null-bitmask in table map events | ||
|
||
Create table with 16 columns with nullability specified by 'bit_mask' variable | ||
'bit_mask' variable is asserted against null_bitmask attribute in table map event. | ||
|
||
Raises: | ||
AssertionError: if null_bitmask isn't set as specified in 'bit_mask' variable | ||
""" | ||
|
||
# any 2-byte bitmask in little-endian hex bytes format (b'a\x03') | ||
## b'a\x03' = 1101100001(2) | ||
bit_mask = b'a\x03' | ||
|
||
# Prepare create_query | ||
create_query = "CREATE TABLE test" | ||
|
||
columns = [] | ||
for i in range(16): | ||
# column_definition consists of... | ||
## column name, column type, nullability | ||
column_definition = [] | ||
|
||
column_name = chr(ord('a') + i) | ||
column_definition.append(column_name) | ||
|
||
column_type = "INT" | ||
column_definition.append(column_type) | ||
|
||
nullability = "NOT NULL" if not RowsEvent.__is_null(bit_mask, i) else "" | ||
column_definition.append(nullability) | ||
|
||
columns.append(" ".join(column_definition)) | ||
|
||
create_query += f' ({", ".join(columns)})' | ||
|
||
# Prepare insert_query | ||
insert_query = "INSERT into test values" | ||
|
||
values = [] | ||
for i in range(16): | ||
values.append('0') | ||
|
||
insert_query += f' ({",".join(values)})') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. insert_query += f' ({",".join(values)})' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the comment. 👍👍 |
||
|
||
self.execute(create_query) | ||
self.execute(insert_query) | ||
self.execute("COMMIT") | ||
|
||
self.assertIsInstance(self.stream.fetchone(), RotateEvent) | ||
self.assertIsInstance(self.stream.fetchone(), FormatDescriptionEvent) | ||
#QueryEvent for the Create Table | ||
self.assertIsInstance(self.stream.fetchone(), QueryEvent) | ||
|
||
#QueryEvent for the BEGIN | ||
self.assertIsInstance(self.stream.fetchone(), QueryEvent) | ||
|
||
event = self.stream.fetchone() | ||
|
||
self.assertEqual(event.event_type, TABLE_MAP_EVENT) | ||
self.assertEqual(event.null_bitmask, bit_mask) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_null_bitmask(self):