diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs index c56eebba6..0c979812d 100644 --- a/postgres-types/src/lib.rs +++ b/postgres-types/src/lib.rs @@ -313,23 +313,14 @@ impl fmt::Debug for Type { impl fmt::Display for Type { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - match self.schema() { - "public" | "pg_catalog" => {} - schema => write!(fmt, "{}.", schema)?, - } fmt.write_str(self.name()) } } impl Type { /// Creates a new `Type`. - pub fn new(name: String, oid: Oid, kind: Kind, schema: String) -> Type { - Type(Inner::Other(Arc::new(Other { - name, - oid, - kind, - schema, - }))) + pub fn new(name: String, oid: Oid, kind: Kind) -> Type { + Type(Inner::Other(Arc::new(Other { name, oid, kind }))) } /// Returns the `Type` corresponding to the provided `Oid` if it @@ -348,14 +339,6 @@ impl Type { self.0.kind() } - /// Returns the schema of this type. - pub fn schema(&self) -> &str { - match self.0 { - Inner::Other(ref u) => &u.schema, - _ => "pg_catalog", - } - } - /// Returns the name of this type. pub fn name(&self) -> &str { self.0.name() diff --git a/postgres-types/src/type_gen.rs b/postgres-types/src/type_gen.rs index a1bc3f85c..311dbdb96 100644 --- a/postgres-types/src/type_gen.rs +++ b/postgres-types/src/type_gen.rs @@ -8,7 +8,6 @@ pub struct Other { pub name: String, pub oid: Oid, pub kind: Kind, - pub schema: String, } #[derive(PartialEq, Eq, Clone, Debug, Hash)] diff --git a/tokio-postgres/src/error/mod.rs b/tokio-postgres/src/error/mod.rs index 75664d258..07b3fd152 100644 --- a/tokio-postgres/src/error/mod.rs +++ b/tokio-postgres/src/error/mod.rs @@ -357,6 +357,7 @@ enum Kind { #[cfg(feature = "runtime")] Connect, Timeout, + UnsupportedType, } struct ErrorInner { @@ -399,6 +400,7 @@ impl fmt::Display for Error { #[cfg(feature = "runtime")] Kind::Connect => fmt.write_str("error connecting to server")?, Kind::Timeout => fmt.write_str("timeout waiting for server")?, + Kind::UnsupportedType => fmt.write_str("unsupported type")?, }; if let Some(ref cause) = self.0.cause { write!(fmt, ": {}", cause)?; @@ -450,6 +452,10 @@ impl Error { Error::new(Kind::UnexpectedMessage, None) } + pub(crate) fn unsupported_type() -> Error { + Error::new(Kind::UnsupportedType, None) + } + #[allow(clippy::needless_pass_by_value)] pub(crate) fn db(error: ErrorResponseBody) -> Error { match DbError::parse(&mut error.fields()) { diff --git a/tokio-postgres/src/prepare.rs b/tokio-postgres/src/prepare.rs index f2aeea007..91dda738a 100644 --- a/tokio-postgres/src/prepare.rs +++ b/tokio-postgres/src/prepare.rs @@ -17,18 +17,15 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; const TYPEINFO_QUERY: &str = "\ -SELECT t.typname, t.typtype, t.typelem, r.rngsubtype, t.typbasetype, n.nspname, t.typrelid +SELECT t.typname, t.typtype, t.typelem, t.typbasetype, t.typrelid FROM pg_catalog.pg_type t -LEFT OUTER JOIN pg_catalog.pg_range r ON r.rngtypid = t.oid -INNER JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid WHERE t.oid = $1 "; // Range types weren't added until Postgres 9.2, so pg_range may not exist const TYPEINFO_FALLBACK_QUERY: &str = "\ -SELECT t.typname, t.typtype, t.typelem, NULL::OID, t.typbasetype, n.nspname, t.typrelid +SELECT t.typname, t.typtype, t.typelem, t.typbasetype, t.typrelid FROM pg_catalog.pg_type t -INNER JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid WHERE t.oid = $1 "; @@ -153,10 +150,8 @@ pub(crate) async fn get_type(client: &Arc, oid: Oid) -> Result = row.try_get(3)?; - let basetype: Oid = row.try_get(4)?; - let schema: String = row.try_get(5)?; - let relid: Oid = row.try_get(6)?; + let basetype: Oid = row.try_get(3)?; + let relid: Oid = row.try_get(4)?; let kind = if type_ == b'e' as i8 { // Note: Quaint is not using the variants information at any time. @@ -173,14 +168,13 @@ pub(crate) async fn get_type(client: &Arc, oid: Oid) -> Result