Copyright | (c) Winterland, 2016 |
---|---|
License | BSD |
Maintainer | drkoster@qq.com |
Stability | experimental |
Portability | PORTABLE |
Safe Haskell | None |
Language | Haskell2010 |
Core text and binary row decoder/encoder machinery.
- data MySQLValue
- = MySQLDecimal !Scientific
- | MySQLInt8U !Word8
- | MySQLInt8 !Int8
- | MySQLInt16U !Word16
- | MySQLInt16 !Int16
- | MySQLInt32U !Word32
- | MySQLInt32 !Int32
- | MySQLInt64U !Word64
- | MySQLInt64 !Int64
- | MySQLFloat !Float
- | MySQLDouble !Double
- | MySQLYear !Word16
- | MySQLDateTime !LocalTime
- | MySQLTimeStamp !LocalTime
- | MySQLDate !Day
- | MySQLTime !Word8 !TimeOfDay
- | MySQLGeometry !ByteString
- | MySQLBytes !ByteString
- | MySQLBit !Word64
- | MySQLText !Text
- | MySQLNull
- putParamMySQLType :: MySQLValue -> Put
- getTextField :: ColumnDef -> Get MySQLValue
- feedLenEncBytes :: FieldType -> (t -> b) -> (ByteString -> Maybe t) -> Get b
- putTextField :: MySQLValue -> Put
- putInQuotes :: Put -> Put
- getTextRow :: [ColumnDef] -> Get [MySQLValue]
- getBinaryField :: ColumnDef -> Get MySQLValue
- getBits :: Int -> Get Word64
- putTextBits :: Word64 -> Put
- putBinaryField :: MySQLValue -> Put
- putBinaryDay :: Day -> Put
- putBinaryTime' :: TimeOfDay -> Put
- putBinaryTime :: TimeOfDay -> Put
- getBinaryRow :: [ColumnDef] -> Int -> Get [MySQLValue]
- newtype BitMap = BitMap {}
- isColumnSet :: BitMap -> Int -> Bool
- makeNullMap :: [MySQLValue] -> BitMap
Documentation
data MySQLValue Source #
Data type mapping between MySQL values and haskell values.
There're some subtle differences between MySQL values and haskell values:
MySQL's DATETIME
and TIMESTAMP
are different on timezone handling:
- DATETIME and DATE is just a represent of a calendar date, it has no timezone information involved, you always get the same value as you put no matter what timezone you're using with MySQL.
- MySQL converts TIMESTAMP values from the current time zone to UTC for storage,
and back from UTC to the current time zone for retrieval. If you put a TIMESTAMP with timezone A,
then read it with timezone B, you may get different result because of this conversion, so always
be careful about setting up the right timezone with MySQL, you can do it with a simple
SET time_zone = timezone;
for more info on timezone support, please read http://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html
So we use LocalTime
to present both DATETIME
and TIMESTAMP
, but the local here is different.
MySQL's TIME
type can present time of day, but also elapsed time or a time interval between two events.
TIME
values may range from -838:59:59
to 838:59:59
, so MySQLTime
values consist of a sign and a
TimeOfDay
whose hour part may exceeded 24. you can use timeOfDayToTime
to get the absolute time interval.
Under MySQL >= 5.7, DATETIME
, TIMESTAMP
and TIME
may contain fractional part, which matches haskell's
precision.
MySQLDecimal !Scientific | DECIMAL, NEWDECIMAL |
MySQLInt8U !Word8 | Unsigned TINY |
MySQLInt8 !Int8 | TINY |
MySQLInt16U !Word16 | Unsigned SHORT |
MySQLInt16 !Int16 | SHORT |
MySQLInt32U !Word32 | Unsigned LONG, INT24 |
MySQLInt32 !Int32 | LONG, INT24 |
MySQLInt64U !Word64 | Unsigned LONGLONG |
MySQLInt64 !Int64 | LONGLONG |
MySQLFloat !Float | IEEE 754 single precision format |
MySQLDouble !Double | IEEE 754 double precision format |
MySQLYear !Word16 | YEAR |
MySQLDateTime !LocalTime | DATETIME |
MySQLTimeStamp !LocalTime | TIMESTAMP |
MySQLDate !Day | DATE |
MySQLTime !Word8 !TimeOfDay | sign(0 = non-negative, 1 = negative) hh mm ss microsecond The sign is OPPOSITE to binlog one !!! |
MySQLGeometry !ByteString | todo: parsing to something meanful |
MySQLBytes !ByteString | |
MySQLBit !Word64 | |
MySQLText !Text | |
MySQLNull |
putParamMySQLType :: MySQLValue -> Put Source #
Decide if usigned bit(0x80) and FieldType
for MySQLValue
s.
getTextField :: ColumnDef -> Get MySQLValue Source #
Text protocol decoder
feedLenEncBytes :: FieldType -> (t -> b) -> (ByteString -> Maybe t) -> Get b Source #
putTextField :: MySQLValue -> Put Source #
Text protocol encoder
putInQuotes :: Put -> Put Source #
getTextRow :: [ColumnDef] -> Get [MySQLValue] Source #
Text row decoder
getBinaryField :: ColumnDef -> Get MySQLValue Source #
Binary protocol decoder
getBits :: Int -> Get Word64 Source #
convert a bit sequence to a Word64
Since Word64
has a Bits
instance, it's easier to deal with in haskell.
putTextBits :: Word64 -> Put Source #
putBinaryField :: MySQLValue -> Put Source #
Binary protocol encoder
putBinaryDay :: Day -> Put Source #
putBinaryTime' :: TimeOfDay -> Put Source #
putBinaryTime :: TimeOfDay -> Put Source #
getBinaryRow :: [ColumnDef] -> Int -> Get [MySQLValue] Source #
Binary row decoder
MySQL use a special null bitmap without offset = 2 here.
Use ByteString
to present a bitmap.
When used for represent bits values, the underlining ByteString
follows:
- byteString: head -> tail
- bit: high bit -> low bit
When used as a null-map/present-map, every bit inside a byte is mapped to a column, the mapping order is following:
- byteString: head -> tail
- column: left -> right
We don't use Int64
here because there maybe more than 64 columns.
isColumnSet :: BitMap -> Int -> Bool Source #
test if a column is set
The number counts from left to right.
makeNullMap :: [MySQLValue] -> BitMap Source #
make a nullmap for params without offset.