-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix false positive truncation for varchar
- Loading branch information
Showing
9 changed files
with
117 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,65 +1,68 @@ | ||
use crate::{IntoParameter, parameter::{VarCharSlice, VarCharBox}}; | ||
|
||
/// Newtype wrapper intend to be used around `String`s or `str` slices to bind them always as narrow | ||
/// text independent of wether the `narrow` feature is set or not. | ||
pub struct Narrow<T>(pub T); | ||
|
||
impl<'a> IntoParameter for Narrow<&'a str> { | ||
type Parameter = VarCharSlice<'a>; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
VarCharSlice::new(self.0.as_bytes()) | ||
} | ||
} | ||
|
||
impl<'a> IntoParameter for Narrow<Option<&'a str>> { | ||
type Parameter = VarCharSlice<'a>; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
match self.0 { | ||
Some(str) => Narrow(str).into_parameter(), | ||
None => VarCharSlice::NULL, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> IntoParameter for Option<Narrow<&'a str>> { | ||
type Parameter = VarCharSlice<'a>; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
match self { | ||
Some(str) => Narrow(str.0).into_parameter(), | ||
None => VarCharSlice::NULL, | ||
} | ||
} | ||
} | ||
|
||
impl IntoParameter for Narrow<String> { | ||
type Parameter = VarCharBox; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
VarCharBox::from_string(self.0) | ||
} | ||
} | ||
|
||
impl IntoParameter for Narrow<Option<String>> { | ||
type Parameter = VarCharBox; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
match self.0 { | ||
Some(str) => Narrow(str).into_parameter(), | ||
None => VarCharBox::null(), | ||
} | ||
} | ||
} | ||
|
||
impl IntoParameter for Option<Narrow<String>> { | ||
type Parameter = VarCharBox; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
match self { | ||
Some(str) => Narrow(str.0).into_parameter(), | ||
None => VarCharBox::null(), | ||
} | ||
} | ||
} | ||
use crate::{ | ||
parameter::{VarCharBox, VarCharSlice}, | ||
IntoParameter, | ||
}; | ||
|
||
/// Newtype wrapper intend to be used around `String`s or `str` slices to bind them always as narrow | ||
/// text independent of wether the `narrow` feature is set or not. | ||
pub struct Narrow<T>(pub T); | ||
|
||
impl<'a> IntoParameter for Narrow<&'a str> { | ||
type Parameter = VarCharSlice<'a>; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
VarCharSlice::new(self.0.as_bytes()) | ||
} | ||
} | ||
|
||
impl<'a> IntoParameter for Narrow<Option<&'a str>> { | ||
type Parameter = VarCharSlice<'a>; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
match self.0 { | ||
Some(str) => Narrow(str).into_parameter(), | ||
None => VarCharSlice::NULL, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> IntoParameter for Option<Narrow<&'a str>> { | ||
type Parameter = VarCharSlice<'a>; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
match self { | ||
Some(str) => Narrow(str.0).into_parameter(), | ||
None => VarCharSlice::NULL, | ||
} | ||
} | ||
} | ||
|
||
impl IntoParameter for Narrow<String> { | ||
type Parameter = VarCharBox; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
VarCharBox::from_string(self.0) | ||
} | ||
} | ||
|
||
impl IntoParameter for Narrow<Option<String>> { | ||
type Parameter = VarCharBox; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
match self.0 { | ||
Some(str) => Narrow(str).into_parameter(), | ||
None => VarCharBox::null(), | ||
} | ||
} | ||
} | ||
|
||
impl IntoParameter for Option<Narrow<String>> { | ||
type Parameter = VarCharBox; | ||
|
||
fn into_parameter(self) -> Self::Parameter { | ||
match self { | ||
Some(str) => Narrow(str.0).into_parameter(), | ||
None => VarCharBox::null(), | ||
} | ||
} | ||
} |
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
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