More ~str -> StrBuf
This commit is contained in:
parent
dc6bb579c2
commit
d1c412b393
38
src/error.rs
38
src/error.rs
@ -415,7 +415,7 @@ pub enum PostgresErrorPosition {
|
||||
/// The byte position
|
||||
pub position: uint,
|
||||
/// A query generated by the Postgres server
|
||||
pub query: ~str
|
||||
pub query: StrBuf
|
||||
}
|
||||
}
|
||||
|
||||
@ -424,19 +424,19 @@ pub struct PostgresDbError {
|
||||
/// The field contents are ERROR, FATAL, or PANIC (in an error message),
|
||||
/// or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message), or a
|
||||
/// localized translation of one of these.
|
||||
pub severity: ~str,
|
||||
pub severity: StrBuf,
|
||||
/// The SQLSTATE code for the error.
|
||||
pub code: PostgresSqlState,
|
||||
/// The primary human-readable error message. This should be accurate but
|
||||
/// terse (typically one line).
|
||||
pub message: ~str,
|
||||
pub message: StrBuf,
|
||||
/// An optional secondary error message carrying more detail about the
|
||||
/// problem. Might run to multiple lines.
|
||||
pub detail: Option<~str>,
|
||||
pub detail: Option<StrBuf>,
|
||||
/// An optional suggestion what to do about the problem. This is intended
|
||||
/// to differ from Detail in that it offers advice (potentially
|
||||
/// inappropriate) rather than hard facts. Might run to multiple lines.
|
||||
pub hint: Option<~str>,
|
||||
pub hint: Option<StrBuf>,
|
||||
/// An optional error cursor position into either the original query string
|
||||
/// or an internally generated query.
|
||||
pub position: Option<PostgresErrorPosition>,
|
||||
@ -444,51 +444,51 @@ pub struct PostgresDbError {
|
||||
/// this includes a call stack traceback of active procedural language
|
||||
/// functions and internally-generated queries. The trace is one entry per
|
||||
/// line, most recent first.
|
||||
pub where: Option<~str>,
|
||||
pub where: Option<StrBuf>,
|
||||
/// If the error was associated with a specific database object, the name
|
||||
/// of the schema containing that object, if any. (PostgreSQL 9.3+)
|
||||
pub schema: Option<~str>,
|
||||
pub schema: Option<StrBuf>,
|
||||
/// If the error was associated with a specific table, the name of the
|
||||
/// table. (Refer to the schema name field for the name of the table's
|
||||
/// schema.) (PostgreSQL 9.3+)
|
||||
pub table: Option<~str>,
|
||||
pub table: Option<StrBuf>,
|
||||
/// If the error was associated with a specific table column, the name of
|
||||
/// the column. (Refer to the schema and table name fields to identify the
|
||||
/// table.) (PostgreSQL 9.3+)
|
||||
pub column: Option<~str>,
|
||||
pub column: Option<StrBuf>,
|
||||
/// If the error was associated with a specific data type, the name of the
|
||||
/// data type. (Refer to the schema name field for the name of the data
|
||||
/// type's schema.) (PostgreSQL 9.3+)
|
||||
pub datatype: Option<~str>,
|
||||
pub datatype: Option<StrBuf>,
|
||||
/// If the error was associated with a specific constraint, the name of the
|
||||
/// constraint. Refer to fields listed above for the associated table or
|
||||
/// domain. (For this purpose, indexes are treated as constraints, even if
|
||||
/// they weren't created with constraint syntax.) (PostgreSQL 9.3+)
|
||||
pub constraint: Option<~str>,
|
||||
pub constraint: Option<StrBuf>,
|
||||
/// The file name of the source-code location where the error was reported.
|
||||
pub file: ~str,
|
||||
pub file: StrBuf,
|
||||
/// The line number of the source-code location where the error was
|
||||
/// reported.
|
||||
pub line: uint,
|
||||
/// The name of the source-code routine reporting the error.
|
||||
pub routine: ~str
|
||||
pub routine: StrBuf
|
||||
}
|
||||
|
||||
impl PostgresDbError {
|
||||
#[doc(hidden)]
|
||||
pub fn new(fields: Vec<(u8, ~str)>) -> PostgresDbError {
|
||||
let mut map: HashMap<u8, ~str> = fields.move_iter().collect();
|
||||
pub fn new(fields: Vec<(u8, StrBuf)>) -> PostgresDbError {
|
||||
let mut map: HashMap<_, _> = fields.move_iter().collect();
|
||||
PostgresDbError {
|
||||
severity: map.pop(&('S' as u8)).unwrap(),
|
||||
code: PostgresSqlState::from_code(map.pop(&('C' as u8)).unwrap()),
|
||||
code: PostgresSqlState::from_code(map.pop(&('C' as u8)).unwrap().as_slice()),
|
||||
message: map.pop(&('M' as u8)).unwrap(),
|
||||
detail: map.pop(&('D' as u8)),
|
||||
hint: map.pop(&('H' as u8)),
|
||||
position: match map.pop(&('P' as u8)) {
|
||||
Some(pos) => Some(Position(FromStr::from_str(pos).unwrap())),
|
||||
Some(pos) => Some(Position(FromStr::from_str(pos.as_slice()).unwrap())),
|
||||
None => match map.pop(&('p' as u8)) {
|
||||
Some(pos) => Some(InternalPosition {
|
||||
position: FromStr::from_str(pos).unwrap(),
|
||||
position: FromStr::from_str(pos.as_slice()).unwrap(),
|
||||
query: map.pop(&('q' as u8)).unwrap()
|
||||
}),
|
||||
None => None
|
||||
@ -501,7 +501,7 @@ impl PostgresDbError {
|
||||
datatype: map.pop(&('d' as u8)),
|
||||
constraint: map.pop(&('n' as u8)),
|
||||
file: map.pop(&('F' as u8)).unwrap(),
|
||||
line: FromStr::from_str(map.pop(&('L' as u8)).unwrap()).unwrap(),
|
||||
line: FromStr::from_str(map.pop(&('L' as u8)).unwrap().as_slice()).unwrap(),
|
||||
routine: map.pop(&('R' as u8)).unwrap()
|
||||
}
|
||||
}
|
||||
|
@ -323,9 +323,9 @@ pub struct PostgresNotification {
|
||||
/// The process ID of the notifying backend process
|
||||
pub pid: i32,
|
||||
/// The name of the channel that the notify has been raised on
|
||||
pub channel: ~str,
|
||||
pub channel: StrBuf,
|
||||
/// The "payload" string passed from the notifying process
|
||||
pub payload: ~str,
|
||||
pub payload: StrBuf,
|
||||
}
|
||||
|
||||
/// An iterator over asynchronous notifications
|
||||
@ -1174,7 +1174,7 @@ impl<'conn> PostgresStatement<'conn> {
|
||||
return Err(PgDbError(PostgresDbError::new(fields)));
|
||||
}
|
||||
CommandComplete { tag } => {
|
||||
let s = tag.split(' ').last().unwrap();
|
||||
let s = tag.as_slice().split(' ').last().unwrap();
|
||||
num = FromStr::from_str(s).unwrap_or(0);
|
||||
break;
|
||||
}
|
||||
@ -1230,7 +1230,7 @@ impl<'conn> PostgresStatement<'conn> {
|
||||
#[deriving(Eq)]
|
||||
pub struct ResultDescription {
|
||||
/// The name of the column
|
||||
pub name: ~str,
|
||||
pub name: StrBuf,
|
||||
/// The type of the data in the column
|
||||
pub ty: PostgresType
|
||||
}
|
||||
|
@ -24,30 +24,30 @@ pub enum BackendMessage {
|
||||
BindComplete,
|
||||
CloseComplete,
|
||||
CommandComplete {
|
||||
pub tag: ~str
|
||||
pub tag: StrBuf,
|
||||
},
|
||||
DataRow {
|
||||
pub row: Vec<Option<Vec<u8>>>
|
||||
},
|
||||
EmptyQueryResponse,
|
||||
ErrorResponse {
|
||||
pub fields: Vec<(u8, ~str)>
|
||||
pub fields: Vec<(u8, StrBuf)>
|
||||
},
|
||||
NoData,
|
||||
NoticeResponse {
|
||||
pub fields: Vec<(u8, ~str)>
|
||||
pub fields: Vec<(u8, StrBuf)>
|
||||
},
|
||||
NotificationResponse {
|
||||
pub pid: i32,
|
||||
pub channel: ~str,
|
||||
pub payload: ~str
|
||||
pub channel: StrBuf,
|
||||
pub payload: StrBuf,
|
||||
},
|
||||
ParameterDescription {
|
||||
pub types: Vec<Oid>
|
||||
},
|
||||
ParameterStatus {
|
||||
pub parameter: ~str,
|
||||
pub value: ~str
|
||||
pub parameter: StrBuf,
|
||||
pub value: StrBuf,
|
||||
},
|
||||
ParseComplete,
|
||||
PortalSuspended,
|
||||
@ -60,7 +60,7 @@ pub enum BackendMessage {
|
||||
}
|
||||
|
||||
pub struct RowDescriptionEntry {
|
||||
pub name: ~str,
|
||||
pub name: StrBuf,
|
||||
pub table_oid: Oid,
|
||||
pub column_id: i16,
|
||||
pub type_oid: Oid,
|
||||
@ -237,14 +237,14 @@ impl<W: Writer> WriteMessage for W {
|
||||
|
||||
#[doc(hidden)]
|
||||
trait ReadCStr {
|
||||
fn read_cstr(&mut self) -> IoResult<~str>;
|
||||
fn read_cstr(&mut self) -> IoResult<StrBuf>;
|
||||
}
|
||||
|
||||
impl<R: Buffer> ReadCStr for R {
|
||||
fn read_cstr(&mut self) -> IoResult<~str> {
|
||||
fn read_cstr(&mut self) -> IoResult<StrBuf> {
|
||||
let mut buf = try!(self.read_until(0));
|
||||
buf.pop();
|
||||
Ok(StrBuf::from_utf8(buf).unwrap().into_owned())
|
||||
Ok(StrBuf::from_utf8(buf).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ impl<R: Reader> ReadMessage for R {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_fields(buf: &mut MemReader) -> IoResult<Vec<(u8, ~str)>> {
|
||||
fn read_fields(buf: &mut MemReader) -> IoResult<Vec<(u8, StrBuf)>> {
|
||||
let mut fields = Vec::new();
|
||||
loop {
|
||||
let ty = try!(buf.read_u8());
|
||||
|
16
src/test.rs
16
src/test.rs
@ -365,8 +365,8 @@ fn test_result_descriptions() {
|
||||
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
|
||||
let stmt = or_fail!(conn.prepare("SELECT 1::INT as a, 'hi'::VARCHAR as b"));
|
||||
assert!(stmt.result_descriptions() ==
|
||||
[ResultDescription { name: "a".to_owned(), ty: PgInt4},
|
||||
ResultDescription { name: "b".to_owned(), ty: PgVarchar}]);
|
||||
[ResultDescription { name: "a".to_strbuf(), ty: PgInt4},
|
||||
ResultDescription { name: "b".to_strbuf(), ty: PgVarchar}]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -869,21 +869,21 @@ fn test_notification_iterator_some() {
|
||||
|
||||
check_notification(PostgresNotification {
|
||||
pid: 0,
|
||||
channel: "test_notification_iterator_one_channel".to_owned(),
|
||||
payload: "hello".to_owned()
|
||||
channel: "test_notification_iterator_one_channel".to_strbuf(),
|
||||
payload: "hello".to_strbuf()
|
||||
}, it.next());
|
||||
check_notification(PostgresNotification {
|
||||
pid: 0,
|
||||
channel: "test_notification_iterator_one_channel2".to_owned(),
|
||||
payload: "world".to_owned()
|
||||
channel: "test_notification_iterator_one_channel2".to_strbuf(),
|
||||
payload: "world".to_strbuf()
|
||||
}, it.next());
|
||||
assert!(it.next().is_none());
|
||||
|
||||
or_fail!(conn.execute("NOTIFY test_notification_iterator_one_channel, '!'", []));
|
||||
check_notification(PostgresNotification {
|
||||
pid: 0,
|
||||
channel: "test_notification_iterator_one_channel".to_owned(),
|
||||
payload: "!".to_owned()
|
||||
channel: "test_notification_iterator_one_channel".to_strbuf(),
|
||||
payload: "!".to_strbuf()
|
||||
}, it.next());
|
||||
assert!(it.next().is_none());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user