Permalink
Browse files

Add support for Range types to TypeInfo system

  • Loading branch information...
1 parent f685f92 commit db14cf8ded7f270e63d1b19d573b76ddac153d02 @lpsmith committed Mar 26, 2013
@@ -1,8 +1,11 @@
module Database.PostgreSQL.Simple.FromRow where
import {-# SOURCE #-} Database.PostgreSQL.Simple.FromField
+import Database.PostgreSQL.Simple.Types
class FromRow a
+instance (FromField a) => FromRow (Only a)
instance (FromField a, FromField b, FromField c, FromField d) => FromRow (a,b,c,d)
instance (FromField a, FromField b, FromField c, FromField d, FromField e) => FromRow (a,b,c,d,e)
+
@@ -67,12 +67,24 @@ getTypeInfo' conn oid oidmap =
[(typoid, typcategory_, typdelim_, typname, typelem_)] -> do
let !typcategory = B8.index typcategory_ 0
!typdelim = B8.index typdelim_ 0
- if typcategory == 'A'
- then do
+ case typcategory of
+ 'A' -> do
(oidmap', typelem) <- getTypeInfo' conn typelem_ oidmap
let !typeInfo = Array{..}
return (oidmap', typeInfo)
- else do
+ 'R' -> do
+ rngsubtypeOids <- query conn "SELECT rngsubtype\
+ \ FROM pg_range\
+ \ WHERE rngtypid = ?"
+ (Only oid)
+ case rngsubtypeOids of
+ [Only rngsubtype_] -> do
+ (oidmap', rngsubtype) <-
+ getTypeInfo' conn rngsubtype_ oidmap
+ let !typeInfo = Range{..}
+ return (oidmap', typeInfo)
+ _ -> fail "range subtype query failed to return exactly one result"
+ _ -> do
let !typeInfo = Basic{..}
return (oidmap, typeInfo)
_ -> fail "typename query returned more than one result"
@@ -30,4 +30,12 @@ data TypeInfo
, typname :: !ByteString
, typelem :: !TypeInfo
}
+
+ | Range { typoid :: {-# UNPACK #-} !Oid
+ , typcategory :: {-# UNPACK #-} !Char
+ , typdelim :: {-# UNPACK #-} !Char
+ , typname :: !ByteString
+ , rngsubtype :: !TypeInfo
+ }
+
deriving (Show)

0 comments on commit db14cf8

Please sign in to comment.