hmssql
Safe HaskellNone
LanguageHaskell2010

Hmssql.Tds.TypeInfo

Description

Column/parameter type descriptors and the length-prefixed value encodings that go with them.

MS-TDS 2.2.5.4 Data Type Definitions

Synopsis

Documentation

data TypeInfo Source #

A type as the wire describes it (MS-TDS 2.2.5.4 TYPE_INFO): the token's type byte with its length, precision and scale, or collation, as the server sends it in COLMETADATA and a client sends it for a parameter. The wire has fewer types than T-SQL (int arrives as TIIntN 4 or TIInt4; json and vector as character types): Hmssql.SqlType names the declared type. RawParam takes one to send a value with a wire type of your choosing.

Constructors

TINull

0x1F

TIBit

0x32

TIInt1

0x30

TIInt2

0x34

TIInt4

0x38

TIInt8

0x7F

TIMoney4

0x7A

TIMoney8

0x3C

TIDateTime4

0x3A

TIDateTime8

0x3D

TIFlt4

0x3B

TIFlt8

0x3E

TIBitN

0x68

TIIntN !Word8

0x26, length 124/8

TIMoneyN !Word8

0x6E, length 4/8

TIDateTimeN !Word8

0x6F, length 4/8

TIFltN !Word8

0x6D, length 4/8

TIGuid

0x24

TIDecimalN !Precision !Scale

0x6A

TINumericN !Precision !Scale

0x6C

TIDateN

0x28

TITimeN !Scale

0x29

TIDateTime2N !Scale

0x2A

TIDateTimeOffsetN !Scale

0x2B

TIBigChar !Word16 !Collation

0xAF

TIBigVarChar !Word16 !Collation

0xA7, 0xFFFF = max

TIText !Word32 !Collation

0x23

TINChar !Word16 !Collation

0xEF

TINVarChar !Word16 !Collation

0xE7, 0xFFFF = max

TINText !Word32 !Collation

0x63

TIBigBinary !Word16

0xAD

TIBigVarBinary !Word16

0xA5, 0xFFFF = max

TIImage !Word32

0x22

TIXml !(Maybe XmlSchema)

0xF1

TISqlVariant !Word32

0x62

TIUdt !UdtInfo

0xF0, a CLR user-defined type (hierarchyid, geometry, geography, ...). Parsed so a result containing one can be read past, but not decoded (Hmssql.Decoding rejects it except as raw bytes) nor sent (typeInfoProblem).

Instances

Instances details
Show TypeInfo Source # 
Instance details

Defined in Hmssql.Tds.TypeInfo

Eq TypeInfo Source # 
Instance details

Defined in Hmssql.Tds.TypeInfo

data XmlSchema Source #

The schema collection of a typed xml column or parameter.

Instances

Instances details
Show XmlSchema Source # 
Instance details

Defined in Hmssql.Tds.TypeInfo

Eq XmlSchema Source # 
Instance details

Defined in Hmssql.Tds.TypeInfo

data UdtInfo Source #

MS-TDS 2.2.5.5.2 UDT_INFO, as the server sends it in COLMETADATA and RETURNVALUE.

Constructors

UdtInfo 

Fields

Instances

Instances details
Show UdtInfo Source # 
Instance details

Defined in Hmssql.Tds.TypeInfo

Eq UdtInfo Source # 
Instance details

Defined in Hmssql.Tds.TypeInfo

Methods

(==) :: UdtInfo -> UdtInfo -> Bool #

(/=) :: UdtInfo -> UdtInfo -> Bool #

maxLength :: Word16 Source #

Sentinel length for varchar(max), nvarchar(max), varbinary(max).

type RawBytes = Maybe ByteString Source #

An undecoded column or parameter value; Nothing is SQL NULL.

readDecimalInfo :: (Precision -> Scale -> a) -> Parser a Source #

Precision and scale of decimal / numeric, which must satisfy 1 <= precision <= 38 and scale <= precision (MS-TDS 2.2.5.5.1.3).

readTypeInfo :: Parser TypeInfo Source #

A column's or parameter's TYPE_INFO, as COLMETADATA and RETURNVALUE carry it.

putValue :: TdsContext -> TypeInfo -> RawBytes -> Put Source #

Write a value as it appears in RPC parameters. Fails (with error) if valueProblem finds invalid framing, including a non-NULL empty payload whose length would encode NULL. This does not validate the type declaration or the payload's semantic value.

putValueUnchecked :: TypeInfo -> RawBytes -> Put Source #

putValue without the check, for a value checked with valueProblem. Invalid lengths can wrap or encode NULL (writeValue).

data LengthKind Source #

How a type's values are delimited on the wire (lengthKind).

Constructors

Fixed !Int 
ByteLen

1-byte length, 0 = NULL

UShortCharBin

2-byte length, 0xFFFF = NULL

LongLen

4-byte length, 0xFFFFFFFF = NULL

VariantLen

4-byte length, 0 = NULL (sql_variant)

Plp

partially length-prefixed

NoValue 

lengthKind :: TypeInfo -> LengthKind Source #

How values of the type are delimited.

valueProblem :: TypeInfo -> RawBytes -> Maybe String Source #

Why a value can't be sent as a parameter of this type, if it can't: a lengthProblem, or an empty value of a type whose length prefix uses 0 for NULL (every BYTE-length type, and sql_variant), which the server would read as NULL.

typeInfoProblem :: TypeInfo -> Maybe String Source #

Why a parameter can't have this type, if it can't: a precision or scale SQL Server doesn't have (a decimal or numeric precision outside 1 through 38 or a scale above the precision, MS-TDS 2.2.5.5.1.3; a time, datetime2 or datetimeoffset scale above 7, 2.2.5.4.2), XML schema names too long for their length prefixes, or a CLR user-defined type, which hmssql doesn't send.

typeInfoSqlName :: TypeInfo -> Text Source #

The T-SQL type declaration for a parameter of this type, as used in the @params argument of sp_executesql.

isNullableType :: TypeInfo -> Bool Source #

Whether the wire encoding of this type can carry NULL.

The wire layouts, written to any sink

writeTypeInfo :: TypeInfo -> Builder Source #

TYPE_INFO (MS-TDS 2.2.5.6): the type byte, then what the type carries (a length, a precision and scale, a collation, names).

writeValue :: TypeInfo -> RawBytes -> Builder Source #

A value as RPC parameters carry it, after its TYPE_INFO: nothing for a type with no value, the bytes of a fixed-length type, else a length prefix (whose NULL spelling depends on the kind, LengthKind) and the bytes, or PLP chunks. Nothing is checked here: a value too long for its length prefix wraps, and an empty BYTE-length or sql_variant payload is written as NULL. putValue checks with valueProblem first; this is for values checked already.