mysql-haskell-0.5.1.0: pure haskell MySQL driver

Copyright(c) Winterland, 2016
LicenseBSD
Maintainerdrkoster@qq.com
Stabilityexperimental
PortabilityPORTABLE
Safe HaskellNone
LanguageHaskell2010

Database.MySQL.Protocol.MySQLValue

Description

Core text and binary row decoder/encoder machinery.

Synopsis

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.

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 

putParamMySQLType :: MySQLValue -> Put Source

Decide if usigned bit(0x80) and FieldType for MySQLValues.

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

getTextRowVector :: Vector ColumnDef -> Get (Vector MySQLValue) Source

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.

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

newtype BitMap Source

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 

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.