mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-29 21:00:54 +00:00
Test Compile
This commit is contained in:
parent
0aa64f8ebb
commit
91fc27a5b8
@ -19,7 +19,7 @@ postgres = []
|
||||
mariadb = []
|
||||
|
||||
[dependencies]
|
||||
# bitflags = "1.1.0"
|
||||
bitflags = "1.1.0"
|
||||
byteorder = { version = "1.3.2", default-features = false }
|
||||
bytes = "0.4.12"
|
||||
crossbeam-queue = "0.1.2"
|
||||
|
||||
@ -11,7 +11,9 @@ pub enum Error {
|
||||
/// Some reasons for this to be caused:
|
||||
///
|
||||
/// - [io::ErrorKind::ConnectionRefused] - Database backend is most likely behind a firewall.
|
||||
///
|
||||
/// - [io::ErrorKind::ConnectionReset] - Database backend dropped the client connection (perhaps from an administrator action).
|
||||
///
|
||||
/// - [io::ErrorKind::InvalidData] - Unexpected or invalid data was encountered. This would indicate that we received data that we were not
|
||||
/// expecting or it was in a format we did not understand. This generally means either there is a programming error in a SQLx driver or
|
||||
/// something with the connection or the database backend itself is corrupted. Additional details are provided along with the
|
||||
|
||||
@ -2,11 +2,8 @@
|
||||
#![allow(clippy::needless_lifetimes)]
|
||||
#![allow(unused)]
|
||||
|
||||
// #[macro_use]
|
||||
// extern crate bitflags;
|
||||
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate test;
|
||||
@ -35,6 +32,8 @@ pub mod postgres;
|
||||
#[cfg(feature = "postgres")]
|
||||
pub use self::postgres::Postgres;
|
||||
|
||||
pub mod error;
|
||||
|
||||
mod connection;
|
||||
pub mod error;
|
||||
mod executor;
|
||||
|
||||
@ -4,7 +4,6 @@ use crate::{
|
||||
Capabilities, ComStmtExec, DeContext, Decode, EofPacket, ErrPacket,
|
||||
HandshakeResponsePacket, InitialHandshakePacket, OkPacket, ProtocolType, StmtExecFlag,
|
||||
},
|
||||
options::ConnectOptions,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use failure::{err_msg, Error};
|
||||
@ -55,7 +54,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn it_can_connect() -> Result<(), Error> {
|
||||
let mut conn = Connection::establish(&"mariadb://root@localhost:3306")
|
||||
let mut conn = Connection::establish(&"mariadb://root@127.0.0.1:3306")
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
@ -63,7 +62,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn it_can_ping() -> Result<(), Error> {
|
||||
let mut conn = Connection::establish(&"mariadb://root@localhost:3306")
|
||||
let mut conn = Connection::establish(&"mariadb://root@127.0.0.1:3306")
|
||||
|
||||
.await?;
|
||||
|
||||
@ -74,7 +73,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn it_can_select_db() -> Result<(), Error> {
|
||||
let mut conn = Connection::establish(&"mariadb://root@localhost:3306")
|
||||
let mut conn = Connection::establish(&"mariadb://root@127.0.0.1:3306")
|
||||
.await?;
|
||||
|
||||
conn.select_db("test").await?;
|
||||
@ -84,7 +83,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn it_can_query() -> Result<(), Error> {
|
||||
let mut conn = Connection::establish(&"mariadb://root@localhost:3306")
|
||||
let mut conn = Connection::establish(&"mariadb://root@127.0.0.1:3306")
|
||||
.await?;
|
||||
|
||||
conn.select_db("test").await?;
|
||||
@ -96,7 +95,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn it_can_prepare() -> Result<(), Error> {
|
||||
let mut conn = Connection::establish(&"mariadb://root@localhost:3306")
|
||||
let mut conn = Connection::establish(&"mariadb://root@127.0.0.1:3306")
|
||||
.await?;
|
||||
|
||||
conn.select_db("test").await?;
|
||||
@ -109,7 +108,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn it_can_execute_prepared() -> Result<(), Error> {
|
||||
let mut conn = Connection::establish(&"mariadb://root@localhost:3306")
|
||||
let mut conn = Connection::establish(&"mariadb://root@127.0.0.1:3306")
|
||||
.await?;
|
||||
|
||||
conn.select_db("test").await?;
|
||||
@ -152,7 +151,7 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn it_does_not_connect() -> Result<(), Error> {
|
||||
match Connection::establish(&"mariadb//roote@localhost:3306")
|
||||
match Connection::establish(&"mariadb//roote@127.0.0.1:3306")
|
||||
.await
|
||||
{
|
||||
Ok(_) => Err(err_msg("Bad username still worked?")),
|
||||
|
||||
@ -4,16 +4,11 @@ use crate::{
|
||||
ComStmtPrepareResp, DeContext, Decode, Decoder, Encode, ErrPacket, OkPacket, PacketHeader,
|
||||
ProtocolType, ResultSet, ServerStatusFlag,
|
||||
},
|
||||
options::ConnectOptions,
|
||||
};
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use core::convert::TryFrom;
|
||||
use failure::Error;
|
||||
use futures::{
|
||||
io::{AsyncRead},
|
||||
prelude::*,
|
||||
};
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWrite, AsyncWriteExt},
|
||||
net::TcpStream,
|
||||
@ -21,6 +16,7 @@ use tokio::{
|
||||
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
|
||||
use url::Url;
|
||||
use bytes::BufMut;
|
||||
use crate::error::ErrorKind;
|
||||
|
||||
mod establish;
|
||||
|
||||
@ -80,7 +76,8 @@ impl ConnContext {
|
||||
impl Connection {
|
||||
pub async fn establish(url: &str) -> Result<Self, Error> {
|
||||
// TODO: Handle errors
|
||||
let url = Url::parse(url).unwrap();
|
||||
let url = Url::parse(url).map_err(ErrorKind::UrlParse)?;
|
||||
println!("{:?}", url);
|
||||
|
||||
let host = url.host_str().unwrap_or("localhost");
|
||||
let port = url.port().unwrap_or(3306);
|
||||
@ -207,14 +204,6 @@ impl Framed {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn reserve(&mut self, size: usize) {
|
||||
self.buf.reserve(size);
|
||||
|
||||
unsafe { self.buf.set_len(self.buf.capacity()); }
|
||||
|
||||
unsafe { self.buf.advance_mut(size) }
|
||||
}
|
||||
|
||||
pub async fn next_packet(&mut self) -> Result<Bytes, Error> {
|
||||
let mut packet_headers: Vec<PacketHeader> = Vec::new();
|
||||
|
||||
@ -239,11 +228,12 @@ impl Framed {
|
||||
|
||||
if let Some(packet_header) = packet_headers.last() {
|
||||
if packet_header.combined_length() > self.buf.len() {
|
||||
unsafe { self.reserve(packet_header.combined_length() - self.buf.len()); }
|
||||
unsafe { self.buf.reserve(packet_header.combined_length() - self.buf.len()); }
|
||||
}
|
||||
} else if self.buf.len() == self.index {
|
||||
unsafe { self.reserve(32); }
|
||||
unsafe { self.buf.reserve(32); }
|
||||
}
|
||||
unsafe { self.buf.set_len(self.buf.capacity()); }
|
||||
|
||||
// If we have a packet_header and the amount of currently read bytes (len) is less than
|
||||
// the specified length inside packet_header, then we can continue reading to self.buf.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user