Use new slice syntax
This commit is contained in:
parent
dd4052210f
commit
e5ed2ba96e
@ -205,7 +205,6 @@ make_errors!(
|
||||
"38003" => ProhibitedSqlStatementAttemptedExternalRoutine,
|
||||
"38004" => ReadingSqlDataNotPermittedExternalRoutine,
|
||||
|
||||
|
||||
// Class 39 — External Routine Invocation Exception
|
||||
"39000" => ExternalRoutineInvocationException,
|
||||
"39001" => InvalidSqlstateReturned,
|
||||
@ -484,15 +483,15 @@ impl PostgresDbError {
|
||||
let mut map: HashMap<_, _> = fields.into_iter().collect();
|
||||
Ok(PostgresDbError {
|
||||
severity: try!(map.pop(&b'S').ok_or(())),
|
||||
code: PostgresSqlState::from_code(try!(map.pop(&b'C').ok_or(())).as_slice()),
|
||||
code: PostgresSqlState::from_code(try!(map.pop(&b'C').ok_or(()))[]),
|
||||
message: try!(map.pop(&b'M').ok_or(())),
|
||||
detail: map.pop(&b'D'),
|
||||
hint: map.pop(&b'H'),
|
||||
position: match map.pop(&b'P') {
|
||||
Some(pos) => Some(Position(try!(from_str(pos.as_slice()).ok_or(())))),
|
||||
Some(pos) => Some(Position(try!(from_str(pos[]).ok_or(())))),
|
||||
None => match map.pop(&b'p') {
|
||||
Some(pos) => Some(InternalPosition {
|
||||
position: try!(from_str(pos.as_slice()).ok_or(())),
|
||||
position: try!(from_str(pos[]).ok_or(())),
|
||||
query: try!(map.pop(&b'q').ok_or(()))
|
||||
}),
|
||||
None => None
|
||||
@ -505,7 +504,7 @@ impl PostgresDbError {
|
||||
datatype: map.pop(&b'd'),
|
||||
constraint: map.pop(&b'n'),
|
||||
file: try!(map.pop(&b'F').ok_or(())),
|
||||
line: try!(map.pop(&b'L').and_then(|l| from_str(l.as_slice())).ok_or(())),
|
||||
line: try!(map.pop(&b'L').and_then(|l| from_str(l[])).ok_or(())),
|
||||
routine: map.pop(&b'R').unwrap()
|
||||
})
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ fn open_socket(params: &PostgresConnectParams)
|
||||
let port = params.port.unwrap_or(DEFAULT_PORT);
|
||||
let socket = match params.target {
|
||||
TargetTcp(ref host) =>
|
||||
tcp::TcpStream::connect(host.as_slice(), port).map(|s| TcpStream(s)),
|
||||
tcp::TcpStream::connect(host[], port).map(|s| TcpStream(s)),
|
||||
TargetUnix(ref path) => {
|
||||
let mut path = path.clone();
|
||||
path.push(format!(".s.PGSQL.{}", port));
|
||||
|
60
src/lib.rs
60
src/lib.rs
@ -224,8 +224,8 @@ impl IntoConnectParams for Url {
|
||||
..
|
||||
} = self;
|
||||
|
||||
let maybe_path = try!(url::decode_component(host.as_slice()).map_err(InvalidUrl));
|
||||
let target = if maybe_path.as_slice().starts_with("/") {
|
||||
let maybe_path = try!(url::decode_component(host[]).map_err(InvalidUrl));
|
||||
let target = if maybe_path[].starts_with("/") {
|
||||
TargetUnix(Path::new(maybe_path))
|
||||
} else {
|
||||
TargetTcp(host)
|
||||
@ -238,7 +238,7 @@ impl IntoConnectParams for Url {
|
||||
|
||||
let database = if !path.is_empty() {
|
||||
// path contains the leading /
|
||||
let (_, path) = path.as_slice().slice_shift_char();
|
||||
let (_, path) = path[].slice_shift_char();
|
||||
Some(path.to_string())
|
||||
} else {
|
||||
None
|
||||
@ -413,7 +413,7 @@ impl InnerPostgresConnection {
|
||||
|
||||
try_pg_conn!(conn.write_messages([StartupMessage {
|
||||
version: message::PROTOCOL_VERSION,
|
||||
parameters: options.as_slice()
|
||||
parameters: options[]
|
||||
}]));
|
||||
|
||||
try!(conn.handle_auth(user));
|
||||
@ -476,7 +476,7 @@ impl InnerPostgresConnection {
|
||||
None => return Err(MissingPassword)
|
||||
};
|
||||
try_pg_conn!(self.write_messages([PasswordMessage {
|
||||
password: pass.as_slice(),
|
||||
password: pass[],
|
||||
}]));
|
||||
}
|
||||
AuthenticationMD5Password { salt } => {
|
||||
@ -487,14 +487,14 @@ impl InnerPostgresConnection {
|
||||
let hasher = Hasher::new(MD5);
|
||||
hasher.update(pass.as_bytes());
|
||||
hasher.update(user.user.as_bytes());
|
||||
let output = hasher.final().as_slice().to_hex();
|
||||
let output = hasher.final()[].to_hex();
|
||||
let hasher = Hasher::new(MD5);
|
||||
hasher.update(output.as_bytes());
|
||||
hasher.update(salt);
|
||||
let output = format!("md5{}",
|
||||
hasher.final().as_slice().to_hex());
|
||||
hasher.final()[].to_hex());
|
||||
try_pg_conn!(self.write_messages([PasswordMessage {
|
||||
password: output.as_slice()
|
||||
password: output[]
|
||||
}]));
|
||||
}
|
||||
AuthenticationKerberosV5
|
||||
@ -530,13 +530,13 @@ impl InnerPostgresConnection {
|
||||
|
||||
try_pg!(self.write_messages([
|
||||
Parse {
|
||||
name: stmt_name.as_slice(),
|
||||
name: stmt_name[],
|
||||
query: query,
|
||||
param_types: []
|
||||
},
|
||||
Describe {
|
||||
variant: b'S',
|
||||
name: stmt_name.as_slice(),
|
||||
name: stmt_name[],
|
||||
},
|
||||
Sync]));
|
||||
|
||||
@ -598,17 +598,17 @@ impl InnerPostgresConnection {
|
||||
let _ = util::comma_join(&mut query, rows.iter().map(|&e| e));
|
||||
let _ = write!(query, " FROM {}", table);
|
||||
let query = String::from_utf8(query.unwrap()).unwrap();
|
||||
let (stmt_name, _, result_desc) = try!(self.raw_prepare(query.as_slice()));
|
||||
let (stmt_name, _, result_desc) = try!(self.raw_prepare(query[]));
|
||||
|
||||
let column_types = result_desc.iter().map(|desc| desc.ty.clone()).collect();
|
||||
try!(self.close_statement(stmt_name.as_slice()));
|
||||
try!(self.close_statement(stmt_name[]));
|
||||
|
||||
let mut query = MemWriter::new();
|
||||
let _ = write!(query, "COPY {} (", table);
|
||||
let _ = util::comma_join(&mut query, rows.iter().map(|&e| e));
|
||||
let _ = write!(query, ") FROM STDIN WITH (FORMAT binary)");
|
||||
let query = String::from_utf8(query.unwrap()).unwrap();
|
||||
let (stmt_name, _, _) = try!(self.raw_prepare(query.as_slice()));
|
||||
let (stmt_name, _, _) = try!(self.raw_prepare(query[]));
|
||||
|
||||
Ok(PostgresCopyInStatement {
|
||||
conn: conn,
|
||||
@ -656,7 +656,7 @@ impl InnerPostgresConnection {
|
||||
None => {}
|
||||
}
|
||||
let name = try!(self.quick_query(format!("SELECT typname FROM pg_type \
|
||||
WHERE oid={}", oid).as_slice()))
|
||||
WHERE oid={}", oid)[]))
|
||||
.into_iter().next().unwrap().into_iter().next().unwrap().unwrap();
|
||||
self.unknown_types.insert(oid, name.clone());
|
||||
Ok(name)
|
||||
@ -687,7 +687,7 @@ impl InnerPostgresConnection {
|
||||
ReadyForQuery { .. } => break,
|
||||
DataRow { row } => {
|
||||
result.push(row.into_iter().map(|opt| {
|
||||
opt.map(|b| String::from_utf8_lossy(b.as_slice()).into_string())
|
||||
opt.map(|b| String::from_utf8_lossy(b[]).into_string())
|
||||
}).collect());
|
||||
}
|
||||
ErrorResponse { fields } => {
|
||||
@ -1149,7 +1149,7 @@ impl<'conn> PostgresStatement<'conn> {
|
||||
fn finish_inner(&mut self) -> PostgresResult<()> {
|
||||
let mut conn = self.conn.conn.borrow_mut();
|
||||
check_desync!(conn);
|
||||
conn.close_statement(self.name.as_slice())
|
||||
conn.close_statement(self.name[])
|
||||
}
|
||||
|
||||
fn inner_execute(&self, portal_name: &str, row_limit: i32, params: &[&ToSql])
|
||||
@ -1170,9 +1170,9 @@ impl<'conn> PostgresStatement<'conn> {
|
||||
try_pg!(conn.write_messages([
|
||||
Bind {
|
||||
portal: portal_name,
|
||||
statement: self.name.as_slice(),
|
||||
statement: self.name[],
|
||||
formats: [1],
|
||||
values: values.as_slice(),
|
||||
values: values[],
|
||||
result_formats: [1]
|
||||
},
|
||||
Execute {
|
||||
@ -1200,7 +1200,7 @@ impl<'conn> PostgresStatement<'conn> {
|
||||
self.next_portal_id.set(id + 1);
|
||||
let portal_name = format!("{}p{}", self.name, id);
|
||||
|
||||
try!(self.inner_execute(portal_name.as_slice(), row_limit, params));
|
||||
try!(self.inner_execute(portal_name[], row_limit, params));
|
||||
|
||||
let mut result = PostgresRows {
|
||||
stmt: self,
|
||||
@ -1217,12 +1217,12 @@ impl<'conn> PostgresStatement<'conn> {
|
||||
|
||||
/// Returns a slice containing the expected parameter types.
|
||||
pub fn param_types(&self) -> &[PostgresType] {
|
||||
self.param_types.as_slice()
|
||||
self.param_types[]
|
||||
}
|
||||
|
||||
/// Returns a slice describing the columns of the result of the query.
|
||||
pub fn result_descriptions(&self) -> &[ResultDescription] {
|
||||
self.result_desc.as_slice()
|
||||
self.result_desc[]
|
||||
}
|
||||
|
||||
/// Executes the prepared statement, returning the number of rows modified.
|
||||
@ -1349,7 +1349,7 @@ impl<'stmt> PostgresRows<'stmt> {
|
||||
try_pg!(conn.write_messages([
|
||||
Close {
|
||||
variant: b'P',
|
||||
name: self.name.as_slice()
|
||||
name: self.name[]
|
||||
},
|
||||
Sync]));
|
||||
|
||||
@ -1404,7 +1404,7 @@ impl<'stmt> PostgresRows<'stmt> {
|
||||
fn execute(&mut self) -> PostgresResult<()> {
|
||||
try_pg!(self.stmt.conn.write_messages([
|
||||
Execute {
|
||||
portal: self.name.as_slice(),
|
||||
portal: self.name[],
|
||||
max_rows: self.row_limit
|
||||
},
|
||||
Sync]));
|
||||
@ -1535,7 +1535,7 @@ impl RowIndex for uint {
|
||||
impl<'a> RowIndex for &'a str {
|
||||
#[inline]
|
||||
fn idx(&self, stmt: &PostgresStatement) -> Option<uint> {
|
||||
stmt.result_descriptions().iter().position(|d| d.name.as_slice() == *self)
|
||||
stmt.result_descriptions().iter().position(|d| d.name[] == *self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1587,12 +1587,12 @@ impl<'a> PostgresCopyInStatement<'a> {
|
||||
fn finish_inner(&mut self) -> PostgresResult<()> {
|
||||
let mut conn = self.conn.conn.borrow_mut();
|
||||
check_desync!(conn);
|
||||
conn.close_statement(self.name.as_slice())
|
||||
conn.close_statement(self.name[])
|
||||
}
|
||||
|
||||
/// Returns a slice containing the expected column types.
|
||||
pub fn column_types(&self) -> &[PostgresType] {
|
||||
self.column_types.as_slice()
|
||||
self.column_types[]
|
||||
}
|
||||
|
||||
/// Executes the prepared statement.
|
||||
@ -1608,7 +1608,7 @@ impl<'a> PostgresCopyInStatement<'a> {
|
||||
try_pg!(conn.write_messages([
|
||||
Bind {
|
||||
portal: "",
|
||||
statement: self.name.as_slice(),
|
||||
statement: self.name[],
|
||||
formats: [],
|
||||
values: [],
|
||||
result_formats: []
|
||||
@ -1657,7 +1657,7 @@ impl<'a> PostgresCopyInStatement<'a> {
|
||||
}
|
||||
Some(val) => {
|
||||
let _ = buf.write_be_i32(val.len() as i32);
|
||||
let _ = buf.write(val.as_slice());
|
||||
let _ = buf.write(val[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1674,7 +1674,7 @@ impl<'a> PostgresCopyInStatement<'a> {
|
||||
|
||||
try_pg_desync!(conn, conn.stream.write_message(
|
||||
&CopyData {
|
||||
data: buf.unwrap().as_slice()
|
||||
data: buf.unwrap()[]
|
||||
}));
|
||||
buf = MemWriter::new();
|
||||
}
|
||||
@ -1682,7 +1682,7 @@ impl<'a> PostgresCopyInStatement<'a> {
|
||||
let _ = buf.write_be_i16(-1);
|
||||
try_pg!(conn.write_messages([
|
||||
CopyData {
|
||||
data: buf.unwrap().as_slice(),
|
||||
data: buf.unwrap()[],
|
||||
},
|
||||
CopyDone,
|
||||
Sync]));
|
||||
|
@ -168,7 +168,7 @@ impl<W: Writer> WriteMessage for W {
|
||||
}
|
||||
Some(ref value) => {
|
||||
try!(buf.write_be_i32(value.len() as i32));
|
||||
try!(buf.write(value.as_slice()));
|
||||
try!(buf.write(value[]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -229,8 +229,8 @@ impl<W: Writer> WriteMessage for W {
|
||||
StartupMessage { version, parameters } => {
|
||||
try!(buf.write_be_u32(version));
|
||||
for &(ref k, ref v) in parameters.iter() {
|
||||
try!(buf.write_cstr(k.as_slice()));
|
||||
try!(buf.write_cstr(v.as_slice()));
|
||||
try!(buf.write_cstr(k[]));
|
||||
try!(buf.write_cstr(v[]));
|
||||
}
|
||||
try!(buf.write_u8(0));
|
||||
}
|
||||
@ -251,7 +251,7 @@ impl<W: Writer> WriteMessage for W {
|
||||
let buf = buf.unwrap();
|
||||
// add size of length value
|
||||
try!(self.write_be_i32((buf.len() + mem::size_of::<i32>()) as i32));
|
||||
try!(self.write(buf.as_slice()));
|
||||
try!(self.write(buf[]));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ impl<T> ArrayBase<T> {
|
||||
|
||||
impl<T> Array<T> for ArrayBase<T> {
|
||||
fn dimension_info<'a>(&'a self) -> &'a [DimensionInfo] {
|
||||
self.info.as_slice()
|
||||
self.info[]
|
||||
}
|
||||
|
||||
fn slice<'a>(&'a self, idx: int) -> ArraySlice<'a, T> {
|
||||
@ -220,7 +220,7 @@ impl<'parent, T> Array<T> for ArraySlice<'parent, T> {
|
||||
MutSliceParent(p) => p.dimension_info(),
|
||||
BaseParent(p) => p.dimension_info()
|
||||
};
|
||||
info.slice_from(1)
|
||||
info[1..]
|
||||
}
|
||||
|
||||
fn slice<'a>(&'a self, idx: int) -> ArraySlice<'a, T> {
|
||||
@ -272,7 +272,7 @@ impl<'parent, T> Array<T> for MutArraySlice<'parent, T> {
|
||||
MutBaseParent(ref p) => mem::transmute(p.dimension_info()),
|
||||
}
|
||||
};
|
||||
info.slice_from(1)
|
||||
info[1..]
|
||||
}
|
||||
|
||||
fn slice<'a>(&'a self, idx: int) -> ArraySlice<'a, T> {
|
||||
|
@ -358,7 +358,7 @@ macro_rules! from_map_impl(
|
||||
macro_rules! from_raw_from_impl(
|
||||
($($expected:pat)|+, $t:ty) => (
|
||||
from_map_impl!($($expected)|+, $t, |buf: &Vec<u8>| {
|
||||
let mut reader = BufReader::new(buf.as_slice());
|
||||
let mut reader = BufReader::new(buf[]);
|
||||
RawFromSql::raw_from_sql(&mut reader)
|
||||
})
|
||||
)
|
||||
@ -383,7 +383,7 @@ from_raw_from_impl!(PgTsRange | PgTstzRange, Range<Timespec>)
|
||||
macro_rules! from_array_impl(
|
||||
($($oid:ident)|+, $t:ty) => (
|
||||
from_map_impl!($($oid)|+, ArrayBase<Option<$t>>, |buf: &Vec<u8>| {
|
||||
let mut rdr = BufReader::new(buf.as_slice());
|
||||
let mut rdr = BufReader::new(buf[]);
|
||||
|
||||
let ndim = try_pg!(rdr.read_be_i32()) as uint;
|
||||
let _has_null = try_pg!(rdr.read_be_i32()) == 1;
|
||||
@ -434,13 +434,13 @@ impl FromSql for Option<HashMap<String, Option<String>>> {
|
||||
fn from_sql(ty: &PostgresType, raw: &Option<Vec<u8>>)
|
||||
-> PostgresResult<Option<HashMap<String, Option<String>>>> {
|
||||
match *ty {
|
||||
PgUnknownType { name: ref name, .. } if "hstore" == name.as_slice() => {}
|
||||
PgUnknownType { name: ref name, .. } if "hstore" == name[] => {}
|
||||
_ => return Err(PgWrongType(ty.clone()))
|
||||
}
|
||||
|
||||
match *raw {
|
||||
Some(ref buf) => {
|
||||
let mut rdr = BufReader::new(buf.as_slice());
|
||||
let mut rdr = BufReader::new(buf[]);
|
||||
let mut map = HashMap::new();
|
||||
|
||||
let count = try_pg!(rdr.read_be_i32());
|
||||
@ -517,7 +517,7 @@ impl RawToSql for bool {
|
||||
|
||||
impl RawToSql for Vec<u8> {
|
||||
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> PostgresResult<()> {
|
||||
Ok(try_pg!(w.write(self.as_slice())))
|
||||
Ok(try_pg!(w.write(self[])))
|
||||
}
|
||||
}
|
||||
|
||||
@ -569,7 +569,7 @@ macro_rules! to_range_impl(
|
||||
try!(bound.value.raw_to_sql(&mut inner_buf));
|
||||
let inner_buf = inner_buf.unwrap();
|
||||
try_pg!(buf.write_be_i32(inner_buf.len() as i32));
|
||||
try_pg!(buf.write(inner_buf.as_slice()));
|
||||
try_pg!(buf.write(inner_buf[]));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
@ -579,7 +579,7 @@ macro_rules! to_range_impl(
|
||||
try!(bound.value.raw_to_sql(&mut inner_buf));
|
||||
let inner_buf = inner_buf.unwrap();
|
||||
try_pg!(buf.write_be_i32(inner_buf.len() as i32));
|
||||
try_pg!(buf.write(inner_buf.as_slice()));
|
||||
try_pg!(buf.write(inner_buf[]));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
@ -703,7 +703,7 @@ macro_rules! to_array_impl(
|
||||
try!(val.raw_to_sql(&mut inner_buf));
|
||||
let inner_buf = inner_buf.unwrap();
|
||||
try_pg!(buf.write_be_i32(inner_buf.len() as i32));
|
||||
try_pg!(buf.write(inner_buf.as_slice()));
|
||||
try_pg!(buf.write(inner_buf[]));
|
||||
}
|
||||
None => try_pg!(buf.write_be_i32(-1))
|
||||
}
|
||||
@ -735,7 +735,7 @@ to_array_impl!(PgJsonArray, Json)
|
||||
impl ToSql for HashMap<String, Option<String>> {
|
||||
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<Option<Vec<u8>>> {
|
||||
match *ty {
|
||||
PgUnknownType { name: ref name, .. } if "hstore" == name.as_slice() => {}
|
||||
PgUnknownType { name: ref name, .. } if "hstore" == name[] => {}
|
||||
_ => return Err(PgWrongType(ty.clone()))
|
||||
}
|
||||
|
||||
@ -763,7 +763,7 @@ impl ToSql for HashMap<String, Option<String>> {
|
||||
impl ToSql for Option<HashMap<String, Option<String>>> {
|
||||
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<Option<Vec<u8>>> {
|
||||
match *ty {
|
||||
PgUnknownType { name: ref name, .. } if "hstore" == name.as_slice() => {}
|
||||
PgUnknownType { name: ref name, .. } if "hstore" == name[] => {}
|
||||
_ => return Err(PgWrongType(ty.clone()))
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,6 @@ pub fn comma_join<'a, W, I>(writer: &mut W, mut strs: I) -> IoResult<()>
|
||||
}
|
||||
|
||||
pub fn parse_update_count(tag: String) -> uint {
|
||||
let s = tag.as_slice().split(' ').last().unwrap();
|
||||
let s = tag[].split(' ').last().unwrap();
|
||||
from_str(s).unwrap_or(0)
|
||||
}
|
||||
|
@ -95,10 +95,10 @@ fn test_unix_connection() {
|
||||
fail!("can't test connect_unix; unix_socket_directories is empty");
|
||||
}
|
||||
|
||||
let unix_socket_directory = unix_socket_directories.as_slice() .split(',').next().unwrap();
|
||||
let unix_socket_directory = unix_socket_directories[] .split(',').next().unwrap();
|
||||
|
||||
let url = format!("postgres://postgres@{}", url::encode_component(unix_socket_directory));
|
||||
let conn = or_fail!(PostgresConnection::connect(url.as_slice(), &NoSsl));
|
||||
let conn = or_fail!(PostgresConnection::connect(url[], &NoSsl));
|
||||
assert!(conn.finish().is_ok());
|
||||
}
|
||||
|
||||
@ -440,7 +440,7 @@ fn test_lazy_query_wrong_conn() {
|
||||
fn test_param_types() {
|
||||
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
|
||||
let stmt = or_fail!(conn.prepare("SELECT $1::INT, $2::VARCHAR"));
|
||||
assert_eq!(stmt.param_types(), [PgInt4, PgVarchar].as_slice());
|
||||
assert_eq!(stmt.param_types(), [PgInt4, PgVarchar][]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -542,7 +542,7 @@ fn test_custom_notice_handler() {
|
||||
|
||||
impl PostgresNoticeHandler for Handler {
|
||||
fn handle(&mut self, notice: PostgresDbError) {
|
||||
assert_eq!("note", notice.message.as_slice());
|
||||
assert_eq!("note", notice.message[]);
|
||||
unsafe { count += 1; }
|
||||
}
|
||||
}
|
||||
@ -698,12 +698,12 @@ fn test_execute_copy_from_err() {
|
||||
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", []));
|
||||
let stmt = or_fail!(conn.prepare("COPY foo (id) FROM STDIN"));
|
||||
match stmt.execute([]) {
|
||||
Err(PgDbError(ref err)) if err.message.as_slice().contains("COPY") => {}
|
||||
Err(PgDbError(ref err)) if err.message[].contains("COPY") => {}
|
||||
Err(err) => fail!("Unexptected error {}", err),
|
||||
_ => fail!("Expected error"),
|
||||
}
|
||||
match stmt.query([]) {
|
||||
Err(PgDbError(ref err)) if err.message.as_slice().contains("COPY") => {}
|
||||
Err(PgDbError(ref err)) if err.message[].contains("COPY") => {}
|
||||
Err(err) => fail!("Unexptected error {}", err),
|
||||
_ => fail!("Expected error"),
|
||||
}
|
||||
@ -734,7 +734,7 @@ fn test_copy_in_bad_column_count() {
|
||||
|
||||
let res = stmt.execute(data.iter().map(|r| r.iter().map(|&e| e)));
|
||||
match res {
|
||||
Err(PgDbError(ref err)) if err.message.as_slice().contains("Invalid column count") => {}
|
||||
Err(PgDbError(ref err)) if err.message[].contains("Invalid column count") => {}
|
||||
Err(err) => fail!("unexpected error {}", err),
|
||||
_ => fail!("Expected error"),
|
||||
}
|
||||
@ -743,7 +743,7 @@ fn test_copy_in_bad_column_count() {
|
||||
|
||||
let res = stmt.execute(data.iter().map(|r| r.iter().map(|&e| e)));
|
||||
match res {
|
||||
Err(PgDbError(ref err)) if err.message.as_slice().contains("Invalid column count") => {}
|
||||
Err(PgDbError(ref err)) if err.message[].contains("Invalid column count") => {}
|
||||
Err(err) => fail!("unexpected error {}", err),
|
||||
_ => fail!("Expected error"),
|
||||
}
|
||||
|
@ -15,11 +15,11 @@ mod range;
|
||||
fn test_type<T: PartialEq+FromSql+ToSql, S: Str>(sql_type: &str, checks: &[(T, S)]) {
|
||||
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
|
||||
for &(ref val, ref repr) in checks.iter() {
|
||||
let stmt = or_fail!(conn.prepare(format!("SELECT {:s}::{}", *repr, sql_type).as_slice()));
|
||||
let stmt = or_fail!(conn.prepare(format!("SELECT {:s}::{}", *repr, sql_type)[]));
|
||||
let result = or_fail!(stmt.query([])).next().unwrap().get(0u);
|
||||
assert!(val == &result);
|
||||
|
||||
let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type).as_slice()));
|
||||
let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type)[]));
|
||||
let result = or_fail!(stmt.query(&[val])).next().unwrap().get(0u);
|
||||
assert!(val == &result);
|
||||
}
|
||||
@ -194,13 +194,13 @@ macro_rules! test_array_params(
|
||||
let tests = [(Some(ArrayBase::from_vec(vec!(Some($v1), Some($v2), None), 1)),
|
||||
format!("'{{{},{},NULL}}'", $s1, $s2).into_string()),
|
||||
(None, "NULL".to_string())];
|
||||
test_type(format!("{}[]", $name).as_slice(), tests);
|
||||
test_type(format!("{}[]", $name)[], tests);
|
||||
let mut a = ArrayBase::from_vec(vec!(Some($v1), Some($v2)), 0);
|
||||
a.wrap(-1);
|
||||
a.push_move(ArrayBase::from_vec(vec!(None, Some($v3)), 0));
|
||||
let tests = [(Some(a), format!("'[-1:0][0:1]={{{{{},{}}},{{NULL,{}}}}}'",
|
||||
$s1, $s2, $s3).into_string())];
|
||||
test_type(format!("{}[][]", $name).as_slice(), tests);
|
||||
test_type(format!("{}[][]", $name)[], tests);
|
||||
})
|
||||
)
|
||||
|
||||
@ -335,13 +335,13 @@ fn test_hstore_params() {
|
||||
|
||||
fn test_nan_param<T: Float+ToSql+FromSql>(sql_type: &str) {
|
||||
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
|
||||
let stmt = or_fail!(conn.prepare(format!("SELECT 'NaN'::{}", sql_type).as_slice()));
|
||||
let stmt = or_fail!(conn.prepare(format!("SELECT 'NaN'::{}", sql_type)[]));
|
||||
let mut result = or_fail!(stmt.query([]));
|
||||
let val: T = result.next().unwrap().get(0u);
|
||||
assert!(val.is_nan());
|
||||
|
||||
let nan: T = Float::nan();
|
||||
let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type).as_slice()));
|
||||
let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type)[]));
|
||||
let mut result = or_fail!(stmt.query(&[&nan]));
|
||||
let val: T = result.next().unwrap().get(0u);
|
||||
assert!(val.is_nan())
|
||||
|
Loading…
Reference in New Issue
Block a user