From 9e35bf0892c008504ea390d029f747c907a20405 Mon Sep 17 00:00:00 2001 From: Kould <2435992353@qq.com> Date: Thu, 21 Mar 2024 21:42:31 +0800 Subject: [PATCH] fix: replace fill symbol '\0' -> ' ' for `LogicalType::Char` --- src/types/tuple.rs | 2 +- src/types/value.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/tuple.rs b/src/types/tuple.rs index 70a4d76a..a272ac6c 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -119,7 +119,7 @@ impl Tuple { let difference = len.saturating_sub(value_bytes.len()); bytes.append(&mut value_bytes); - bytes.append(&mut vec![0; difference]); + bytes.append(&mut vec![b' '; difference]); } else { bytes.append(&mut (value_bytes.len() as u32).encode_fixed_vec()); bytes.append(&mut value_bytes); diff --git a/src/types/value.rs b/src/types/value.rs index e2be7251..5cdacf81 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -443,7 +443,7 @@ impl DataValue { LogicalType::Char(_) => { // https://dev.mysql.com/doc/refman/8.0/en/char.html#:~:text=If%20a%20given%20value%20is%20stored%20into%20the%20CHAR(4)%20and%20VARCHAR(4)%20columns%2C%20the%20values%20retrieved%20from%20the%20columns%20are%20not%20always%20the%20same%20because%20trailing%20spaces%20are%20removed%20from%20CHAR%20columns%20upon%20retrieval.%20The%20following%20example%20illustrates%20this%20difference%3A let value = (!bytes.is_empty()).then(|| { - let last_non_zero_index = match bytes.iter().rposition(|&x| x != 0) { + let last_non_zero_index = match bytes.iter().rposition(|&x| x != b' ') { Some(index) => index + 1, None => 0, };