Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
56 changes: 55 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ my_bitflags! {
UnknownMariadbCapabilityFlags,
u32,

/// Mariadb client capability flags
/// MariaDB client capability flags
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
pub struct MariadbCapabilities: u32 {
/// Permits feedback during long-running operations
Expand Down Expand Up @@ -431,6 +431,20 @@ my_bitflags! {
}
}

my_bitflags! {
StmtBulkExecuteFlags,
#[error("Unknown flags in the raw value of StmtBulkExecuteParamsFlags (raw={0:b})")]
UnknownStmtBulkExecuteParamsFlags,
u16,

/// MySql stmt execute params flags.
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
pub struct StmtBulkExecuteFlags: u16 {
const SEND_UNIT_RESULTS = 64_u16;
const SEND_TYPES_TO_SERVER = 128_u16;
}
}

my_bitflags! {
ColumnFlags,
#[error("Unknown flags in the raw value of ColumnFlags (raw={0:b})")]
Expand Down Expand Up @@ -528,6 +542,46 @@ pub enum Command {
COM_BINLOG_DUMP_GTID,
COM_RESET_CONNECTION,
COM_END,
COM_STMT_BULK_EXECUTE = 0xfa_u8,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[error("Unknown MariaDB bulk execute parameter value indicator {}", _0)]
pub struct UnknownMariadbBulkIndicator(pub u8);

/// MariaDB bulk execute parameter value indicators
#[allow(non_camel_case_types)]
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
#[repr(u8)]
pub enum MariadbBulkIndicator {
/// No special indicator, normal value
BULK_INDICATOR_NONE = 0x00_u8,
/// NULL value
BULK_INDICATOR_NULL = 0x01_u8,
/// For INSERT/UPDATE, value is default. Not used
BULK_INDICATOR_DEFAULT = 0x02_u8,
/// Value is default for insert, Is ignored for update. Not used.
BULK_INDICATOR_IGNORE = 0x03_u8,
}

impl From<MariadbBulkIndicator> for u8 {
fn from(x: MariadbBulkIndicator) -> u8 {
x as u8
}
}

impl TryFrom<u8> for MariadbBulkIndicator {
type Error = UnknownMariadbBulkIndicator;

fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0x00 => Ok(Self::BULK_INDICATOR_NONE),
0x01 => Ok(Self::BULK_INDICATOR_NULL),
0x02 => Ok(Self::BULK_INDICATOR_DEFAULT),
0x03 => Ok(Self::BULK_INDICATOR_IGNORE),
x => Err(UnknownMariadbBulkIndicator(x)),
}
}
}

/// Type of state change information (part of MySql's Ok packet).
Expand Down
44 changes: 44 additions & 0 deletions src/misc/raw/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ impl<T: Clone, U> Deref for Seq<'_, T, U> {
}
}

impl<T: Clone, U> Seq<'static, T, U> {
pub fn empty() -> Seq<'static, T, U> {
Self(Cow::Borrowed(&[]), PhantomData)
}
}

impl<'a, T: Clone, U> Seq<'a, T, U> {
pub fn new(s: impl Into<Cow<'a, [T]>>) -> Self {
Self(s.into(), PhantomData)
Expand Down Expand Up @@ -111,6 +117,44 @@ pub trait SeqRepr {
T: MyDeserialize<'de, Ctx = ()>;
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Unknown;

/// Unknown number of elements.
impl SeqRepr for Unknown {
const MAX_LEN: usize = usize::MAX;
const SIZE: Option<usize> = None;
type Ctx = usize;

fn serialize<T: MySerialize>(seq: &[T], buf: &mut Vec<u8>) {
for x in seq.iter() {
x.serialize(&mut *buf);
}
}

fn deserialize<'de, T>(len: Self::Ctx, buf: &mut ParseBuf<'de>) -> io::Result<Cow<'de, [T]>>
where
T: Clone,
T: MyDeserialize<'de, Ctx = ()>,
{
let mut seq = Vec::with_capacity(len);
match T::SIZE {
Some(count) => {
let mut buf: ParseBuf<'_> = buf.parse(count * len)?;
for _ in 0..len {
seq.push(buf.parse(())?);
}
}
None => {
for _ in 0..len {
seq.push(buf.parse(())?);
}
}
}
Ok(Cow::Owned(seq))
}
}

macro_rules! impl_seq_repr {
($t:ty, $name:ident) => {
impl SeqRepr for $name {
Expand Down
Loading