| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hmssql.SqlType
Description
SQL Server's data types by name, as T-SQL and the catalog spell them:
nvarchar(50), decimal(10,2), vector(3). This is the vocabulary
for code that handles SQL generically, such as checking that a database
has the columns an application expects, generating record types from
tables, or serializing whatever a table holds; Hmssql.Catalog reads
these types from a database.
SqlDataType is the closed list of the types a server ships with, so a
case over it can be total, and a type this library doesn't know yet
makes a lookup return Nothing rather than a catch-all constructor.
SqlType adds a type's arguments: a length, a precision and scale, a
scale, a vector's dimensions or an xml schema collection.
The wire has its own view of types, TypeInfo: the encodings values are
carried in, which name lengths in bytes and don't tell json (sent as
nvarchar(max)), vector (sent as varchar) or rowversion (sent as
binary(8)) from what they are sent as. typeInfoSqlType and
sqlTypeTypeInfo go between the two views. columnSqlType also uses
the column's user-type tag to recognize rowversion.
Synopsis
- data SqlDataType
- = TyBit
- | TyTinyInt
- | TySmallInt
- | TyInt
- | TyBigInt
- | TyDecimal
- | TyNumeric
- | TyMoney
- | TySmallMoney
- | TyFloat
- | TyReal
- | TyDate
- | TyTime
- | TyDateTime
- | TySmallDateTime
- | TyDateTime2
- | TyDateTimeOffset
- | TyChar
- | TyVarChar
- | TyText
- | TyNChar
- | TyNVarChar
- | TyNText
- | TyBinary
- | TyVarBinary
- | TyImage
- | TyUniqueIdentifier
- | TyRowVersion
- | TyXml
- | TySqlVariant
- | TyJson
- | TyVector
- | TyHierarchyId
- | TyGeometry
- | TyGeography
- dataTypeName :: SqlDataType -> Text
- dataTypeFromName :: Text -> Maybe SqlDataType
- data TypeCategory
- dataTypeCategory :: SqlDataType -> TypeCategory
- data SqlType = SqlType {}
- data TypeArgs
- = NoArgs
- | LengthArg !Length
- | PrecisionScaleArg !Precision !Scale
- | ScaleArg !Scale
- | DimensionsArg !Int
- | XmlSchemaArg !Text !Text
- data Length
- sqlTypeName :: SqlType -> Text
- sqlTypeProblem :: SqlType -> Maybe String
- typeInfoDataType :: TypeInfo -> Maybe SqlDataType
- typeInfoSqlType :: TypeInfo -> Maybe SqlType
- sqlTypeTypeInfo :: SqlType -> Maybe TypeInfo
- columnSqlType :: ColumnInfo -> Maybe SqlType
Data types
data SqlDataType Source #
Every data type SQL Server ships with, in the groups of its
documentation (dataTypeCategory). The three CLR system
types are here because the catalog lists them; hmssql neither decodes nor
sends their values. float(n) is stored as real or float, and sysname is
nvarchar(128): neither is a type of its own.
Constructors
| TyBit | |
| TyTinyInt | |
| TySmallInt | |
| TyInt | |
| TyBigInt | |
| TyDecimal | |
| TyNumeric | |
| TyMoney | |
| TySmallMoney | |
| TyFloat | |
| TyReal | |
| TyDate | |
| TyTime | |
| TyDateTime | |
| TySmallDateTime | |
| TyDateTime2 | |
| TyDateTimeOffset | |
| TyChar | |
| TyVarChar | |
| TyText | |
| TyNChar | |
| TyNVarChar | |
| TyNText | |
| TyBinary | |
| TyVarBinary | |
| TyImage | |
| TyUniqueIdentifier | |
| TyRowVersion |
|
| TyXml | |
| TySqlVariant | |
| TyJson | SQL Server 2025 |
| TyVector | SQL Server 2025 |
| TyHierarchyId | a CLR system type |
| TyGeometry | a CLR system type |
| TyGeography | a CLR system type |
Instances
dataTypeName :: SqlDataType -> Text Source #
The type's name in T-SQL and in sys.types, except that
TyRowVersion is rowversion (the catalog says timestamp, the older
name, which dataTypeFromName accepts).
dataTypeFromName :: Text -> Maybe SqlDataType Source #
The type of a name as sys.types or T-SQL spells it, ignoring case
and surrounding space: the inverse of dataTypeName, plus the aliases
timestamp (TyRowVersion) and sysname (TyNVarChar). Nothing
for a user-defined type, and for a type newer than this library.
data TypeCategory Source #
The groups of SQL Server's data type documentation.
Constructors
| ExactNumeric | |
| ApproximateNumeric | |
| DateAndTime | |
| CharacterString | single-byte: |
| UnicodeCharacterString |
|
| BinaryString |
|
| OtherDataType |
|
Instances
dataTypeCategory :: SqlDataType -> TypeCategory Source #
The group of SQL Server's documentation the type is listed under.
Types with their arguments
A data type with its arguments: what a column is declared as.
Constructors
| SqlType | |
Fields
| |
A type's arguments. Which a type takes is fixed (sqlTypeProblem):
a length for the character and binary types, a precision and scale for
decimal and numeric, a scale for time, datetime2 and
datetimeoffset, dimensions for vector, nothing or a schema
collection for xml, and nothing for the rest.
Constructors
| NoArgs | |
| LengthArg !Length | |
| PrecisionScaleArg !Precision !Scale | |
| ScaleArg !Scale | |
| DimensionsArg !Int | |
| XmlSchemaArg !Text !Text | the schema and the name of the collection: |
The declared length of a character or binary type: in characters
(nvarchar(50) is Length 50, whatever its storage takes), or in bytes
for the binary types.
sqlTypeName :: SqlType -> Text Source #
The type as T-SQL declares it: nvarchar(50), varbinary(max),
decimal(10,2), time(4), vector(3), xml([dbo].[Person]), int.
Rendered as it is; check sqlTypeProblem first for a type built by
hand.
sqlTypeProblem :: SqlType -> Maybe String Source #
Why this isn't a type SQL Server has, if it isn't: an argument the type
doesn't take, a missing one (the length of an nvarchar, the precision
and scale of a decimal, ...; nothing is defaulted), or one out of
range: a length outside 1 through 8000 (4000 for nchar and
nvarchar), max on a fixed-length type, a precision outside 1
through 38 or a scale above it, a scale above 7, dimensions below 1.
The wire's types
typeInfoDataType :: TypeInfo -> Maybe SqlDataType Source #
The data type a column or parameter of this wire type was declared
as, as far as the wire says: a json column arrives as nvarchar(max),
a vector as varchar and a rowversion as binary(8), and that is
what they come back as. Nothing for TINull, for a CLR user-defined
type other than the three system ones, and for a width the wire doesn't
have (a TIIntN 3).
One case match, and the results are constants, so it costs nothing to
call per value: Hmssql.Decoding classifies columns with it, on every
row for a RowDecoderMonadic.
typeInfoSqlType :: TypeInfo -> Maybe SqlType Source #
The type with its arguments: typeInfoDataType plus the length,
precision and scale or schema collection the wire carries. This
allocates the result, so prefer typeInfoDataType where the arguments
don't matter.
sqlTypeTypeInfo :: SqlType -> Maybe TypeInfo Source #
The wire type to declare a parameter of this type with, as
RawParam's: the nullable encodings, the server's default collation
for character types, a schema collection in the current database.
Nothing for a type with a sqlTypeProblem, and for json, vector
and the CLR types, which a TDS 7.4 or 8.0 client can't send as such
(send json as nvarchar(max), a vector as its JSON array text).
columnSqlType :: ColumnInfo -> Maybe SqlType Source #
The declared type of a result set's column, as far as its metadata
says. The user-type tag identifies rowversion; otherwise this is
typeInfoSqlType of the column's storage type. An alias type's user
ID does not carry its name, so its underlying type is returned.