git.iko.soy/typeable/postgresql-simple
on master help sign in
Add a typeOid field to the Field record
commit3a67b8d9772edeb0c61dcc35d382952917cd1cd5 authorLeon P Smith <leon@melding-monads.com> dateWed 30 Jan 2013, 04:11 (14 years ago) parentab14797
3 files changed+8−11
src/Database/PostgreSQL/Simple/FromField.hs−6 src/Database/PostgreSQL/Simple/FromRow.hs+5−4 src/Database/PostgreSQL/Simple/Internal.hs+3−1
src/Database/PostgreSQL/Simple/FromField.hs−6
@@ -219,12 +219,6 @@ tableColumn Field{..} = fromCol (unsafePerformIO (PQ.ftablecol result column))
219219format :: Field -> PQ.Format
220220format Field{..} = unsafePerformIO (PQ.fformat result column)
221221
222−-- | This returns the type oid associated with the column. Analogous
223−-- to libpq's @PQftype@.
224−
225−typeOid :: Field -> PQ.Oid
226−typeOid Field{..} = unsafePerformIO (PQ.ftype result column)
227−
228222instance (FromField a) => FromField (Maybe a) where
229223 fromField _ Nothing = pure Nothing
230224 fromField f bs = Just <$> fromField f bs
src/Database/PostgreSQL/Simple/FromRow.hs+5−4
@@ -92,7 +92,7 @@ fieldWith fieldP = RP $ do
9292 then lift $ lift $ do
9393 vals <- mapM (getTypenameByCol r) [0..ncols-1]
9494 let err = ConversionFailed
95− (show (unCol ncols) ++ " values: " ++ show vals)
95+ (show (unCol ncols) ++ " values: " ++ show (map ellipsis vals))
9696 Nothing
9797 ""
9898 ("at least " ++ show (unCol column + 1)
@@ -101,9 +101,10 @@ fieldWith fieldP = RP $ do
101101 \convert and number in target type"
102102 conversionError err
103103 else do
104− let result = rowresult
105− field = Field{..}
106− lift (lift (fieldP field (getvalue result row column)))
104+ let !result = rowresult
105+ !typeOid = unsafePerformIO (PQ.ftype result column)
106+ !field = Field{..}
107+ lift (lift (fieldP field (getvalue result row column)))
107108
108109field :: FromField a => RowParser a
109110field = fieldWith fromField
src/Database/PostgreSQL/Simple/Internal.hs+3−1
@@ -41,7 +41,6 @@ import Database.PostgreSQL.Simple.Ok
4141import Database.PostgreSQL.Simple.Types (Query(..))
4242import Control.Monad.Trans.State.Strict
4343import Control.Monad.Trans.Reader
44−import qualified Data.Vector as V
4544
4645-- | A Field represents metadata about a particular field
4746--
@@ -52,6 +51,9 @@ import qualified Data.Vector as V
5251data Field = Field {
5352 result :: !PQ.Result
5453 , column :: {-# UNPACK #-} !PQ.Column
54+ , typeOid :: {-# UNPACK #-} !PQ.Oid
55+ -- ^ This returns the type oid associated with the column. Analogous
56+ -- to libpq's @PQftype@.
5557 }
5658
5759data NamedOid = NamedOid { typoid :: !PQ.Oid