| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hmssql.Query.Lexer
Description
Finding the positional parameter references (@p1, @p2, ...) in
T-SQL text, so that mkQuery can turn them into placeholders
that renumber when queries are concatenated.
This is not a T-SQL parser. It only knows enough of the lexical
structure to leave alone what is inside string literals ( and
...N, with ...'' for a quote), quoted identifiers ("..." with
"", and [...] with ]]) and comments (-- ... to the end of the
line, and /* ... */, which T-SQL nests). Everything unterminated
runs to the end of the text; the scanner never fails.
Synopsis
- data Fragment
- = Static !Text
- | Placeholder !Int
- lexPlaceholders :: Text -> [Fragment]
- isVariableChar :: Char -> Bool
Documentation
A piece of SQL text, or a reference to a positional parameter (1-based).
Constructors
| Static !Text | |
| Placeholder !Int |
Instances
lexPlaceholders :: Text -> [Fragment] Source #
Split T-SQL text into static text and positional placeholders.
A placeholder is @p (either case) followed by one or more ASCII digits,
standing alone as a name: the character before the @ is not @ or a
character of a variable name (so @@p1 and x@p1 are text), and the
character after the digits is not one either (so @p1x, @p1_old and
@p1é are other variables). @P01 is placeholder 1. More than nine
digits is text (no request has that many parameters).
Adjacent static text is merged; the result concatenates back to the input
with each placeholder rendered as @pN.
The scanner only finds the placeholders; the static text between two of
them is one slice of the input. (Building it from the pieces the
scanner passes over, appending as it went, was quadratic in the number
of special characters between placeholders: every - of a - b, every
'' in a string, every / or * in a comment.)
isVariableChar :: Char -> Bool Source #
A character of a T-SQL variable name after the leading @: a letter,
combining mark, decimal digit or letter number from the Basic
Multilingual Plane, or one of @, #, $ and _. (SQL Server
rejects surrogates in identifiers, so nothing above U+FFFF.)