Skip to content

Commit d6616dd

Browse files
committed
Merge branch 'release-v0.9.3' into release
2 parents 206bb32 + 06b4681 commit d6616dd

File tree

6 files changed

+61
-27
lines changed

6 files changed

+61
-27
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "postgres"
3-
version = "0.9.2"
3+
version = "0.9.3"
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.2/postgres"
8+
documentation = "https://sfackler.github.io/rust-postgres/doc/v0.9.3/postgres"
99
readme = "README.md"
1010
keywords = ["database", "sql"]
1111
build = "build.rs"

README.md

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

4-
[Documentation](https://sfackler.github.io/rust-postgres/doc/v0.9.2/postgres)
4+
[Documentation](https://sfackler.github.io/rust-postgres/doc/v0.9.3/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

@@ -57,9 +57,9 @@ fn main() {
5757
```
5858

5959
## Requirements
60-
* **Rust** - Rust-Postgres is developed against the 1.0.0 release of Rust
60+
* **Rust** - Rust-Postgres is developed against the 1.0 release of Rust
6161
available on http://www.rust-lang.org. It should also compile against more
62-
recent unstable releases.
62+
recent releases.
6363

6464
* **PostgreSQL 7.4 or later** - Rust-Postgres speaks version 3 of the
6565
PostgreSQL protocol, which corresponds to versions 7.4 and later. If your
@@ -254,13 +254,13 @@ types. The driver currently supports the following conversions:
254254
More conversions can be defined by implementing the `ToSql` and `FromSql`
255255
traits.
256256

257-
Support for Postgres arrays is located in the
257+
Support for array types is located in the
258258
[postgres-array](https://github.com/sfackler/rust-postgres-array) crate.
259259

260-
Support for Postgres ranges is located in the
260+
Support for range types is located in the
261261
[postgres-range](https://github.com/sfackler/rust-postgres-range) crate.
262262

263-
Support for Postgres large objects is located in the
263+
Support for the large object API is located in the
264264
[postgres-large-object](https://github.com/sfackler/rust-postgres-large-object) crate.
265265

266266
## Optional features

src/error.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ impl fmt::Display for ConnectError {
217217
try!(fmt.write_str(error::Error::description(self)));
218218
match *self {
219219
ConnectError::InvalidUrl(ref msg) => write!(fmt, ": {}", msg),
220+
ConnectError::DbError(ref err) => write!(fmt, ": {}", err),
221+
ConnectError::SslError(ref err) => write!(fmt, ": {}", err),
222+
ConnectError::IoError(ref err) => write!(fmt, ": {}", err),
220223
_ => Ok(())
221224
}
222225
}
@@ -227,14 +230,14 @@ impl error::Error for ConnectError {
227230
match *self {
228231
ConnectError::InvalidUrl(_) => "Invalid URL",
229232
ConnectError::MissingUser => "User missing in URL",
230-
ConnectError::DbError(_) => "An error from the Postgres server itself",
233+
ConnectError::DbError(_) => "Error reported by Postgres",
231234
ConnectError::MissingPassword => "The server requested a password but none was provided",
232235
ConnectError::UnsupportedAuthentication => {
233236
"The server requested an unsupported authentication method"
234237
}
235238
ConnectError::NoSslSupport => "The server does not support SSL",
236239
ConnectError::SslError(_) => "Error initiating SSL session",
237-
ConnectError::IoError(_) => "Error communicating with server",
240+
ConnectError::IoError(_) => "Error communicating with the server",
238241
}
239242
}
240243

@@ -300,7 +303,10 @@ impl fmt::Display for Error {
300303
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
301304
try!(fmt.write_str(error::Error::description(self)));
302305
match *self {
306+
Error::DbError(ref err) => write!(fmt, ": {}", err),
307+
Error::IoError(ref err) => write!(fmt, ": {}", err),
303308
Error::WrongType(ref ty) => write!(fmt, ": saw type {:?}", ty),
309+
Error::Conversion(ref err) => write!(fmt, ": {}", err),
304310
_ => Ok(()),
305311
}
306312
}
@@ -309,11 +315,11 @@ impl fmt::Display for Error {
309315
impl error::Error for Error {
310316
fn description(&self) -> &str {
311317
match *self {
312-
Error::DbError(_) => "An error reported by the Postgres server",
313-
Error::IoError(_) => "An error communicating with the Postgres server",
318+
Error::DbError(_) => "Error reported by Postgres",
319+
Error::IoError(_) => "Error communicating with the server",
314320
Error::WrongType(_) => "Unexpected type",
315321
Error::InvalidColumn => "Invalid column",
316-
Error::Conversion(_) => "An error converting between Postgres and Rust types",
322+
Error::Conversion(_) => "Error converting between Postgres and Rust types",
317323
}
318324
}
319325

src/lib.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
//! }
4242
//! }
4343
//! ```
44-
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.9.2")]
44+
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.9.3")]
4545
#![warn(missing_docs)]
4646

4747
extern crate bufstream;
@@ -73,7 +73,7 @@ use std::path::PathBuf;
7373
use error::{Error, ConnectError, SqlState, DbError};
7474
use types::{ToSql, FromSql};
7575
use io::{StreamWrapper, NegotiateSsl};
76-
use types::{IsNull, Kind, Type, SessionInfo, Oid, Other};
76+
use types::{IsNull, Kind, Type, SessionInfo, Oid, Other, ReadWithInfo};
7777
use message::BackendMessage::*;
7878
use message::FrontendMessage::*;
7979
use message::{FrontendMessage, BackendMessage, RowDescriptionEntry};
@@ -1530,12 +1530,13 @@ impl<'conn> Statement<'conn> {
15301530
/// Executes a `COPY FROM STDIN` statement, returning the number of rows
15311531
/// added.
15321532
///
1533-
/// The contents of the provided `Read`er are passed to the Postgres server
1534-
/// verbatim; it is the caller's responsibility to ensure the data is in
1535-
/// the proper format. See the [Postgres documentation](http://www.postgresql.org/docs/9.4/static/sql-copy.html)
1533+
/// The contents of the provided reader are passed to the Postgres server
1534+
/// verbatim; it is the caller's responsibility to ensure it uses the
1535+
/// proper format. See the
1536+
/// [Postgres documentation](http://www.postgresql.org/docs/9.4/static/sql-copy.html)
15361537
/// for details.
15371538
///
1538-
/// If the statement is not a `COPY FROM STDIN` statement, it will still be
1539+
/// If the statement is not a `COPY FROM STDIN` statement it will still be
15391540
/// executed and this method will return an error.
15401541
///
15411542
/// # Examples
@@ -1547,7 +1548,7 @@ impl<'conn> Statement<'conn> {
15471548
/// let stmt = conn.prepare("COPY people FROM STDIN").unwrap();
15481549
/// stmt.copy_in(&[], &mut "1\tjohn\n2\tjane\n".as_bytes()).unwrap();
15491550
/// ```
1550-
pub fn copy_in<R: Read>(&self, params: &[&ToSql], r: &mut R) -> Result<u64> {
1551+
pub fn copy_in<R: ReadWithInfo>(&self, params: &[&ToSql], r: &mut R) -> Result<u64> {
15511552
try!(self.inner_execute("", 0, params));
15521553
let mut conn = self.conn.conn.borrow_mut();
15531554

@@ -1567,16 +1568,15 @@ impl<'conn> Statement<'conn> {
15671568
}
15681569
}
15691570

1570-
let mut buf = vec![];
1571+
let mut buf = [0; 16 * 1024];
15711572
loop {
1572-
match r.take(16 * 1024).read_to_end(&mut buf) {
1573+
match fill_copy_buf(&mut buf, r, &SessionInfo::new(&conn)) {
15731574
Ok(0) => break,
1574-
Ok(_) => {
1575+
Ok(len) => {
15751576
try_desync!(conn, conn.stream.write_message(
15761577
&CopyData {
1577-
data: &buf,
1578+
data: &buf[..len],
15781579
}));
1579-
buf.clear();
15801580
}
15811581
Err(err) => {
15821582
try!(conn.write_messages(&[
@@ -1628,6 +1628,20 @@ impl<'conn> Statement<'conn> {
16281628
}
16291629
}
16301630

1631+
fn fill_copy_buf<R: ReadWithInfo>(buf: &mut [u8], r: &mut R, info: &SessionInfo)
1632+
-> std_io::Result<usize> {
1633+
let mut nread = 0;
1634+
while nread < buf.len() {
1635+
match r.read_with_info(&mut buf[nread..], info) {
1636+
Ok(0) => break,
1637+
Ok(n) => nread += n,
1638+
Err(ref e) if e.kind() == std_io::ErrorKind::Interrupted => {}
1639+
Err(e) => return Err(e),
1640+
}
1641+
}
1642+
Ok(nread)
1643+
}
1644+
16311645
/// Information about a column of the result of a query.
16321646
#[derive(PartialEq, Eq, Clone, Debug)]
16331647
pub struct Column {

src/priv_io.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ fn open_socket(params: &ConnectParams) -> Result<InternalStream, ConnectError> {
112112
}
113113
#[cfg(feature = "unix_socket")]
114114
ConnectTarget::Unix(ref path) => {
115-
let mut path = path.clone();
116-
path.push(&format!(".s.PGSQL.{}", port));
115+
let path = path.join(&format!(".s.PGSQL.{}", port));
117116
Ok(try!(UnixStream::connect(&path).map(InternalStream::Unix)))
118117
}
119118
}

src/types/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::collections::HashMap;
44
use std::error;
55
use std::fmt;
66
use std::io::prelude::*;
7+
use std::io;
78
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
89

910
pub use self::slice::Slice;
@@ -75,6 +76,20 @@ impl<'a> SessionInfo<'a> {
7576
}
7677
}
7778

79+
/// Like `Read` except that a `SessionInfo` object is provided as well.
80+
///
81+
/// All types that implement `Read` also implement this trait.
82+
pub trait ReadWithInfo {
83+
/// Like `Read::read`.
84+
fn read_with_info(&mut self, buf: &mut [u8], info: &SessionInfo) -> io::Result<usize>;
85+
}
86+
87+
impl<R: Read> ReadWithInfo for R {
88+
fn read_with_info(&mut self, buf: &mut [u8], _: &SessionInfo) -> io::Result<usize> {
89+
self.read(buf)
90+
}
91+
}
92+
7893
/// A Postgres OID.
7994
pub type Oid = u32;
8095

0 commit comments

Comments
 (0)