mysql: clean up protocol

This commit is contained in:
Ryan Leckey 2020-03-11 09:02:29 -07:00
parent 7a98253840
commit 27cd552a8c
24 changed files with 118 additions and 188 deletions

View file

@ -8,7 +8,7 @@ use sha1::Sha1;
use crate::connection::{Connect, Connection};
use crate::executor::Executor;
use crate::mysql::protocol::{
AuthPlugin, AuthSwitch, Capabilities, ComPing, Decode, Handshake, HandshakeResponse,
AuthPlugin, AuthSwitch, Capabilities, ComPing, Handshake, HandshakeResponse,
};
use crate::mysql::stream::MySqlStream;
use crate::mysql::util::xor_eq;
@ -149,7 +149,7 @@ async fn establish(stream: &mut MySqlStream, url: &Url) -> crate::Result<()> {
// Read a [Handshake] packet. When connecting to the database server, this is immediately
// received from the database server.
let handshake = Handshake::decode(stream.receive().await?)?;
let handshake = Handshake::read(stream.receive().await?)?;
let mut auth_plugin = handshake.auth_plugin;
let mut auth_plugin_data = handshake.auth_plugin_data;
@ -202,7 +202,7 @@ async fn establish(stream: &mut MySqlStream, url: &Url) -> crate::Result<()> {
// AUTH_SWITCH
0xFE => {
let auth = AuthSwitch::decode(packet)?;
let auth = AuthSwitch::read(packet)?;
auth_plugin = auth.auth_plugin;
auth_plugin_data = auth.auth_plugin_data;

View file

@ -6,7 +6,7 @@ use futures_core::future::BoxFuture;
use crate::connection::{ConnectionSource, MaybeOwnedConnection};
use crate::cursor::Cursor;
use crate::executor::Execute;
use crate::mysql::protocol::{ColumnCount, ColumnDefinition, Decode, Row, Status, TypeId};
use crate::mysql::protocol::{ColumnCount, ColumnDefinition, Row, Status, TypeId};
use crate::mysql::{MySql, MySqlArguments, MySqlConnection, MySqlRow};
use crate::pool::Pool;
@ -109,7 +109,7 @@ async fn next<'a, 'c: 'a, 'q: 'a>(
// At the start of the results we expect to see a
// COLUMN_COUNT followed by N COLUMN_DEF
let cc = ColumnCount::decode(conn.stream.packet())?;
let cc = ColumnCount::read(conn.stream.packet())?;
// We use these definitions to get the actual column types that is critical
// in parsing the rows coming back soon
@ -120,7 +120,7 @@ async fn next<'a, 'c: 'a, 'q: 'a>(
let mut column_names = HashMap::with_capacity(cc.columns as usize);
for i in 0..cc.columns {
let column = ColumnDefinition::decode(conn.stream.receive().await?)?;
let column = ColumnDefinition::read(conn.stream.receive().await?)?;
cursor.column_types.push(column.type_id);
@ -142,15 +142,12 @@ async fn next<'a, 'c: 'a, 'q: 'a>(
conn.stream.packet(),
&cursor.column_types,
&mut conn.current_row_values,
// TODO: Text mode
cursor.binary,
)?;
let row = MySqlRow {
row,
columns: Arc::clone(&cursor.column_names),
// TODO: Text mode
binary: cursor.binary,
};
return Ok(Some(row));

View file

@ -4,7 +4,7 @@ use crate::cursor::Cursor;
use crate::describe::{Column, Describe};
use crate::executor::{Execute, Executor, RefExecutor};
use crate::mysql::protocol::{
self, ColumnDefinition, ComQuery, ComStmtExecute, ComStmtPrepare, ComStmtPrepareOk, Decode,
self, ColumnDefinition, ComQuery, ComStmtExecute, ComStmtPrepare, ComStmtPrepareOk,
FieldFlags, Status,
};
use crate::mysql::{MySql, MySqlArguments, MySqlCursor, MySqlTypeInfo};
@ -49,12 +49,12 @@ impl super::MySqlConnection {
return self.stream.handle_err();
}
ComStmtPrepareOk::decode(packet)
ComStmtPrepareOk::read(packet)
}
async fn drop_column_defs(&mut self, count: usize) -> crate::Result<()> {
for _ in 0..count {
let _column = ColumnDefinition::decode(self.stream.receive().await?)?;
let _column = ColumnDefinition::read(self.stream.receive().await?)?;
}
if count > 0 {
@ -168,7 +168,7 @@ impl super::MySqlConnection {
let mut result_columns = Vec::with_capacity(stmt.columns as usize);
for _ in 0..stmt.params {
let param = ColumnDefinition::decode(self.stream.receive().await?)?;
let param = ColumnDefinition::read(self.stream.receive().await?)?;
param_types.push(MySqlTypeInfo::from_column_def(&param));
}
@ -177,7 +177,7 @@ impl super::MySqlConnection {
}
for _ in 0..stmt.columns {
let column = ColumnDefinition::decode(self.stream.receive().await?)?;
let column = ColumnDefinition::read(self.stream.receive().await?)?;
result_columns.push(Column::<MySql> {
type_info: MySqlTypeInfo::from_column_def(&column),

View file

@ -1,17 +1,15 @@
use byteorder::LittleEndian;
use crate::io::Buf;
use crate::mysql::protocol::{AuthPlugin, Capabilities, Decode, Status};
use crate::mysql::protocol::{AuthPlugin};
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_connection_phase_packets_protocol_auth_switch_request.html
#[derive(Debug)]
pub struct AuthSwitch {
pub auth_plugin: AuthPlugin,
pub auth_plugin_data: Box<[u8]>,
pub(crate) struct AuthSwitch {
pub(crate) auth_plugin: AuthPlugin,
pub(crate) auth_plugin_data: Box<[u8]>,
}
impl Decode for AuthSwitch {
fn decode(mut buf: &[u8]) -> crate::Result<Self>
impl AuthSwitch {
pub(crate) fn read(mut buf: &[u8]) -> crate::Result<Self>
where
Self: Sized,
{

View file

@ -1,16 +1,14 @@
use byteorder::LittleEndian;
use crate::io::Buf;
use crate::mysql::io::BufExt;
use crate::mysql::protocol::Decode;
#[derive(Debug)]
pub struct ColumnCount {
pub columns: u64,
}
impl Decode for ColumnCount {
fn decode(mut buf: &[u8]) -> crate::Result<Self> {
impl ColumnCount {
pub(crate) fn read(mut buf: &[u8]) -> crate::Result<Self> {
let columns = buf.get_uint_lenenc::<LittleEndian>()?.unwrap_or(0);
Ok(Self { columns })

View file

@ -2,7 +2,7 @@ use byteorder::LittleEndian;
use crate::io::Buf;
use crate::mysql::io::BufExt;
use crate::mysql::protocol::{Decode, FieldFlags, TypeId};
use crate::mysql::protocol::{FieldFlags, TypeId};
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_com_query_response_text_resultset_column_definition.html
// https://mariadb.com/kb/en/resultset/#column-definition-packet
@ -33,8 +33,8 @@ impl ColumnDefinition {
}
}
impl Decode for ColumnDefinition {
fn decode(mut buf: &[u8]) -> crate::Result<Self> {
impl ColumnDefinition {
pub(crate) fn read(mut buf: &[u8]) -> crate::Result<Self> {
// catalog : string<lenenc>
let catalog = buf.get_str_lenenc::<LittleEndian>()?;

View file

@ -1,7 +1,4 @@
use byteorder::LittleEndian;
use crate::io::BufMut;
use crate::mysql::io::BufMutExt;
use crate::mysql::protocol::{Capabilities, Encode};
// https://dev.mysql.com/doc/internals/en/com-ping.html

View file

@ -1,7 +1,4 @@
use byteorder::LittleEndian;
use crate::io::BufMut;
use crate::mysql::io::BufMutExt;
use crate::mysql::protocol::{Capabilities, Encode};
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_com_query.html

View file

@ -1,29 +0,0 @@
use byteorder::LittleEndian;
use crate::io::BufMut;
use crate::mysql::io::BufMutExt;
use crate::mysql::protocol::{Capabilities, Encode};
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/mysql__com_8h.html#a53f60000da139fc7d547db96635a2c02
#[derive(Debug, Copy, Clone)]
#[repr(u16)]
pub enum SetOption {
MultiStatementsOn = 0x00,
MultiStatementsOff = 0x01,
}
// https://dev.mysql.com/doc/internals/en/com-set-option.html
#[derive(Debug)]
pub struct ComSetOption {
pub option: SetOption,
}
impl Encode for ComSetOption {
fn encode(&self, buf: &mut Vec<u8>, _: Capabilities) {
// COM_SET_OPTION : int<1>
buf.put_u8(0x1a);
// option : int<2>
buf.put_u16::<LittleEndian>(self.option as u16);
}
}

View file

@ -1,7 +1,6 @@
use byteorder::LittleEndian;
use crate::io::BufMut;
use crate::mysql::io::BufMutExt;
use crate::mysql::protocol::{Capabilities, Encode};
use crate::mysql::types::MySqlTypeInfo;
@ -27,7 +26,7 @@ pub struct ComStmtExecute<'a> {
}
impl Encode for ComStmtExecute<'_> {
fn encode(&self, buf: &mut Vec<u8>, capabilities: Capabilities) {
fn encode(&self, buf: &mut Vec<u8>, _: Capabilities) {
// COM_STMT_EXECUTE : int<1>
buf.put_u8(0x17);

View file

@ -1,7 +1,4 @@
use byteorder::LittleEndian;
use crate::io::BufMut;
use crate::mysql::io::BufMutExt;
use crate::mysql::protocol::{Capabilities, Encode};
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_com_stmt_prepare.html

View file

@ -1,27 +1,25 @@
use byteorder::LittleEndian;
use crate::io::Buf;
use crate::mysql::io::BufExt;
use crate::mysql::protocol::Decode;
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_com_stmt_prepare.html#sect_protocol_com_stmt_prepare_response_ok
#[derive(Debug)]
pub struct ComStmtPrepareOk {
pub statement_id: u32,
pub(crate) struct ComStmtPrepareOk {
pub(crate) statement_id: u32,
/// Number of columns in the returned result set (or 0 if statement
/// does not return result set).
pub columns: u16,
pub(crate) columns: u16,
/// Number of prepared statement parameters ('?' placeholders).
pub params: u16,
pub(crate) params: u16,
/// Number of warnings.
pub warnings: u16,
pub(crate) warnings: u16,
}
impl Decode for ComStmtPrepareOk {
fn decode(mut buf: &[u8]) -> crate::Result<Self> {
impl ComStmtPrepareOk {
pub(crate) fn read(mut buf: &[u8]) -> crate::Result<Self> {
let header = buf.get_u8()?;
if header != 0x00 {

View file

@ -1,7 +0,0 @@
use std::io;
pub trait Decode {
fn decode(buf: &[u8]) -> crate::Result<Self>
where
Self: Sized;
}

View file

@ -1,12 +0,0 @@
use crate::io::BufMut;
use crate::mysql::protocol::Capabilities;
pub trait Encode {
fn encode(&self, buf: &mut Vec<u8>, capabilities: Capabilities);
}
impl Encode for &'_ [u8] {
fn encode(&self, buf: &mut Vec<u8>, _: Capabilities) {
buf.put_bytes(self);
}
}

View file

@ -1,8 +1,7 @@
use byteorder::LittleEndian;
use crate::io::Buf;
use crate::mysql::io::BufExt;
use crate::mysql::protocol::{Capabilities, Decode, Status};
use crate::mysql::protocol::{Status};
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_basic_eof_packet.html
// https://mariadb.com/kb/en/eof_packet/
@ -12,8 +11,8 @@ pub struct EofPacket {
pub status: Status,
}
impl Decode for EofPacket {
fn decode(mut buf: &[u8]) -> crate::Result<Self>
impl EofPacket {
pub(crate) fn read(mut buf: &[u8]) -> crate::Result<Self>
where
Self: Sized,
{

View file

@ -1,8 +1,7 @@
use byteorder::LittleEndian;
use crate::io::Buf;
use crate::mysql::io::BufExt;
use crate::mysql::protocol::{Capabilities, Decode, Status};
use crate::mysql::protocol::{Capabilities};
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_basic_err_packet.html
// https://mariadb.com/kb/en/err_packet/
@ -14,7 +13,7 @@ pub struct ErrPacket {
}
impl ErrPacket {
pub(crate) fn decode(mut buf: &[u8], capabilities: Capabilities) -> crate::Result<Self>
pub(crate) fn read(mut buf: &[u8], capabilities: Capabilities) -> crate::Result<Self>
where
Self: Sized,
{
@ -50,7 +49,7 @@ impl ErrPacket {
#[cfg(test)]
mod tests {
use super::{Capabilities, Decode, ErrPacket, Status};
use super::{Capabilities, ErrPacket};
const ERR_PACKETS_OUT_OF_ORDER: &[u8] = b"\xff\x84\x04Got packets out of order";
@ -58,7 +57,7 @@ mod tests {
#[test]
fn it_decodes_packets_out_of_order() {
let mut p = ErrPacket::decode(ERR_PACKETS_OUT_OF_ORDER, Capabilities::PROTOCOL_41).unwrap();
let p = ErrPacket::read(ERR_PACKETS_OUT_OF_ORDER, Capabilities::PROTOCOL_41).unwrap();
assert_eq!(&*p.error_message, "Got packets out of order");
assert_eq!(p.error_code, 1156);
@ -67,7 +66,7 @@ mod tests {
#[test]
fn it_decodes_ok_handshake() {
let mut p = ErrPacket::decode(ERR_HANDSHAKE_UNKNOWN_DB, Capabilities::PROTOCOL_41).unwrap();
let p = ErrPacket::read(ERR_HANDSHAKE_UNKNOWN_DB, Capabilities::PROTOCOL_41).unwrap();
assert_eq!(p.error_code, 1049);
assert_eq!(p.sql_state.as_deref(), Some("42000"));

View file

@ -1,24 +1,24 @@
use byteorder::LittleEndian;
use crate::io::Buf;
use crate::mysql::protocol::{AuthPlugin, Capabilities, Decode, Status};
use crate::mysql::protocol::{AuthPlugin, Capabilities, Status};
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_connection_phase_packets_protocol_handshake_v10.html
// https://mariadb.com/kb/en/connection/#initial-handshake-packet
#[derive(Debug)]
pub struct Handshake {
pub protocol_version: u8,
pub server_version: Box<str>,
pub connection_id: u32,
pub server_capabilities: Capabilities,
pub server_default_collation: u8,
pub status: Status,
pub auth_plugin: AuthPlugin,
pub auth_plugin_data: Box<[u8]>,
pub(crate) struct Handshake {
pub(crate) protocol_version: u8,
pub(crate) server_version: Box<str>,
pub(crate) connection_id: u32,
pub(crate) server_capabilities: Capabilities,
pub(crate) server_default_collation: u8,
pub(crate) status: Status,
pub(crate) auth_plugin: AuthPlugin,
pub(crate) auth_plugin_data: Box<[u8]>,
}
impl Decode for Handshake {
fn decode(mut buf: &[u8]) -> crate::Result<Self>
impl Handshake {
pub(crate) fn read(mut buf: &[u8]) -> crate::Result<Self>
where
Self: Sized,
{
@ -68,7 +68,7 @@ impl Decode for Handshake {
} else {
// capability_flags_3 : int<4>
let capabilities_3 = buf.get_u32::<LittleEndian>()?;
capabilities |= Capabilities::from_bits_truncate((capabilities_2 as u64) << 32);
capabilities |= Capabilities::from_bits_truncate((capabilities_3 as u64) << 32);
}
if capabilities.contains(Capabilities::SECURE_CONNECTION) {
@ -102,15 +102,15 @@ impl Decode for Handshake {
#[cfg(test)]
mod tests {
use super::{AuthPlugin, Capabilities, Decode, Handshake, Status};
use super::{AuthPlugin, Capabilities, Handshake, Status};
use matches::assert_matches;
const HANDSHAKE_MARIA_DB_10_4_7: &[u8] = b"\n5.5.5-10.4.7-MariaDB-1:10.4.7+maria~bionic\x00\x0b\x00\x00\x00t6L\\j\"dS\x00\xfe\xf7\x08\x02\x00\xff\x81\x15\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00U14Oph9\"<H5n\x00mysql_native_password\x00";
const HANDSHAKE_MYSQL_8_0_18: &[u8] = b"\n8.0.18\x00\x19\x00\x00\x00\x114aB0c\x06g\x00\xff\xff\xff\x02\x00\xff\xc7\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00tL\x03s\x0f[4\rl4. \x00caching_sha2_password\x00";
#[test]
fn it_decodes_handshake_mysql_8_0_18() {
let mut p = Handshake::decode(HANDSHAKE_MYSQL_8_0_18).unwrap();
fn it_reads_handshake_mysql_8_0_18() {
let mut p = Handshake::read(HANDSHAKE_MYSQL_8_0_18).unwrap();
assert_eq!(p.protocol_version, 10);
@ -157,8 +157,8 @@ mod tests {
}
#[test]
fn it_decodes_handshake_mariadb_10_4_7() {
let mut p = Handshake::decode(HANDSHAKE_MARIA_DB_10_4_7).unwrap();
fn it_reads_handshake_mariadb_10_4_7() {
let mut p = Handshake::read(HANDSHAKE_MARIA_DB_10_4_7).unwrap();
assert_eq!(p.protocol_version, 10);

View file

@ -1,38 +1,26 @@
// There is much to the protocol that is not yet used. As we mature we'll be trimming
// the size of this module to exactly what is necessary.
#![allow(unused)]
mod decode;
mod encode;
pub use decode::Decode;
pub use encode::Encode;
mod auth_plugin;
mod capabilities;
mod field;
mod status;
mod r#type;
pub use auth_plugin::AuthPlugin;
pub use capabilities::Capabilities;
pub use field::FieldFlags;
pub use r#type::TypeId;
pub use status::Status;
pub(crate) use auth_plugin::AuthPlugin;
pub(crate) use capabilities::Capabilities;
pub(crate) use field::FieldFlags;
pub(crate) use r#type::TypeId;
pub(crate) use status::Status;
mod com_ping;
mod com_query;
mod com_set_option;
mod com_stmt_execute;
mod com_stmt_prepare;
mod handshake;
pub use com_ping::ComPing;
pub use com_query::ComQuery;
pub use com_set_option::{ComSetOption, SetOption};
pub use com_stmt_execute::{ComStmtExecute, Cursor};
pub use com_stmt_prepare::ComStmtPrepare;
pub use handshake::Handshake;
pub(crate) use com_ping::ComPing;
pub(crate) use com_query::ComQuery;
pub(crate) use com_stmt_execute::{ComStmtExecute, Cursor};
pub(crate) use com_stmt_prepare::ComStmtPrepare;
pub(crate) use handshake::Handshake;
mod auth_switch;
mod column_count;
@ -43,15 +31,29 @@ mod err;
mod handshake_response;
mod ok;
mod row;
#[cfg_attr(not(feature = "tls"), allow(unused_imports, dead_code))]
mod ssl_request;
pub use auth_switch::AuthSwitch;
pub use column_count::ColumnCount;
pub use column_def::ColumnDefinition;
pub use com_stmt_prepare_ok::ComStmtPrepareOk;
pub use eof::EofPacket;
pub use err::ErrPacket;
pub use handshake_response::HandshakeResponse;
pub use ok::OkPacket;
pub use row::Row;
pub use ssl_request::SslRequest;
pub(crate) use auth_switch::AuthSwitch;
pub(crate) use column_count::ColumnCount;
pub(crate) use column_def::ColumnDefinition;
pub(crate) use com_stmt_prepare_ok::ComStmtPrepareOk;
pub(crate) use eof::EofPacket;
pub(crate) use err::ErrPacket;
pub(crate) use handshake_response::HandshakeResponse;
pub(crate) use ok::OkPacket;
pub(crate) use row::Row;
#[cfg_attr(not(feature = "tls"), allow(unused_imports, dead_code))]
pub(crate) use ssl_request::SslRequest;
pub(crate) trait Encode {
fn encode(&self, buf: &mut Vec<u8>, capabilities: Capabilities);
}
impl Encode for &'_ [u8] {
fn encode(&self, buf: &mut Vec<u8>, _: Capabilities) {
use crate::io::BufMut;
buf.put_bytes(self);
}
}

View file

@ -2,21 +2,21 @@ use byteorder::LittleEndian;
use crate::io::Buf;
use crate::mysql::io::BufExt;
use crate::mysql::protocol::{Capabilities, Decode, Status};
use crate::mysql::protocol::{Status};
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_basic_ok_packet.html
// https://mariadb.com/kb/en/ok_packet/
#[derive(Debug)]
pub struct OkPacket {
pub affected_rows: u64,
pub last_insert_id: u64,
pub status: Status,
pub warnings: u16,
pub info: Box<str>,
pub(crate) struct OkPacket {
pub(crate) affected_rows: u64,
pub(crate) last_insert_id: u64,
pub(crate) status: Status,
pub(crate) warnings: u16,
pub(crate) info: Box<str>,
}
impl Decode for OkPacket {
fn decode(mut buf: &[u8]) -> crate::Result<Self>
impl OkPacket {
pub(crate) fn read(mut buf: &[u8]) -> crate::Result<Self>
where
Self: Sized,
{
@ -46,13 +46,13 @@ impl Decode for OkPacket {
#[cfg(test)]
mod tests {
use super::{Capabilities, Decode, OkPacket, Status};
use super::{OkPacket, Status};
const OK_HANDSHAKE: &[u8] = b"\x00\x00\x00\x02@\x00\x00";
#[test]
fn it_decodes_ok_handshake() {
let mut p = OkPacket::decode(OK_HANDSHAKE).unwrap();
let p = OkPacket::read(OK_HANDSHAKE).unwrap();
assert_eq!(p.affected_rows, 0);
assert_eq!(p.last_insert_id, 0);

View file

@ -3,21 +3,20 @@ use std::ops::Range;
use byteorder::{ByteOrder, LittleEndian};
use crate::io::Buf;
use crate::mysql::io::BufExt;
use crate::mysql::protocol::{Decode, TypeId};
use crate::mysql::protocol::{TypeId};
pub struct Row<'c> {
pub(crate) struct Row<'c> {
buffer: &'c [u8],
values: &'c [Option<Range<usize>>],
binary: bool,
pub(crate) binary: bool,
}
impl<'c> Row<'c> {
pub fn len(&self) -> usize {
pub(crate) fn len(&self) -> usize {
self.values.len()
}
pub fn get(&self, index: usize) -> Option<&'c [u8]> {
pub(crate) fn get(&self, index: usize) -> Option<&'c [u8]> {
let range = self.values[index].as_ref()?;
Some(&self.buffer[(range.start as usize)..(range.end as usize)])
@ -54,13 +53,13 @@ fn get_lenenc(buf: &[u8]) -> (usize, Option<usize>) {
}
impl<'c> Row<'c> {
pub fn read(
pub(crate) fn read(
mut buf: &'c [u8],
columns: &[TypeId],
values: &'c mut Vec<Option<Range<usize>>>,
binary: bool,
) -> crate::Result<Self> {
let mut buffer = &*buf;
let buffer = &*buf;
values.clear();
values.reserve(columns.len());
@ -68,7 +67,7 @@ impl<'c> Row<'c> {
if !binary {
let mut index = 0;
for column_idx in 0..columns.len() {
for _ in 0..columns.len() {
let (len_size, size) = get_lenenc(&buf[index..]);
if let Some(size) = size {
@ -77,7 +76,7 @@ impl<'c> Row<'c> {
values.push(None);
}
index += (len_size + size.unwrap_or_default());
index += len_size + size.unwrap_or_default();
}
return Ok(Self {

View file

@ -1,8 +1,7 @@
use byteorder::LittleEndian;
use crate::io::BufMut;
use crate::mysql::io::BufMutExt;
use crate::mysql::protocol::{AuthPlugin, Capabilities, Encode};
use crate::mysql::protocol::{Capabilities, Encode};
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_connection_phase_packets_protocol_handshake_response.html
// https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::SSLRequest

View file

@ -49,7 +49,7 @@ type_id_consts! {
pub const SMALL_INT: TypeId = TypeId(2);
pub const INT: TypeId = TypeId(3);
pub const BIG_INT: TypeId = TypeId(8);
pub const MEDIUM_INT: TypeId = TypeId(9);
// pub const MEDIUM_INT: TypeId = TypeId(9);
// Numeric: FLOAT, DOUBLE
pub const FLOAT: TypeId = TypeId(4);

View file

@ -28,7 +28,6 @@ impl<'c> TryFrom<Option<MySqlValue<'c>>> for MySqlValue<'c> {
pub struct MySqlRow<'c> {
pub(super) row: protocol::Row<'c>,
pub(super) columns: Arc<HashMap<Box<str>, u16>>,
pub(super) binary: bool,
}
impl<'c> Row<'c> for MySqlRow<'c> {
@ -45,7 +44,7 @@ impl<'c> Row<'c> for MySqlRow<'c> {
let index = index.resolve(self)?;
Ok(self.row.get(index).map(|buf| {
if self.binary {
if self.row.binary {
MySqlValue::Binary(buf)
} else {
MySqlValue::Text(buf)

View file

@ -3,7 +3,7 @@ use std::net::Shutdown;
use byteorder::{ByteOrder, LittleEndian};
use crate::io::{Buf, BufMut, BufStream, MaybeTlsStream};
use crate::mysql::protocol::{Capabilities, Decode, Encode, EofPacket, ErrPacket, OkPacket};
use crate::mysql::protocol::{Capabilities, Encode, EofPacket, ErrPacket, OkPacket};
use crate::mysql::MySqlError;
use crate::url::Url;
@ -163,7 +163,7 @@ impl MySqlStream {
impl MySqlStream {
pub(crate) async fn maybe_receive_eof(&mut self) -> crate::Result<()> {
if !self.capabilities.contains(Capabilities::DEPRECATE_EOF) {
let _eof = EofPacket::decode(self.receive().await?)?;
let _eof = EofPacket::read(self.receive().await?)?;
}
Ok(())
@ -171,7 +171,7 @@ impl MySqlStream {
pub(crate) fn maybe_handle_eof(&mut self) -> crate::Result<Option<EofPacket>> {
if !self.capabilities.contains(Capabilities::DEPRECATE_EOF) && self.packet()[0] == 0xFE {
Ok(Some(EofPacket::decode(self.packet())?))
Ok(Some(EofPacket::read(self.packet())?))
} else {
Ok(None)
}
@ -182,10 +182,10 @@ impl MySqlStream {
}
pub(crate) fn handle_err<T>(&mut self) -> crate::Result<T> {
Err(MySqlError(ErrPacket::decode(self.packet(), self.capabilities)?).into())
Err(MySqlError(ErrPacket::read(self.packet(), self.capabilities)?).into())
}
pub(crate) fn handle_ok(&mut self) -> crate::Result<OkPacket> {
OkPacket::decode(self.packet())
OkPacket::read(self.packet())
}
}