InfluxElixir.Client.Local.SQLMask (InfluxElixir v0.1.40)

Copy Markdown View Source

Reads quoted text out of the way. Every clause of a SQL text is located by a regular expression, and a string literal can hold anything: a comma, >, limit 5, from t. So the text is masked first — the body of each '...' or "..." becomes filler, byte for byte, the quotes stay — the expression runs over the mask, and what it found is cut out of the original at the same offsets.

The options say how a quoted token is read:

  • :blank — the filler byte (default ?x)
  • :doubled — a doubled quote ('O''Brien') is one quote inside the literal, as in SQL (default true); false reads 'a''b' as two literals, as InfluxQL does
  • :backslash — a backslash makes the next byte part of the literal, as in InfluxQL (default false)
  • :regex — a /.../ that follows =~ or !~ is masked too, as an InfluxQL regular expression (default false)
  • :lenient — an unterminated literal is masked to the end of the text instead of raising (default false; InfluxElixir.Client.Local.SQLLexer refuses such a text first, so SQL never reaches one)

Summary

Types

How mask/2 reads quoted text.

Functions

Splits str at the parenthesis that closes the one already opened; parentheses inside a quoted literal do not count.

The text a {start, length} capture covers, or "" for a group that did not match.

The text with the inside of every quoted string and quoted identifier blanked, byte for byte.

Regex.run/2 over the masked text, with the captures cut from text (an unmatched optional group is ""); nil when the pattern does not match.

Splits at the commas outside parentheses and string literals.

Types

option()

@type option() ::
  {:blank, byte()}
  | {:doubled, boolean()}
  | {:backslash, boolean()}
  | {:regex, boolean()}
  | {:lenient, boolean()}

How mask/2 reads quoted text.

Functions

balanced(str)

@spec balanced(binary()) :: {:ok, binary(), binary()} | :error

Splits str at the parenthesis that closes the one already opened; parentheses inside a quoted literal do not count.

cut(text, arg)

@spec cut(
  binary(),
  {integer(), non_neg_integer()}
) :: binary()

The text a {start, length} capture covers, or "" for a group that did not match.

mask(text, opts \\ [])

@spec mask(binary(), [option()]) :: binary()

The text with the inside of every quoted string and quoted identifier blanked, byte for byte.

run(pattern, text)

@spec run(Regex.t(), binary()) :: [binary()] | nil

Regex.run/2 over the masked text, with the captures cut from text (an unmatched optional group is ""); nil when the pattern does not match.

split_commas(str)

@spec split_commas(binary()) :: [binary()]

Splits at the commas outside parentheses and string literals.