Skip to content
Browse files

Add a typeOid field to the Field record

  • Loading branch information...
1 parent ab14797 commit 3a67b8d9772edeb0c61dcc35d382952917cd1cd5 @lpsmith committed
View
6 src/Database/PostgreSQL/Simple/FromField.hs
@@ -219,12 +219,6 @@ tableColumn Field{..} = fromCol (unsafePerformIO (PQ.ftablecol result column))
format :: Field -> PQ.Format
format Field{..} = unsafePerformIO (PQ.fformat result column)
--- | This returns the type oid associated with the column. Analogous
--- to libpq's @PQftype@.
-
-typeOid :: Field -> PQ.Oid
-typeOid Field{..} = unsafePerformIO (PQ.ftype result column)
-
instance (FromField a) => FromField (Maybe a) where
fromField _ Nothing = pure Nothing
fromField f bs = Just <$> fromField f bs
View
9 src/Database/PostgreSQL/Simple/FromRow.hs
@@ -92,7 +92,7 @@ fieldWith fieldP = RP $ do
then lift $ lift $ do
vals <- mapM (getTypenameByCol r) [0..ncols-1]
let err = ConversionFailed
- (show (unCol ncols) ++ " values: " ++ show vals)
+ (show (unCol ncols) ++ " values: " ++ show (map ellipsis vals))
Nothing
""
("at least " ++ show (unCol column + 1)
@@ -101,9 +101,10 @@ fieldWith fieldP = RP $ do
\convert and number in target type"
conversionError err
else do
- let result = rowresult
- field = Field{..}
- lift (lift (fieldP field (getvalue result row column)))
+ let !result = rowresult
+ !typeOid = unsafePerformIO (PQ.ftype result column)
+ !field = Field{..}
+ lift (lift (fieldP field (getvalue result row column)))
field :: FromField a => RowParser a
field = fieldWith fromField
View
4 src/Database/PostgreSQL/Simple/Internal.hs
@@ -41,7 +41,6 @@ import Database.PostgreSQL.Simple.Ok
import Database.PostgreSQL.Simple.Types (Query(..))
import Control.Monad.Trans.State.Strict
import Control.Monad.Trans.Reader
-import qualified Data.Vector as V
-- | A Field represents metadata about a particular field
--
@@ -52,6 +51,9 @@ import qualified Data.Vector as V
data Field = Field {
result :: !PQ.Result
, column :: {-# UNPACK #-} !PQ.Column
+ , typeOid :: {-# UNPACK #-} !PQ.Oid
+ -- ^ This returns the type oid associated with the column. Analogous
+ -- to libpq's @PQftype@.
}
data NamedOid = NamedOid { typoid :: !PQ.Oid

0 comments on commit 3a67b8d

Please sign in to comment.
Something went wrong with that request. Please try again.