@@ -98,6 +98,7 @@ pub mod types;
9898pub mod notification;
9999
100100const TYPEINFO_QUERY : & ' static str = "__typeinfo" ;
101+ const TYPEINFO_ENUM_QUERY : & ' static str = "__typeinfo_enum" ;
101102const TYPEINFO_ARRAY_QUERY : & ' static str = "__typeinfo_array" ;
102103
103104/// A type alias of the result returned by many methods.
@@ -464,12 +465,23 @@ impl InnerConnection {
464465
465466 #[ cfg_attr( rustfmt, rustfmt_skip) ]
466467 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+
467479 match self . raw_prepare ( TYPEINFO_ARRAY_QUERY ,
468480 "SELECT attname, atttypid \
469481 FROM pg_catalog.pg_attribute \
470482 WHERE attrelid = $1 \
471- AND NOT attisdropped \
472- AND attnum > 0 \
483+ AND NOT attisdropped \
484+ AND attnum > 0 \
473485 ORDER BY attnum") {
474486 Ok ( ..) => { }
475487 Err ( Error :: Io ( e) ) => return Err ( ConnectError :: Io ( e) ) ,
@@ -865,7 +877,19 @@ impl InnerConnection {
865877 } ;
866878
867879 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)
869893 } else if type_ == b'p' as i8 {
870894 Kind :: Pseudo
871895 } else if basetype != 0 {
0 commit comments