mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-03 07:45:30 +00:00
remove unused imports
This commit is contained in:
parent
6924b4fe6d
commit
c14338d329
@ -32,6 +32,7 @@ pub trait Connect: Connection {
|
||||
}
|
||||
|
||||
mod internal {
|
||||
#[allow(dead_code)]
|
||||
pub enum MaybeOwnedConnection<'c, C>
|
||||
where
|
||||
C: super::Connect,
|
||||
@ -40,6 +41,7 @@ mod internal {
|
||||
Owned(super::PoolConnection<C>),
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub enum ConnectionSource<'c, C>
|
||||
where
|
||||
C: super::Connect,
|
||||
@ -55,6 +57,7 @@ impl<'c, C> ConnectionSource<'c, C>
|
||||
where
|
||||
C: Connect,
|
||||
{
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn resolve_by_ref(&mut self) -> crate::Result<&'_ mut C> {
|
||||
if let ConnectionSource::Pool(pool) = self {
|
||||
*self =
|
||||
|
@ -53,6 +53,7 @@ pub enum Error {
|
||||
}
|
||||
|
||||
impl Error {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn decode<E>(err: E) -> Self
|
||||
where
|
||||
E: StdError + Send + Sync + 'static,
|
||||
|
@ -3,7 +3,6 @@
|
||||
#![forbid(unsafe_code)]
|
||||
#![recursion_limit = "512"]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![allow(unused)]
|
||||
|
||||
#[macro_use]
|
||||
pub mod error;
|
||||
|
@ -1,25 +1,20 @@
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::io;
|
||||
use std::sync::Arc;
|
||||
use std::ops::Range;
|
||||
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use futures_core::future::BoxFuture;
|
||||
use sha1::Sha1;
|
||||
use std::net::Shutdown;
|
||||
|
||||
use crate::connection::{Connect, Connection};
|
||||
use crate::io::{Buf, BufMut, BufStream, MaybeTlsStream};
|
||||
use crate::mysql::error::MySqlError;
|
||||
use crate::mysql::protocol::{
|
||||
AuthPlugin, AuthSwitch, Capabilities, ComPing, Decode, Encode, EofPacket, ErrPacket, Handshake,
|
||||
HandshakeResponse, OkPacket, SslRequest,
|
||||
AuthPlugin, AuthSwitch, Capabilities, ComPing, Decode, Handshake,
|
||||
HandshakeResponse,
|
||||
};
|
||||
use crate::mysql::stream::MySqlStream;
|
||||
use crate::mysql::util::xor_eq;
|
||||
use crate::mysql::{rsa, tls};
|
||||
use crate::executor::Executor;
|
||||
use crate::url::Url;
|
||||
use std::ops::Range;
|
||||
|
||||
// Size before a packet is split
|
||||
pub(super) const MAX_PACKET_SIZE: u32 = 1024;
|
||||
@ -191,7 +186,6 @@ async fn establish(stream: &mut MySqlStream, url: &Url) -> crate::Result<()> {
|
||||
loop {
|
||||
// After sending the handshake response with our assumed auth method the server
|
||||
// will send OK, fail, or tell us to change auth methods
|
||||
let capabilities = stream.capabilities;
|
||||
let packet = stream.receive().await?;
|
||||
|
||||
match packet[0] {
|
||||
@ -238,7 +232,7 @@ async fn establish(stream: &mut MySqlStream, url: &Url) -> crate::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
unk => {
|
||||
_ => {
|
||||
return stream.handle_unexpected();
|
||||
}
|
||||
}
|
||||
|
@ -60,8 +60,6 @@ impl<'c, 'q> Cursor<'c, 'q> for MySqlCursor<'c, 'q> {
|
||||
async fn next<'a, 'c: 'a, 'q: 'a>(
|
||||
cursor: &'a mut MySqlCursor<'c, 'q>,
|
||||
) -> crate::Result<Option<MySqlRow<'a>>> {
|
||||
println!("[cursor::next]");
|
||||
|
||||
let mut conn = cursor.source.resolve_by_ref().await?;
|
||||
|
||||
// The first time [next] is called we need to actually execute our
|
||||
@ -79,8 +77,7 @@ async fn next<'a, 'c: 'a, 'q: 'a>(
|
||||
};
|
||||
|
||||
loop {
|
||||
let mut packet_id = conn.stream.receive().await?[0];
|
||||
println!("[cursor::next/iter] {:x}", packet_id);
|
||||
let packet_id = conn.stream.receive().await?[0];
|
||||
match packet_id {
|
||||
// OK or EOF packet
|
||||
0x00 | 0xFE
|
||||
|
@ -1,26 +1,22 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use futures_core::future::BoxFuture;
|
||||
use futures_core::stream::BoxStream;
|
||||
|
||||
use crate::cursor::Cursor;
|
||||
use crate::describe::{Column, Describe};
|
||||
use crate::executor::{Execute, Executor, RefExecutor};
|
||||
use crate::mysql::protocol::{
|
||||
Status,
|
||||
self, Capabilities, ColumnCount, ColumnDefinition, ComQuery, ComStmtExecute, ComStmtPrepare,
|
||||
ComStmtPrepareOk, Decode, EofPacket, ErrPacket, FieldFlags, OkPacket, Row, TypeId,
|
||||
self, ColumnDefinition, ComQuery, ComStmtExecute, ComStmtPrepare,
|
||||
ComStmtPrepareOk, Decode, FieldFlags,
|
||||
};
|
||||
use crate::mysql::{
|
||||
MySql, MySqlArguments, MySqlConnection, MySqlCursor, MySqlError, MySqlRow, MySqlTypeInfo,
|
||||
MySql, MySqlArguments, MySqlCursor, MySqlTypeInfo,
|
||||
};
|
||||
|
||||
impl super::MySqlConnection {
|
||||
async fn wait_until_ready(&mut self) -> crate::Result<()> {
|
||||
if !self.is_ready {
|
||||
loop {
|
||||
let mut packet_id = self.stream.receive().await?[0];
|
||||
let packet_id = self.stream.receive().await?[0];
|
||||
match packet_id {
|
||||
0xFE if self.stream.packet().len() < 0xFF_FF_FF => {
|
||||
// OK or EOF packet
|
||||
|
@ -8,8 +8,8 @@ use crate::mysql::protocol::{Capabilities, Decode, Status};
|
||||
// https://mariadb.com/kb/en/eof_packet/
|
||||
#[derive(Debug)]
|
||||
pub struct EofPacket {
|
||||
warnings: u16,
|
||||
status: Status,
|
||||
pub warnings: u16,
|
||||
pub status: Status,
|
||||
}
|
||||
|
||||
impl Decode for EofPacket {
|
||||
|
@ -1,16 +1,11 @@
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::str::{from_utf8, Utf8Error};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::decode::Decode;
|
||||
use crate::error::UnexpectedNullError;
|
||||
use crate::mysql::io::BufExt;
|
||||
use crate::mysql::protocol;
|
||||
use crate::mysql::MySql;
|
||||
use crate::row::{ColumnIndex, Row};
|
||||
use crate::types::Type;
|
||||
use byteorder::LittleEndian;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MySqlValue<'c> {
|
||||
@ -49,7 +44,7 @@ impl<'c> Row<'c> for MySqlRow<'c> {
|
||||
{
|
||||
let index = index.resolve(self)?;
|
||||
|
||||
Ok(self.row.get(index).map(|mut buf| {
|
||||
Ok(self.row.get(index).map(|buf| {
|
||||
if self.binary {
|
||||
MySqlValue::Binary(buf)
|
||||
} else {
|
||||
|
@ -169,13 +169,11 @@ impl MySqlStream {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn maybe_handle_eof(&mut self) -> crate::Result<bool> {
|
||||
pub(crate) fn maybe_handle_eof(&mut self) -> crate::Result<Option<EofPacket>> {
|
||||
if !self.capabilities.contains(Capabilities::DEPRECATE_EOF) {
|
||||
let _eof = EofPacket::decode(self.packet())?;
|
||||
|
||||
Ok(true)
|
||||
Ok(Some(EofPacket::decode(self.packet())?))
|
||||
} else {
|
||||
Ok(false)
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,47 +1,44 @@
|
||||
use std::borrow::Cow;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::mysql::protocol::{Capabilities, SslRequest};
|
||||
use crate::mysql::stream::MySqlStream;
|
||||
use crate::url::Url;
|
||||
|
||||
#[cfg_attr(not(feature = "tls"), allow(unused_variables))]
|
||||
pub(super) async fn upgrade_if_needed(stream: &mut MySqlStream, url: &Url) -> crate::Result<()> {
|
||||
#[cfg_attr(not(feature = "tls"), allow(unused_imports))]
|
||||
use crate::mysql::protocol::Capabilities;
|
||||
|
||||
let ca_file = url.param("ssl-ca");
|
||||
|
||||
let ssl_mode = url.param("ssl-mode");
|
||||
|
||||
let supports_tls = stream.capabilities.contains(Capabilities::SSL);
|
||||
|
||||
// https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode
|
||||
match ssl_mode.as_deref() {
|
||||
Some("DISABLED") => {}
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
Some("PREFERRED") | None if !supports_tls => {}
|
||||
Some("PREFERRED") | None if !stream.capabilities.contains(Capabilities::SSL) => {}
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
Some("PREFERRED") => {
|
||||
if let Err(error) = try_upgrade(stream, &url, None, true).await {
|
||||
if let Err(_error) = try_upgrade(stream, &url, None, true).await {
|
||||
// TLS upgrade failed; fall back to a normal connection
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
None => {
|
||||
if let Err(error) = try_upgrade(stream, &url, ca_file.as_deref(), true).await {
|
||||
if let Err(_error) = try_upgrade(stream, &url, ca_file.as_deref(), true).await {
|
||||
// TLS upgrade failed; fall back to a normal connection
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
Some(mode @ "REQUIRED") | Some(mode @ "VERIFY_CA") | Some(mode @ "VERIFY_IDENTITY")
|
||||
if !supports_tls =>
|
||||
Some("REQUIRED") | Some("VERIFY_CA") | Some("VERIFY_IDENTITY")
|
||||
if !stream.capabilities.contains(Capabilities::SSL) =>
|
||||
{
|
||||
return Err(tls_err!("server does not support TLS").into());
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
Some(mode @ "VERIFY_CA") | Some(mode @ "VERIFY_IDENTITY") if ca_file.is_none() => {
|
||||
Some("VERIFY_CA") | Some("VERIFY_IDENTITY") if ca_file.is_none() => {
|
||||
return Err(
|
||||
tls_err!("`ssl-mode` of {:?} requires `ssl-ca` to be set", ssl_mode).into(),
|
||||
);
|
||||
@ -93,6 +90,7 @@ async fn try_upgrade(
|
||||
ca_file: Option<&str>,
|
||||
accept_invalid_hostnames: bool,
|
||||
) -> crate::Result<()> {
|
||||
use crate::mysql::protocol::{SslRequest};
|
||||
use crate::runtime::fs;
|
||||
|
||||
use async_native_tls::{Certificate, TlsConnector};
|
||||
|
@ -2,7 +2,6 @@ use std::convert::TryInto;
|
||||
|
||||
use crate::decode::Decode;
|
||||
use crate::encode::Encode;
|
||||
use crate::error::UnexpectedNullError;
|
||||
use crate::mysql::protocol::TypeId;
|
||||
use crate::mysql::types::MySqlTypeInfo;
|
||||
use crate::mysql::{MySql, MySqlValue};
|
||||
|
@ -2,7 +2,6 @@ use byteorder::LittleEndian;
|
||||
|
||||
use crate::decode::Decode;
|
||||
use crate::encode::Encode;
|
||||
use crate::error::UnexpectedNullError;
|
||||
use crate::mysql::io::{BufExt, BufMutExt};
|
||||
use crate::mysql::protocol::TypeId;
|
||||
use crate::mysql::types::MySqlTypeInfo;
|
||||
|
@ -4,7 +4,6 @@ use byteorder::{LittleEndian, ReadBytesExt};
|
||||
|
||||
use crate::decode::Decode;
|
||||
use crate::encode::Encode;
|
||||
use crate::error::UnexpectedNullError;
|
||||
use crate::mysql::protocol::TypeId;
|
||||
use crate::mysql::types::MySqlTypeInfo;
|
||||
use crate::mysql::{MySql, MySqlValue};
|
||||
|
@ -5,7 +5,6 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
use crate::decode::Decode;
|
||||
use crate::encode::Encode;
|
||||
use crate::error::UnexpectedNullError;
|
||||
use crate::mysql::protocol::TypeId;
|
||||
use crate::mysql::types::MySqlTypeInfo;
|
||||
use crate::mysql::{MySql, MySqlValue};
|
||||
@ -20,7 +19,7 @@ impl Type<MySql> for i8 {
|
||||
|
||||
impl Encode<MySql> for i8 {
|
||||
fn encode(&self, buf: &mut Vec<u8>) {
|
||||
buf.write_i8(*self);
|
||||
let _ = buf.write_i8(*self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +44,7 @@ impl Type<MySql> for i16 {
|
||||
|
||||
impl Encode<MySql> for i16 {
|
||||
fn encode(&self, buf: &mut Vec<u8>) {
|
||||
buf.write_i16::<LittleEndian>(*self);
|
||||
let _ = buf.write_i16::<LittleEndian>(*self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +69,7 @@ impl Type<MySql> for i32 {
|
||||
|
||||
impl Encode<MySql> for i32 {
|
||||
fn encode(&self, buf: &mut Vec<u8>) {
|
||||
buf.write_i32::<LittleEndian>(*self);
|
||||
let _ = buf.write_i32::<LittleEndian>(*self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +94,7 @@ impl Type<MySql> for i64 {
|
||||
|
||||
impl Encode<MySql> for i64 {
|
||||
fn encode(&self, buf: &mut Vec<u8>) {
|
||||
buf.write_i64::<LittleEndian>(*self);
|
||||
let _ = buf.write_i64::<LittleEndian>(*self);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ use byteorder::LittleEndian;
|
||||
|
||||
use crate::decode::Decode;
|
||||
use crate::encode::Encode;
|
||||
use crate::error::UnexpectedNullError;
|
||||
use crate::mysql::io::{BufExt, BufMutExt};
|
||||
use crate::mysql::protocol::TypeId;
|
||||
use crate::mysql::types::MySqlTypeInfo;
|
||||
|
@ -5,7 +5,6 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
use crate::decode::Decode;
|
||||
use crate::encode::Encode;
|
||||
use crate::error::UnexpectedNullError;
|
||||
use crate::mysql::protocol::TypeId;
|
||||
use crate::mysql::types::MySqlTypeInfo;
|
||||
use crate::mysql::{MySql, MySqlValue};
|
||||
@ -20,7 +19,7 @@ impl Type<MySql> for u8 {
|
||||
|
||||
impl Encode<MySql> for u8 {
|
||||
fn encode(&self, buf: &mut Vec<u8>) {
|
||||
buf.write_u8(*self);
|
||||
let _ = buf.write_u8(*self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +44,7 @@ impl Type<MySql> for u16 {
|
||||
|
||||
impl Encode<MySql> for u16 {
|
||||
fn encode(&self, buf: &mut Vec<u8>) {
|
||||
buf.write_u16::<LittleEndian>(*self);
|
||||
let _ = buf.write_u16::<LittleEndian>(*self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +69,7 @@ impl Type<MySql> for u32 {
|
||||
|
||||
impl Encode<MySql> for u32 {
|
||||
fn encode(&self, buf: &mut Vec<u8>) {
|
||||
buf.write_u32::<LittleEndian>(*self);
|
||||
let _ = buf.write_u32::<LittleEndian>(*self);
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +94,7 @@ impl Type<MySql> for u64 {
|
||||
|
||||
impl Encode<MySql> for u64 {
|
||||
fn encode(&self, buf: &mut Vec<u8>) {
|
||||
buf.write_u64::<LittleEndian>(*self);
|
||||
let _ = buf.write_u64::<LittleEndian>(*self);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user