Skip to content

Commit c4b637d

Browse files
jakubkulhanclaude
andcommitted
Update mysql-binlog-connector-rust to fix ENUM/SET parsing with proper string values and arrays
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 27ce200 commit c4b637d

4 files changed

Lines changed: 27 additions & 8 deletions

File tree

data-access-kit-replication/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data-access-kit-replication/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ crate-type = ["cdylib"]
99
[dependencies]
1010
ext-php-rs = "0.14.2"
1111
mysql_async = { version = "0.33", default-features = false, features = ["minimal"] }
12-
mysql-binlog-connector-rust = { git = "https://github.com/apecloud/mysql-binlog-connector-rust" }
12+
mysql-binlog-connector-rust = { git = "https://github.com/jakubkulhan/mysql-binlog-connector-rust", branch = "fix-enum-set-metadata" }
1313
tokio = { version = "1.0", default-features = false, features = ["rt", "net", "io-util"] }
1414
url = "2.5"
1515
rand = "0.8"

data-access-kit-replication/src/mysql.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ impl MySQLStreamDriver {
714714
zval.set_long(*value as i64);
715715
},
716716
ColumnValue::Set(value) => {
717-
// Convert SET bitmask to string values using column metadata
717+
// Convert SET bitmask to array of string values using column metadata
718718
if let Some(metadata) = column_metadata {
719719
if let Some(ref set_values) = metadata.set_string_values {
720720
let mut selected_values = Vec::new();
@@ -727,8 +727,27 @@ impl MySQLStreamDriver {
727727
}
728728
}
729729

730-
let result_string = selected_values.join(",");
731-
zval.set_string(&result_string, false)?;
730+
// Create PHP array instead of comma-separated string
731+
let zvals: Result<Vec<Zval>, PhpException> = selected_values.iter().map(|value| {
732+
let mut element = Zval::new();
733+
element.set_string(value, false)?;
734+
Ok(element)
735+
}).collect();
736+
737+
match zvals {
738+
Ok(array_zvals) => {
739+
if let Err(_) = zval.set_array(array_zvals) {
740+
// Fallback to comma-separated string on array error
741+
let result_string = selected_values.join(",");
742+
zval.set_string(&result_string, false)?;
743+
}
744+
}
745+
Err(_) => {
746+
// Fallback to comma-separated string on error
747+
let result_string = selected_values.join(",");
748+
zval.set_string(&result_string, false)?;
749+
}
750+
}
732751
} else {
733752
// Fallback to numeric value if no metadata
734753
zval.set_long(*value as i64);

data-access-kit-replication/test/StreamIntegrationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ public static function dataTypeProvider(): array
298298
['MEDIUMBLOB', 'X\'48656c6c6f204d656469756d\'', 'SGVsbG8gTWVkaXVt'], // "Hello Medium" in base64
299299
['LONGBLOB', 'X\'48656c6c6f204c6f6e67\'', 'SGVsbG8gTG9uZw=='], // "Hello Long" in base64
300300

301-
// Special String Types - these return numeric values due to binlog limitations
302-
['ENUM(\'red\',\'green\',\'blue\')', '\'red\'', 1], // ENUM returns 1-based index (string values not available in binlog metadata)
303-
['SET(\'read\',\'write\',\'execute\')', '\'read,write\'', 3], // SET returns bitmask (string values not available in binlog metadata)
301+
// Special String Types - now return actual string values with fix-enum-set-metadata branch
302+
['ENUM(\'red\',\'green\',\'blue\')', '\'red\'', 'red'], // ENUM returns actual string value
303+
['SET(\'read\',\'write\',\'execute\')', '\'read,write\'', ['read', 'write']], // SET returns array of strings
304304

305305
// Date and Time Data Types
306306
['DATE', '\'2024-01-15\'', '2024-01-15'],

0 commit comments

Comments
 (0)