| Copyright | (c) Winterland 2016 |
|---|---|
| License | BSD |
| Maintainer | [email protected] |
| Stability | experimental |
| Portability | PORTABLE |
| Safe Haskell | None |
| Language | Haskell2010 |
Database.MySQL.Protocol.MySQLValue
Description
Core text and binary row decoder/encoder machinery.
Synopsis
- 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
- putTextField :: MySQLValue -> Put
- getTextRow :: [ColumnDef] -> Get [MySQLValue]
- getTextRowVector :: Vector ColumnDef -> Get (Vector MySQLValue)
- getBinaryField :: ColumnDef -> Get MySQLValue
- putBinaryField :: MySQLValue -> Put
- getBinaryRow :: [ColumnDef] -> Int -> Get [MySQLValue]
- getBinaryRowVector :: Vector ColumnDef -> Int -> Get (Vector MySQLValue)
- getBits :: Int -> Get Word64
- newtype BitMap = BitMap {}
- isColumnSet :: BitMap -> Int -> Bool
- isColumnNull :: BitMap -> Int -> Bool
- makeNullMap :: [MySQLValue] -> BitMap
MySQLValue decoder and encoder
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.
Constructors
| 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 |
Instances
putParamMySQLType :: MySQLValue -> Put Source #
Put FieldType and usigned bit(0x80/0x00) for MySQLValues.
getTextField :: ColumnDef -> Get MySQLValue Source #
Text protocol decoder
putTextField :: MySQLValue -> Put Source #
Text protocol encoder
getTextRow :: [ColumnDef] -> Get [MySQLValue] Source #
Text row decoder
getTextRowVector :: Vector ColumnDef -> Get (Vector MySQLValue) Source #
getBinaryField :: ColumnDef -> Get MySQLValue Source #
Binary protocol decoder
putBinaryField :: MySQLValue -> Put Source #
Binary protocol encoder
getBinaryRow :: [ColumnDef] -> Int -> Get [MySQLValue] Source #
Binary row decoder
MySQL use a special null bitmap without offset = 2 here.
getBinaryRowVector :: Vector ColumnDef -> Int -> Get (Vector MySQLValue) Source #
Internal utilities
getBits :: Int -> Get Word64 Source #
Get a bit sequence as a Word64
Since Word64 has a Bits instance, it's easier to deal with in haskell.
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.
Constructors
| BitMap | |
Fields | |
isColumnSet :: BitMap -> Int -> Bool Source #
Test if a column is set(binlog protocol).
The number counts from left to right.
isColumnNull :: BitMap -> Int -> Bool Source #
Test if a column is null(binary protocol).
The number counts from left to right.
makeNullMap :: [MySQLValue] -> BitMap Source #
Make a nullmap for params(binary protocol) without offset.