Skip to content

Commit 206bb32

Browse files
committed
Merge branch 'release-v0.9.2' into release
2 parents b6864b9 + d146061 commit 206bb32

File tree

11 files changed

+720
-162
lines changed

11 files changed

+720
-162
lines changed

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "postgres"
3-
version = "0.9.0"
3+
version = "0.9.2"
44
authors = ["Steven Fackler <[email protected]>"]
55
license = "MIT"
66
description = "A native PostgreSQL driver"
77
repository = "https://github.com/sfackler/rust-postgres"
8-
documentation = "https://sfackler.github.io/rust-postgres/doc/v0.9.0/postgres"
8+
documentation = "https://sfackler.github.io/rust-postgres/doc/v0.9.2/postgres"
99
readme = "README.md"
1010
keywords = ["database", "sql"]
1111
build = "build.rs"
@@ -29,7 +29,6 @@ byteorder = "0.3"
2929
debug-builders = "0.1"
3030
log = "0.3"
3131
phf = "0.7"
32-
rust-crypto = "0.2"
3332
rustc-serialize = "0.3"
3433
chrono = { version = "0.2.14", optional = true }
3534
openssl = { version = "0.6", optional = true }

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Rust-Postgres
22
A native PostgreSQL driver for Rust.
33

4-
Documentation is available at https://sfackler.github.io/rust-postgres/doc/v0.8.9/postgres
4+
[Documentation](https://sfackler.github.io/rust-postgres/doc/v0.9.2/postgres)
55

66
[![Build Status](https://travis-ci.org/sfackler/rust-postgres.png?branch=master)](https://travis-ci.org/sfackler/rust-postgres) [![Latest Version](https://img.shields.io/crates/v/postgres.svg)](https://crates.io/crates/postgres)
77

88
You can integrate Rust-Postgres into your project through the [releases on crates.io](https://crates.io/crates/postgres):
99
```toml
1010
# Cargo.toml
1111
[dependencies]
12-
postgres = "0.8"
12+
postgres = "0.9"
1313
```
1414

1515
## Overview

THIRD_PARTY

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,34 @@ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
5757
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
5858
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
5959
DEALINGS IN THE SOFTWARE.
60+
61+
-------------------------------------------------------------------------------
62+
63+
* src/md5.rs has been copied from rust-crypto
64+
65+
Copyright (c) 2006-2009 Graydon Hoare
66+
Copyright (c) 2009-2013 Mozilla Foundation
67+
68+
Permission is hereby granted, free of charge, to any
69+
person obtaining a copy of this software and associated
70+
documentation files (the "Software"), to deal in the
71+
Software without restriction, including without
72+
limitation the rights to use, copy, modify, merge,
73+
publish, distribute, sublicense, and/or sell copies of
74+
the Software, and to permit persons to whom the Software
75+
is furnished to do so, subject to the following
76+
conditions:
77+
78+
The above copyright notice and this permission notice
79+
shall be included in all copies or substantial portions
80+
of the Software.
81+
82+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
83+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
84+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
85+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
86+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
87+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
88+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
89+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
90+
DEALINGS IN THE SOFTWARE.

src/lib.rs

Lines changed: 51 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! package.
44
//!
55
//! ```rust,no_run
6-
//! # #![allow(unstable)]
76
//! extern crate postgres;
87
//!
98
//! use postgres::{Connection, SslMode};
@@ -42,12 +41,11 @@
4241
//! }
4342
//! }
4443
//! ```
45-
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.9.0")]
44+
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.9.2")]
4645
#![warn(missing_docs)]
4746

4847
extern crate bufstream;
4948
extern crate byteorder;
50-
extern crate crypto;
5149
#[macro_use]
5250
extern crate log;
5351
extern crate phf;
@@ -57,8 +55,7 @@ extern crate unix_socket;
5755
extern crate debug_builders;
5856

5957
use bufstream::BufStream;
60-
use crypto::digest::Digest;
61-
use crypto::md5::Md5;
58+
use md5::Md5;
6259
use debug_builders::DebugStruct;
6360
use std::ascii::AsciiExt;
6461
use std::borrow::ToOwned;
@@ -95,6 +92,7 @@ mod url;
9592
mod util;
9693
pub mod types;
9794
pub mod rows;
95+
mod md5;
9896

9997
const TYPEINFO_QUERY: &'static str = "t";
10098

@@ -174,7 +172,7 @@ impl IntoConnectParams for Url {
174172

175173
#[cfg(feature = "unix_socket")]
176174
fn make_unix(maybe_path: String) -> result::Result<ConnectTarget, ConnectError> {
177-
Ok(ConnectTarget::Unix(PathBuf::from(&maybe_path)))
175+
Ok(ConnectTarget::Unix(PathBuf::from(maybe_path)))
178176
}
179177
#[cfg(not(feature = "unix_socket"))]
180178
fn make_unix(_: String) -> result::Result<ConnectTarget, ConnectError> {
@@ -289,62 +287,6 @@ impl<'conn> Notifications<'conn> {
289287
_ => unreachable!()
290288
}
291289
}
292-
293-
/*
294-
/// Returns the oldest pending notification
295-
///
296-
/// If no notifications are pending, blocks for up to `timeout` time, after
297-
/// which `None` is returned.
298-
///
299-
/// ## Example
300-
///
301-
/// ```rust,no_run
302-
/// # #![allow(unstable)]
303-
/// use std::old_io::{IoError, IoErrorKind};
304-
/// use std::time::Duration;
305-
///
306-
/// use postgres::Error;
307-
///
308-
/// # let conn = postgres::Connection::connect("", &postgres::SslMode::None).unwrap();
309-
/// match conn.notifications().next_block_for(Duration::seconds(2)) {
310-
/// Some(Ok(notification)) => println!("notification: {}", notification.payload),
311-
/// Some(Err(e)) => println!("Error: {:?}", e),
312-
/// None => println!("Wait for notification timed out"),
313-
/// }
314-
/// ```
315-
pub fn next_block_for(&mut self, timeout: Duration) -> Option<Result<Notification>> {
316-
if let Some(notification) = self.next() {
317-
return Some(Ok(notification));
318-
}
319-
320-
let mut conn = self.conn.conn.borrow_mut();
321-
if conn.desynchronized {
322-
return Some(Err(Error::StreamDesynchronized));
323-
}
324-
325-
let end = SteadyTime::now() + timeout;
326-
loop {
327-
let timeout = max(Duration::zero(), end - SteadyTime::now()).num_milliseconds() as u64;
328-
conn.stream.set_read_timeout(Some(timeout));
329-
match conn.read_one_message() {
330-
Ok(Some(NotificationResponse { pid, channel, payload })) => {
331-
return Some(Ok(Notification {
332-
pid: pid,
333-
channel: channel,
334-
payload: payload
335-
}))
336-
}
337-
Ok(Some(_)) => unreachable!(),
338-
Ok(None) => {}
339-
Err(IoError { kind: IoErrorKind::TimedOut, .. }) => {
340-
conn.desynchronized = false;
341-
return None;
342-
}
343-
Err(e) => return Some(Err(Error::IoError(e))),
344-
}
345-
}
346-
}
347-
*/
348290
}
349291

350292
/// Contains information necessary to cancel queries for a session.
@@ -467,9 +409,19 @@ pub enum SslMode {
467409
/// The connection will not use SSL.
468410
None,
469411
/// The connection will use SSL if the backend supports it.
470-
Prefer(Box<NegotiateSsl>),
412+
Prefer(Box<NegotiateSsl+std::marker::Sync+Send>),
471413
/// The connection must use SSL.
472-
Require(Box<NegotiateSsl>),
414+
Require(Box<NegotiateSsl+std::marker::Sync+Send>),
415+
}
416+
417+
impl fmt::Debug for SslMode {
418+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
419+
match *self {
420+
SslMode::None => fmt.write_str("None"),
421+
SslMode::Prefer(..) => fmt.write_str("Prefer"),
422+
SslMode::Require(..) => fmt.write_str("Require"),
423+
}
424+
}
473425
}
474426

475427
#[derive(Clone)]
@@ -479,10 +431,6 @@ struct CachedStatement {
479431
columns: Vec<Column>,
480432
}
481433

482-
trait SessionInfoNew<'a> {
483-
fn new(conn: &'a InnerConnection) -> SessionInfo<'a>;
484-
}
485-
486434
struct InnerConnection {
487435
stream: BufStream<Box<StreamWrapper>>,
488436
notice_handler: Box<HandleNotice>,
@@ -597,27 +545,19 @@ impl InnerConnection {
597545
Ok(try_desync!(self, self.stream.flush()))
598546
}
599547

600-
fn read_one_message(&mut self) -> std_io::Result<Option<BackendMessage>> {
601-
debug_assert!(!self.desynchronized);
602-
match try_desync!(self, self.stream.read_message()) {
603-
NoticeResponse { fields } => {
604-
if let Ok(err) = DbError::new_raw(fields) {
605-
self.notice_handler.handle_notice(err);
606-
}
607-
Ok(None)
608-
}
609-
ParameterStatus { parameter, value } => {
610-
self.parameters.insert(parameter, value);
611-
Ok(None)
612-
}
613-
val => Ok(Some(val))
614-
}
615-
}
616-
617548
fn read_message_with_notification(&mut self) -> std_io::Result<BackendMessage> {
549+
debug_assert!(!self.desynchronized);
618550
loop {
619-
if let Some(msg) = try!(self.read_one_message()) {
620-
return Ok(msg);
551+
match try_desync!(self, self.stream.read_message()) {
552+
NoticeResponse { fields } => {
553+
if let Ok(err) = DbError::new_raw(fields) {
554+
self.notice_handler.handle_notice(err);
555+
}
556+
}
557+
ParameterStatus { parameter, value } => {
558+
self.parameters.insert(parameter, value);
559+
}
560+
val => return Ok(val)
621561
}
622562
}
623563
}
@@ -982,7 +922,6 @@ impl Connection {
982922
/// ```
983923
///
984924
/// ```rust,no_run
985-
/// # #![allow(unstable)]
986925
/// # use postgres::{Connection, UserInfo, ConnectParams, SslMode, ConnectTarget};
987926
/// # #[cfg(feature = "unix_socket")]
988927
/// # fn f() -> Result<(), ::postgres::error::ConnectError> {
@@ -1630,22 +1569,31 @@ impl<'conn> Statement<'conn> {
16301569

16311570
let mut buf = vec![];
16321571
loop {
1633-
match std::io::copy(&mut r.take(16 * 1024), &mut buf) {
1572+
match r.take(16 * 1024).read_to_end(&mut buf) {
16341573
Ok(0) => break,
1635-
Ok(len) => {
1574+
Ok(_) => {
16361575
try_desync!(conn, conn.stream.write_message(
1637-
&CopyData {
1638-
data: &buf[..len as usize],
1639-
}));
1576+
&CopyData {
1577+
data: &buf,
1578+
}));
16401579
buf.clear();
16411580
}
16421581
Err(err) => {
1643-
// FIXME better to return the error directly
1644-
try_desync!(conn, conn.stream.write_message(
1645-
&CopyFail {
1646-
message: &err.to_string(),
1647-
}));
1648-
break;
1582+
try!(conn.write_messages(&[
1583+
CopyFail {
1584+
message: "",
1585+
},
1586+
CopyDone,
1587+
Sync]));
1588+
match try!(conn.read_message()) {
1589+
ErrorResponse { .. } => { /* expected from the CopyFail */ }
1590+
_ => {
1591+
conn.desynchronized = true;
1592+
return Err(Error::IoError(bad_response()));
1593+
}
1594+
}
1595+
try!(conn.wait_for_ready());
1596+
return Err(Error::IoError(err));
16491597
}
16501598
}
16511599
}
@@ -1833,3 +1781,7 @@ trait LazyRowsNew<'trans, 'stmt> {
18331781
finished: bool,
18341782
trans: &'trans Transaction<'trans>) -> LazyRows<'trans, 'stmt>;
18351783
}
1784+
1785+
trait SessionInfoNew<'a> {
1786+
fn new(conn: &'a InnerConnection) -> SessionInfo<'a>;
1787+
}

0 commit comments

Comments
 (0)