sqlite-simple-0.4.15.0: Mid-Level SQLite client library

Copyright(c) 2011 MailRank Inc.
(c) 2011-2012 Leon P Smith
(c) 2012-2013 Janne Hellsten
LicenseBSD3
MaintainerJanne Hellsten <jjhellst@gmail.com>
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Database.SQLite.Simple.FromField

Description

The FromField typeclass, for converting a single value in a row returned by a SQL query into a more useful Haskell representation.

A Haskell numeric type is considered to be compatible with all SQLite numeric types that are less accurate than it. For instance, the Haskell Double type is compatible with the SQLite's 32-bit Int type because it can represent a Int exactly. On the other hand, since a Double might lose precision if representing a 64-bit BigInt, the two are not considered compatible.

Synopsis

Documentation

class FromField a where Source #

A type that may be converted from a SQL type.

Minimal complete definition

fromField

Methods

fromField :: FieldParser a Source #

Convert a SQL value to a Haskell value.

Returns a list of exceptions if the conversion fails. In the case of library instances, this will usually be a single ResultError, but may be a UnicodeException.

Implementations of fromField should not retain any references to the Field nor the ByteString arguments after the result has been evaluated to WHNF. Such a reference causes the entire LibPQ.Result to be retained.

For example, the instance for ByteString uses copy to avoid such a reference, and that using bytestring functions such as drop and takeWhile alone will also trigger this memory leak.

Instances

FromField Bool Source # 
FromField Double Source # 
FromField Float Source # 
FromField Int Source # 
FromField Int8 Source # 
FromField Int16 Source # 
FromField Int32 Source # 
FromField Int64 Source # 
FromField Integer Source # 
FromField Word Source # 
FromField Word8 Source # 
FromField Word16 Source # 
FromField Word32 Source # 
FromField Word64 Source # 
FromField ByteString Source # 
FromField ByteString Source # 
FromField Text Source # 
FromField Text Source # 
FromField UTCTime Source # 
FromField Day Source # 
FromField Null Source # 
FromField [Char] Source # 
FromField a => FromField (Maybe a) Source # 

type FieldParser a = Field -> Ok a Source #

data ResultError Source #

Exception thrown if conversion from a SQL value to a Haskell value fails.

Constructors

Incompatible

The SQL and Haskell types are not compatible.

UnexpectedNull

A SQL NULL was encountered when the Haskell type did not permit it.

ConversionFailed

The SQL value could not be parsed, or could not be represented as a valid Haskell value, or an unexpected low-level error occurred (e.g. mismatch between metadata and actual data in a row).

data Field Source #

A Field represents metadata about a particular field

fieldData :: Field -> SQLData Source #

Return the actual SQL data for a database field. This allows user-defined FromField instances to access the SQL data associated with a field being parsed.

returnError :: forall a err. (Typeable a, Exception err) => (String -> String -> String -> err) -> Field -> String -> Ok a Source #

Given one of the constructors from ResultError, the field, and an errMessage, this fills in the other fields in the exception value and returns it in a 'Left . SomeException' constructor.