|
38 | 38 | //! } |
39 | 39 | //! } |
40 | 40 | //! ``` |
41 | | -#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.2")] |
| 41 | +#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.3")] |
42 | 42 | #![warn(missing_docs)] |
43 | 43 |
|
44 | 44 | extern crate bufstream; |
@@ -98,6 +98,7 @@ pub mod types; |
98 | 98 | pub mod notification; |
99 | 99 |
|
100 | 100 | const TYPEINFO_QUERY: &'static str = "__typeinfo"; |
| 101 | +const TYPEINFO_ENUM_QUERY: &'static str = "__typeinfo_enum"; |
101 | 102 | const TYPEINFO_ARRAY_QUERY: &'static str = "__typeinfo_array"; |
102 | 103 |
|
103 | 104 | /// A type alias of the result returned by many methods. |
@@ -464,12 +465,23 @@ impl InnerConnection { |
464 | 465 |
|
465 | 466 | #[cfg_attr(rustfmt, rustfmt_skip)] |
466 | 467 | fn setup_typeinfo_query(&mut self) -> result::Result<(), ConnectError> { |
| 468 | + match self.raw_prepare(TYPEINFO_ENUM_QUERY, |
| 469 | + "SELECT enumlabel \ |
| 470 | + FROM pg_catalog.pg_enum \ |
| 471 | + WHERE enumtypid = $1 \ |
| 472 | + ORDER BY enumsortorder") { |
| 473 | + Ok(..) => {} |
| 474 | + Err(Error::Io(e)) => return Err(ConnectError::Io(e)), |
| 475 | + Err(Error::Db(e)) => return Err(ConnectError::Db(e)), |
| 476 | + Err(Error::Conversion(_)) => unreachable!(), |
| 477 | + } |
| 478 | + |
467 | 479 | match self.raw_prepare(TYPEINFO_ARRAY_QUERY, |
468 | 480 | "SELECT attname, atttypid \ |
469 | 481 | FROM pg_catalog.pg_attribute \ |
470 | 482 | WHERE attrelid = $1 \ |
471 | | - AND NOT attisdropped \ |
472 | | - AND attnum > 0 \ |
| 483 | + AND NOT attisdropped \ |
| 484 | + AND attnum > 0 \ |
473 | 485 | ORDER BY attnum") { |
474 | 486 | Ok(..) => {} |
475 | 487 | Err(Error::Io(e)) => return Err(ConnectError::Io(e)), |
@@ -865,7 +877,19 @@ impl InnerConnection { |
865 | 877 | }; |
866 | 878 |
|
867 | 879 | let kind = if type_ == b'e' as i8 { |
868 | | - Kind::Enum |
| 880 | + try!(self.raw_execute(TYPEINFO_ENUM_QUERY, "", 0, &[Type::Oid], &[&oid])); |
| 881 | + let mut rows = VecDeque::new(); |
| 882 | + try!(self.read_rows(&mut rows)); |
| 883 | + |
| 884 | + let ctx = SessionInfo::new(self); |
| 885 | + let mut variants = vec![]; |
| 886 | + for row in rows { |
| 887 | + variants.push(try!(String::from_sql(&Type::Name, |
| 888 | + &mut &**row[0].as_ref().unwrap(), |
| 889 | + &ctx))); |
| 890 | + } |
| 891 | + |
| 892 | + Kind::Enum(variants) |
869 | 893 | } else if type_ == b'p' as i8 { |
870 | 894 | Kind::Pseudo |
871 | 895 | } else if basetype != 0 { |
|
0 commit comments