Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fed121d

Browse files
committed
Merge branch 'release-v0.11.1' into release
2 parents 3d67d52 + c677386 commit fed121d

File tree

8 files changed

+76
-19
lines changed

8 files changed

+76
-19
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sudo: required
33
rust:
44
- nightly
55
- beta
6-
- 1.4.0
6+
- 1.5.0
77
addons:
88
postgresql: 9.4
99
before_script:

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "postgres"
3-
version = "0.11.0"
3+
version = "0.11.1"
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.11.0/postgres"
8+
documentation = "https://sfackler.github.io/rust-postgres/doc/v0.11.1/postgres"
99
readme = "README.md"
10-
keywords = ["database", "sql"]
10+
keywords = ["database", "postgres", "postgresql", "sql"]
1111
build = "build.rs"
1212
include = ["src/*", "build.rs", "Cargo.toml", "LICENSE", "README.md", "THIRD_PARTY"]
1313

@@ -42,4 +42,4 @@ security-framework = { version = "0.1.2", optional = true }
4242
bit-vec = { version = "0.4", optional = true }
4343

4444
[dev-dependencies]
45-
url = "0.2"
45+
url = "0.5"

README.md

Lines changed: 2 additions & 2 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.11.0/postgres)
4+
[Documentation](https://sfackler.github.io/rust-postgres/doc/v0.11.1/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

@@ -54,7 +54,7 @@ fn main() {
5454
```
5555

5656
## Requirements
57-
* **Rust** - Rust-Postgres is developed against the 1.4 release of Rust
57+
* **Rust** - Rust-Postgres is developed against the 1.5 release of Rust
5858
available on http://www.rust-lang.org. It should also compile against more
5959
recent releases.
6060

src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
//! }
3939
//! }
4040
//! ```
41-
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.0")]
41+
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.1")]
4242
#![warn(missing_docs)]
4343

4444
extern crate bufstream;
@@ -462,7 +462,7 @@ impl InnerConnection {
462462
#[cfg_attr(rustfmt, rustfmt_skip)]
463463
fn setup_typeinfo_query(&mut self) -> result::Result<(), ConnectError> {
464464
match self.raw_prepare(TYPEINFO_QUERY,
465-
"SELECT t.typname, t.typelem, r.rngsubtype, n.nspname \
465+
"SELECT t.typname, t.typelem, r.rngsubtype, t.typbasetype, n.nspname \
466466
FROM pg_catalog.pg_type t \
467467
LEFT OUTER JOIN pg_catalog.pg_range r ON \
468468
r.rngtypid = t.oid \
@@ -478,7 +478,7 @@ impl InnerConnection {
478478
}
479479

480480
match self.raw_prepare(TYPEINFO_QUERY,
481-
"SELECT t.typname, t.typelem, NULL::OID, n.nspname \
481+
"SELECT t.typname, t.typelem, NULL::OID, t.typbasetype, n.nspname \
482482
FROM pg_catalog.pg_type t \
483483
INNER JOIN pg_catalog.pg_namespace n \
484484
ON t.typnamespace = n.oid \
@@ -749,7 +749,7 @@ impl InnerConnection {
749749
}
750750
_ => bad_response!(self),
751751
}
752-
let (name, elem_oid, rngsubtype, schema) = match try!(self.read_message()) {
752+
let (name, elem_oid, rngsubtype, basetype, schema) = match try!(self.read_message()) {
753753
DataRow { row } => {
754754
let ctx = SessionInfo::new(self);
755755
let name = try!(String::from_sql(&Type::Name,
@@ -762,10 +762,13 @@ impl InnerConnection {
762762
Some(ref data) => try!(Option::<Oid>::from_sql(&Type::Oid, &mut &**data, &ctx)),
763763
None => try!(Option::<Oid>::from_sql_null(&Type::Oid, &ctx)),
764764
};
765+
let basetype = try!(Oid::from_sql(&Type::Oid,
766+
&mut &**row[3].as_ref().unwrap(),
767+
&ctx));
765768
let schema = try!(String::from_sql(&Type::Name,
766-
&mut &**row[3].as_ref().unwrap(),
769+
&mut &**row[4].as_ref().unwrap(),
767770
&ctx));
768-
(name, elem_oid, rngsubtype, schema)
771+
(name, elem_oid, rngsubtype, basetype, schema)
769772
}
770773
ErrorResponse { fields } => {
771774
try!(self.wait_for_ready());
@@ -783,7 +786,9 @@ impl InnerConnection {
783786
}
784787
try!(self.wait_for_ready());
785788

786-
let kind = if elem_oid != 0 {
789+
let kind = if basetype != 0 {
790+
Kind::Domain(try!(self.get_type(basetype)))
791+
} else if elem_oid != 0 {
787792
Kind::Array(try!(self.get_type(elem_oid)))
788793
} else {
789794
match rngsubtype {

src/md5.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ struct StepUp<T> {
2121
ammount: T,
2222
}
2323

24-
impl<T> Iterator for StepUp<T> where T: Add<T, Output = T> + PartialOrd + Copy
24+
impl<T> Iterator for StepUp<T>
25+
where T: Add<T, Output = T> + PartialOrd + Copy
2526
{
2627
type Item = T;
2728

@@ -41,7 +42,8 @@ trait RangeExt<T> {
4142
fn step_up(self, ammount: T) -> StepUp<T>;
4243
}
4344

44-
impl<T> RangeExt<T> for Range<T> where T: Add<T, Output = T> + PartialOrd + Copy
45+
impl<T> RangeExt<T> for Range<T>
46+
where T: Add<T, Output = T> + PartialOrd + Copy
4547
{
4648
fn step_up(self, ammount: T) -> StepUp<T> {
4749
StepUp {

src/types/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ pub enum Kind {
107107
Array(Type),
108108
/// A range type along with the type of its elements.
109109
Range(Type),
110+
/// Domain type along with its underlying type.
111+
Domain(Type),
110112
#[doc(hidden)]
111113
__PseudoPrivateForExtensibility,
112114
}
@@ -889,7 +891,8 @@ pub trait ToSql: fmt::Debug {
889891
fn to_sql_checked(&self, ty: &Type, out: &mut Write, ctx: &SessionInfo) -> Result<IsNull>;
890892
}
891893

892-
impl<'a, T> ToSql for &'a T where T: ToSql
894+
impl<'a, T> ToSql for &'a T
895+
where T: ToSql
893896
{
894897
to_sql_checked!();
895898

tests/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[macro_use]
12
extern crate postgres;
23
extern crate url;
34
#[cfg(feature = "openssl")]

tests/types/mod.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ use std::collections::HashMap;
22
use std::f32;
33
use std::f64;
44
use std::fmt;
5+
use std::io::{Read, Write};
56

6-
use postgres::{Connection, SslMode};
7+
use postgres::{Connection, SslMode, Result};
78
use postgres::error::Error;
8-
use postgres::types::{ToSql, FromSql, Slice, WrongType};
9+
use postgres::types::{ToSql, FromSql, Slice, WrongType, Type, IsNull, Kind, SessionInfo};
910

1011
#[cfg(feature = "bit-vec")]
1112
mod bit_vec;
@@ -233,3 +234,48 @@ fn test_slice_range() {
233234
Err(e) => panic!("Unexpected error {:?}", e),
234235
};
235236
}
237+
238+
#[test]
239+
fn domain() {
240+
#[derive(Debug, PartialEq)]
241+
struct SessionId(Vec<u8>);
242+
243+
impl ToSql for SessionId {
244+
fn to_sql<W: ?Sized>(&self, ty: &Type, out: &mut W, ctx: &SessionInfo) -> Result<IsNull>
245+
where W: Write
246+
{
247+
let inner = match *ty.kind() {
248+
Kind::Domain(ref inner) => inner,
249+
_ => unreachable!(),
250+
};
251+
self.0.to_sql(inner, out, ctx)
252+
}
253+
254+
fn accepts(ty: &Type) -> bool {
255+
ty.name() == "session_id" && match *ty.kind() { Kind::Domain(_) => true, _ => false }
256+
}
257+
258+
to_sql_checked!();
259+
}
260+
261+
impl FromSql for SessionId {
262+
fn from_sql<R: Read>(ty: &Type, raw: &mut R, ctx: &SessionInfo) -> Result<Self> {
263+
Vec::<u8>::from_sql(ty, raw, ctx).map(SessionId)
264+
}
265+
266+
fn accepts(ty: &Type) -> bool {
267+
// This is super weird!
268+
<Vec<u8> as FromSql>::accepts(ty)
269+
}
270+
}
271+
272+
let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap();
273+
conn.batch_execute("CREATE DOMAIN pg_temp.session_id AS bytea CHECK(octet_length(VALUE) = 16);
274+
CREATE TABLE pg_temp.foo (id pg_temp.session_id);")
275+
.unwrap();
276+
277+
let id = SessionId(b"0123456789abcdef".to_vec());
278+
conn.execute("INSERT INTO pg_temp.foo (id) VALUES ($1)", &[&id]).unwrap();
279+
let rows = conn.query("SELECT id FROM pg_temp.foo", &[]).unwrap();
280+
assert_eq!(id, rows.get(0).get(0));
281+
}

0 commit comments

Comments
 (0)