StrBuf -> String
This commit is contained in:
parent
584226bd23
commit
d2cd820f71
32
src/error.rs
32
src/error.rs
@ -17,7 +17,7 @@ macro_rules! make_errors(
|
||||
#[allow(missing_doc)]
|
||||
pub enum PostgresSqlState {
|
||||
$($error,)+
|
||||
UnknownSqlState(StrBuf)
|
||||
UnknownSqlState(String)
|
||||
}
|
||||
|
||||
static STATE_MAP: PhfMap<PostgresSqlState> = phf_map!(
|
||||
@ -359,7 +359,7 @@ make_errors!(
|
||||
/// Reasons a new Postgres connection could fail
|
||||
pub enum PostgresConnectError {
|
||||
/// The provided URL could not be parsed
|
||||
InvalidUrl(StrBuf),
|
||||
InvalidUrl(String),
|
||||
/// The URL was missing a user
|
||||
MissingUser,
|
||||
/// There was an error opening a socket to the server
|
||||
@ -412,7 +412,7 @@ pub enum PostgresErrorPosition {
|
||||
/// The byte position
|
||||
pub position: uint,
|
||||
/// A query generated by the Postgres server
|
||||
pub query: StrBuf
|
||||
pub query: String
|
||||
}
|
||||
}
|
||||
|
||||
@ -421,19 +421,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: StrBuf,
|
||||
pub severity: String,
|
||||
/// 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: StrBuf,
|
||||
pub message: String,
|
||||
/// An optional secondary error message carrying more detail about the
|
||||
/// problem. Might run to multiple lines.
|
||||
pub detail: Option<StrBuf>,
|
||||
pub detail: Option<String>,
|
||||
/// 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<StrBuf>,
|
||||
pub hint: Option<String>,
|
||||
/// An optional error cursor position into either the original query string
|
||||
/// or an internally generated query.
|
||||
pub position: Option<PostgresErrorPosition>,
|
||||
@ -441,39 +441,39 @@ 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<StrBuf>,
|
||||
pub where: Option<String>,
|
||||
/// 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<StrBuf>,
|
||||
pub schema: Option<String>,
|
||||
/// 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<StrBuf>,
|
||||
pub table: Option<String>,
|
||||
/// 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<StrBuf>,
|
||||
pub column: Option<String>,
|
||||
/// 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<StrBuf>,
|
||||
pub datatype: Option<String>,
|
||||
/// 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<StrBuf>,
|
||||
pub constraint: Option<String>,
|
||||
/// The file name of the source-code location where the error was reported.
|
||||
pub file: StrBuf,
|
||||
pub file: String,
|
||||
/// 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: StrBuf
|
||||
pub routine: String
|
||||
}
|
||||
|
||||
impl PostgresDbError {
|
||||
#[doc(hidden)]
|
||||
pub fn new(fields: Vec<(u8, StrBuf)>) -> PostgresDbError {
|
||||
pub fn new(fields: Vec<(u8, String)>) -> PostgresDbError {
|
||||
let mut map: HashMap<_, _> = fields.move_iter().collect();
|
||||
PostgresDbError {
|
||||
severity: map.pop(&('S' as u8)).unwrap(),
|
||||
|
36
src/lib.rs
36
src/lib.rs
@ -14,7 +14,7 @@ use postgres::types::ToSql;
|
||||
|
||||
struct Person {
|
||||
id: i32,
|
||||
name: StrBuf,
|
||||
name: String,
|
||||
time_created: Timespec,
|
||||
data: Option<Vec<u8>>
|
||||
}
|
||||
@ -206,7 +206,7 @@ pub type PostgresResult<T> = Result<T, PostgresError>;
|
||||
#[deriving(Clone)]
|
||||
pub enum PostgresConnectTarget {
|
||||
/// Connect via TCP to the specified host.
|
||||
TargetTcp(StrBuf),
|
||||
TargetTcp(String),
|
||||
/// Connect via a Unix domain socket in the specified directory.
|
||||
TargetUnix(Path)
|
||||
}
|
||||
@ -224,13 +224,13 @@ pub struct PostgresConnectParams {
|
||||
///
|
||||
/// `PostgresConnection::connect` requires a user but `cancel_query` does
|
||||
/// not.
|
||||
pub user: Option<StrBuf>,
|
||||
pub user: Option<String>,
|
||||
/// An optional password used for authentication
|
||||
pub password: Option<StrBuf>,
|
||||
pub password: Option<String>,
|
||||
/// The database to connect to. Defaults the value of `user`.
|
||||
pub database: Option<StrBuf>,
|
||||
pub database: Option<String>,
|
||||
/// Runtime parameters to be passed to the Postgres backend.
|
||||
pub options: Vec<(StrBuf, StrBuf)>,
|
||||
pub options: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
/// A trait implemented by types that can be converted into a
|
||||
@ -331,9 +331,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: StrBuf,
|
||||
pub channel: String,
|
||||
/// The "payload" string passed from the notifying process
|
||||
pub payload: StrBuf,
|
||||
pub payload: String,
|
||||
}
|
||||
|
||||
/// An iterator over asynchronous notifications
|
||||
@ -413,7 +413,7 @@ struct InnerPostgresConnection {
|
||||
notice_handler: Box<PostgresNoticeHandler:Send>,
|
||||
notifications: RingBuf<PostgresNotification>,
|
||||
cancel_data: PostgresCancelData,
|
||||
unknown_types: HashMap<Oid, StrBuf>,
|
||||
unknown_types: HashMap<Oid, String>,
|
||||
desynchronized: bool,
|
||||
finished: bool,
|
||||
trans_depth: u32,
|
||||
@ -523,7 +523,7 @@ impl InnerPostgresConnection {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_auth(&mut self, user: StrBuf, pass: Option<StrBuf>)
|
||||
fn handle_auth(&mut self, user: String, pass: Option<String>)
|
||||
-> Result<(), PostgresConnectError> {
|
||||
match try_pg_conn!(self.read_message()) {
|
||||
AuthenticationOk => return Ok(()),
|
||||
@ -649,7 +649,7 @@ impl InnerPostgresConnection {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_type_name(&mut self, oid: Oid) -> PostgresResult<StrBuf> {
|
||||
fn get_type_name(&mut self, oid: Oid) -> PostgresResult<String> {
|
||||
match self.unknown_types.find(&oid) {
|
||||
Some(name) => return Ok(name.clone()),
|
||||
None => {}
|
||||
@ -677,7 +677,7 @@ impl InnerPostgresConnection {
|
||||
}
|
||||
|
||||
fn quick_query(&mut self, query: &str)
|
||||
-> PostgresResult<Vec<Vec<Option<StrBuf>>>> {
|
||||
-> PostgresResult<Vec<Vec<Option<String>>>> {
|
||||
check_desync!(self);
|
||||
try_pg!(self.write_messages([Query { query: query }]));
|
||||
|
||||
@ -687,7 +687,7 @@ impl InnerPostgresConnection {
|
||||
ReadyForQuery { .. } => break,
|
||||
DataRow { row } => {
|
||||
result.push(row.move_iter().map(|opt| {
|
||||
opt.map(|b| StrBuf::from_utf8(b).unwrap())
|
||||
opt.map(|b| String::from_utf8(b).unwrap())
|
||||
}).collect());
|
||||
}
|
||||
ErrorResponse { fields } => {
|
||||
@ -901,7 +901,7 @@ impl PostgresConnection {
|
||||
}
|
||||
|
||||
fn quick_query(&self, query: &str)
|
||||
-> PostgresResult<Vec<Vec<Option<StrBuf>>>> {
|
||||
-> PostgresResult<Vec<Vec<Option<String>>>> {
|
||||
self.conn.borrow_mut().quick_query(query)
|
||||
}
|
||||
|
||||
@ -1045,7 +1045,7 @@ impl<'conn> PostgresTransaction<'conn> {
|
||||
/// A prepared statement
|
||||
pub struct PostgresStatement<'conn> {
|
||||
conn: &'conn PostgresConnection,
|
||||
name: StrBuf,
|
||||
name: String,
|
||||
param_types: Vec<PostgresType>,
|
||||
result_desc: Vec<ResultDescription>,
|
||||
next_portal_id: Cell<uint>,
|
||||
@ -1244,7 +1244,7 @@ impl<'conn> PostgresStatement<'conn> {
|
||||
#[deriving(Eq)]
|
||||
pub struct ResultDescription {
|
||||
/// The name of the column
|
||||
pub name: StrBuf,
|
||||
pub name: String,
|
||||
/// The type of the data in the column
|
||||
pub ty: PostgresType
|
||||
}
|
||||
@ -1252,7 +1252,7 @@ pub struct ResultDescription {
|
||||
/// An iterator over the resulting rows of a query.
|
||||
pub struct PostgresRows<'stmt> {
|
||||
stmt: &'stmt PostgresStatement<'stmt>,
|
||||
name: StrBuf,
|
||||
name: String,
|
||||
data: RingBuf<Vec<Option<Vec<u8>>>>,
|
||||
row_limit: uint,
|
||||
more_rows: bool,
|
||||
@ -1416,7 +1416,7 @@ impl<'stmt, I: RowIndex+Clone+fmt::Show, T: FromSql> Index<I, T>
|
||||
/// # let mut result = stmt.query([]).unwrap();
|
||||
/// # let row = result.next().unwrap();
|
||||
/// let foo: i32 = row[1];
|
||||
/// let bar: StrBuf = row["bar"];
|
||||
/// let bar: String = row["bar"];
|
||||
/// ```
|
||||
fn index(&self, idx: &I) -> T {
|
||||
match self.get(idx.clone()) {
|
||||
|
@ -24,30 +24,30 @@ pub enum BackendMessage {
|
||||
BindComplete,
|
||||
CloseComplete,
|
||||
CommandComplete {
|
||||
pub tag: StrBuf,
|
||||
pub tag: String,
|
||||
},
|
||||
DataRow {
|
||||
pub row: Vec<Option<Vec<u8>>>
|
||||
},
|
||||
EmptyQueryResponse,
|
||||
ErrorResponse {
|
||||
pub fields: Vec<(u8, StrBuf)>
|
||||
pub fields: Vec<(u8, String)>
|
||||
},
|
||||
NoData,
|
||||
NoticeResponse {
|
||||
pub fields: Vec<(u8, StrBuf)>
|
||||
pub fields: Vec<(u8, String)>
|
||||
},
|
||||
NotificationResponse {
|
||||
pub pid: i32,
|
||||
pub channel: StrBuf,
|
||||
pub payload: StrBuf,
|
||||
pub channel: String,
|
||||
pub payload: String,
|
||||
},
|
||||
ParameterDescription {
|
||||
pub types: Vec<Oid>
|
||||
},
|
||||
ParameterStatus {
|
||||
pub parameter: StrBuf,
|
||||
pub value: StrBuf,
|
||||
pub parameter: String,
|
||||
pub value: String,
|
||||
},
|
||||
ParseComplete,
|
||||
PortalSuspended,
|
||||
@ -60,7 +60,7 @@ pub enum BackendMessage {
|
||||
}
|
||||
|
||||
pub struct RowDescriptionEntry {
|
||||
pub name: StrBuf,
|
||||
pub name: String,
|
||||
pub table_oid: Oid,
|
||||
pub column_id: i16,
|
||||
pub type_oid: Oid,
|
||||
@ -110,7 +110,7 @@ pub enum FrontendMessage<'a> {
|
||||
},
|
||||
StartupMessage {
|
||||
pub version: i32,
|
||||
pub parameters: &'a [(StrBuf, StrBuf)]
|
||||
pub parameters: &'a [(String, String)]
|
||||
},
|
||||
Sync,
|
||||
Terminate
|
||||
@ -237,14 +237,14 @@ impl<W: Writer> WriteMessage for W {
|
||||
|
||||
#[doc(hidden)]
|
||||
trait ReadCStr {
|
||||
fn read_cstr(&mut self) -> IoResult<StrBuf>;
|
||||
fn read_cstr(&mut self) -> IoResult<String>;
|
||||
}
|
||||
|
||||
impl<R: Buffer> ReadCStr for R {
|
||||
fn read_cstr(&mut self) -> IoResult<StrBuf> {
|
||||
fn read_cstr(&mut self) -> IoResult<String> {
|
||||
let mut buf = try!(self.read_until(0));
|
||||
buf.pop();
|
||||
Ok(StrBuf::from_utf8(buf).unwrap())
|
||||
Ok(String::from_utf8(buf).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ impl<R: Reader> ReadMessage for R {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_fields(buf: &mut MemReader) -> IoResult<Vec<(u8, StrBuf)>> {
|
||||
fn read_fields(buf: &mut MemReader) -> IoResult<Vec<(u8, String)>> {
|
||||
let mut fields = Vec::new();
|
||||
loop {
|
||||
let ty = try!(buf.read_u8());
|
||||
|
@ -113,7 +113,7 @@ fn test_unix_connection() {
|
||||
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
|
||||
let stmt = or_fail!(conn.prepare("SHOW unix_socket_directories"));
|
||||
let result = or_fail!(stmt.query([]));
|
||||
let unix_socket_directories: StrBuf = result.map(|row| row[1]).next().unwrap();
|
||||
let unix_socket_directories: String = result.map(|row| row[1]).next().unwrap();
|
||||
|
||||
if unix_socket_directories.is_empty() {
|
||||
fail!("can't test connect_unix; unix_socket_directories is empty");
|
||||
@ -1028,6 +1028,6 @@ fn test_pg_database_datname() {
|
||||
let mut result = or_fail!(stmt.query([]));
|
||||
|
||||
let next = result.next().unwrap();
|
||||
or_fail!(next.get::<uint, StrBuf>(1));
|
||||
or_fail!(next.get::<&str, StrBuf>("datname"));
|
||||
or_fail!(next.get::<uint, String>(1));
|
||||
or_fail!(next.get::<&str, String>("datname"));
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ macro_rules! make_postgres_type(
|
||||
/// An unknown type
|
||||
PgUnknownType {
|
||||
/// The name of the type
|
||||
pub name: StrBuf,
|
||||
pub name: String,
|
||||
/// The OID of the type
|
||||
pub oid: Oid
|
||||
}
|
||||
@ -268,9 +268,9 @@ impl RawFromSql for Vec<u8> {
|
||||
}
|
||||
}
|
||||
|
||||
impl RawFromSql for StrBuf {
|
||||
fn raw_from_sql<R: Reader>(raw: &mut R) -> PostgresResult<StrBuf> {
|
||||
Ok(StrBuf::from_utf8(try_pg!(raw.read_to_end())).unwrap())
|
||||
impl RawFromSql for String {
|
||||
fn raw_from_sql<R: Reader>(raw: &mut R) -> PostgresResult<String> {
|
||||
Ok(String::from_utf8(try_pg!(raw.read_to_end())).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@ -399,7 +399,7 @@ macro_rules! from_raw_from_impl(
|
||||
|
||||
from_raw_from_impl!(PgBool, bool)
|
||||
from_raw_from_impl!(PgByteA, Vec<u8>)
|
||||
from_raw_from_impl!(PgVarchar | PgText | PgCharN | PgName, StrBuf)
|
||||
from_raw_from_impl!(PgVarchar | PgText | PgCharN | PgName, String)
|
||||
from_raw_from_impl!(PgChar, i8)
|
||||
from_raw_from_impl!(PgInt2, i16)
|
||||
from_raw_from_impl!(PgInt4, i32)
|
||||
@ -454,7 +454,7 @@ from_array_impl!(PgByteAArray, Vec<u8>)
|
||||
from_array_impl!(PgCharArray, i8)
|
||||
from_array_impl!(PgInt2Array, i16)
|
||||
from_array_impl!(PgInt4Array, i32)
|
||||
from_array_impl!(PgTextArray | PgCharNArray | PgVarcharArray | PgNameArray, StrBuf)
|
||||
from_array_impl!(PgTextArray | PgCharNArray | PgVarcharArray | PgNameArray, String)
|
||||
from_array_impl!(PgInt8Array, i64)
|
||||
from_array_impl!(PgTimestampArray | PgTimestampTZArray, Timespec)
|
||||
from_array_impl!(PgJsonArray, Json)
|
||||
@ -465,9 +465,9 @@ from_array_impl!(PgInt4RangeArray, Range<i32>)
|
||||
from_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>)
|
||||
from_array_impl!(PgInt8RangeArray, Range<i64>)
|
||||
|
||||
impl FromSql for Option<HashMap<StrBuf, Option<StrBuf>>> {
|
||||
impl FromSql for Option<HashMap<String, Option<String>>> {
|
||||
fn from_sql(ty: &PostgresType, raw: &Option<Vec<u8>>)
|
||||
-> PostgresResult<Option<HashMap<StrBuf, Option<StrBuf>>>> {
|
||||
-> PostgresResult<Option<HashMap<String, Option<String>>>> {
|
||||
match *ty {
|
||||
PgUnknownType { name: ref name, .. }
|
||||
if "hstore" == name.as_slice() => {}
|
||||
@ -484,14 +484,14 @@ impl FromSql for Option<HashMap<StrBuf, Option<StrBuf>>> {
|
||||
for _ in range(0, count) {
|
||||
let key_len = try_pg!(rdr.read_be_i32());
|
||||
let key = try_pg!(rdr.read_exact(key_len as uint));
|
||||
let key = StrBuf::from_utf8(key).unwrap();
|
||||
let key = String::from_utf8(key).unwrap();
|
||||
|
||||
let val_len = try_pg!(rdr.read_be_i32());
|
||||
let val = if val_len < 0 {
|
||||
None
|
||||
} else {
|
||||
let val = try_pg!(rdr.read_exact(val_len as uint));
|
||||
Some(StrBuf::from_utf8(val).unwrap())
|
||||
Some(String::from_utf8(val).unwrap())
|
||||
};
|
||||
|
||||
map.insert(key, val);
|
||||
@ -503,11 +503,11 @@ impl FromSql for Option<HashMap<StrBuf, Option<StrBuf>>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromSql for HashMap<StrBuf, Option<StrBuf>> {
|
||||
impl FromSql for HashMap<String, Option<String>> {
|
||||
fn from_sql(ty: &PostgresType, raw: &Option<Vec<u8>>)
|
||||
-> PostgresResult<HashMap<StrBuf, Option<StrBuf>>> {
|
||||
-> PostgresResult<HashMap<String, Option<String>>> {
|
||||
// FIXME when you can specify Self types properly
|
||||
let ret: PostgresResult<Option<HashMap<StrBuf, Option<StrBuf>>>> =
|
||||
let ret: PostgresResult<Option<HashMap<String, Option<String>>>> =
|
||||
FromSql::from_sql(ty, raw);
|
||||
match ret {
|
||||
Ok(Some(val)) => Ok(val),
|
||||
@ -552,7 +552,7 @@ impl RawToSql for Vec<u8> {
|
||||
}
|
||||
}
|
||||
|
||||
impl RawToSql for StrBuf {
|
||||
impl RawToSql for String {
|
||||
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> PostgresResult<()> {
|
||||
Ok(try_pg!(w.write(self.as_bytes())))
|
||||
}
|
||||
@ -692,7 +692,7 @@ macro_rules! to_raw_to_impl(
|
||||
|
||||
to_raw_to_impl!(PgBool, bool)
|
||||
to_raw_to_impl!(PgByteA, Vec<u8>)
|
||||
to_raw_to_impl!(PgVarchar | PgText | PgCharN | PgName, StrBuf)
|
||||
to_raw_to_impl!(PgVarchar | PgText | PgCharN | PgName, String)
|
||||
to_raw_to_impl!(PgJson, Json)
|
||||
to_raw_to_impl!(PgChar, i8)
|
||||
to_raw_to_impl!(PgInt2, i16)
|
||||
@ -771,7 +771,7 @@ to_array_impl!(PgCharArray, i8)
|
||||
to_array_impl!(PgInt2Array, i16)
|
||||
to_array_impl!(PgInt4Array, i32)
|
||||
to_array_impl!(PgInt8Array, i64)
|
||||
to_array_impl!(PgTextArray | PgCharNArray | PgVarcharArray | PgNameArray, StrBuf)
|
||||
to_array_impl!(PgTextArray | PgCharNArray | PgVarcharArray | PgNameArray, String)
|
||||
to_array_impl!(PgTimestampArray | PgTimestampTZArray, Timespec)
|
||||
to_array_impl!(PgFloat4Array, f32)
|
||||
to_array_impl!(PgFloat8Array, f64)
|
||||
@ -781,7 +781,7 @@ to_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>)
|
||||
to_array_impl!(PgInt8RangeArray, Range<i64>)
|
||||
to_array_impl!(PgJsonArray, Json)
|
||||
|
||||
impl ToSql for HashMap<StrBuf, Option<StrBuf>> {
|
||||
impl ToSql for HashMap<String, Option<String>> {
|
||||
fn to_sql(&self, ty: &PostgresType)
|
||||
-> PostgresResult<(Format, Option<Vec<u8>>)> {
|
||||
match *ty {
|
||||
@ -811,7 +811,7 @@ impl ToSql for HashMap<StrBuf, Option<StrBuf>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSql for Option<HashMap<StrBuf, Option<StrBuf>>> {
|
||||
impl ToSql for Option<HashMap<String, Option<String>>> {
|
||||
fn to_sql(&self, ty: &PostgresType)
|
||||
-> PostgresResult<(Format, Option<Vec<u8>>)> {
|
||||
match *ty {
|
||||
|
Loading…
Reference in New Issue
Block a user