Class SqlStringLiterals

java.lang.Object
dev.frostlake.executor.SqlStringLiterals

public final class SqlStringLiterals extends Object
The single, canonical decode for a single-quoted SQL string literal — the one place that turns a STRING_LITERAL token (or its already-stripped inner text) into the value it denotes.

Snowflake recognises two escape mechanisms inside a '…' literal: doubling a quote ('' → ') and backslash escapes (\' → ', \\ → \, \n/\t/\r → the control character). Any other backslash sequence keeps the backslash verbatim. Because \' is a real escape, the lexer rule for STRING_LITERAL treats backslash as always starting an escape, so this decoder must agree with it — otherwise a stored procedure/function body (decoded once at CREATE, re-parsed at CALL) or any other doubly-handled literal drifts out of alignment. Every string-literal decode site delegates here so the behaviour is identical whether the literal appears in an expression, a DDL option, a COPY clause, a column default, or a routine body.

  • Method Details

    • decode

      public static String decode(String tokenText)
      Decode a whole STRING_LITERAL token, i.e. the text including its surrounding single quotes.
    • encode

      public static String encode(String text)
      Render text as a single-quoted SQL string literal that decodes back to exactly text — the inverse of decode(java.lang.String). In this dialect a backslash always escapes (see the lexer), so every backslash must be doubled BEFORE quote-doubling; escaping quotes alone corrupted any substituted value that itself contained escape sequences (a VARIANT whose JSON held "{\"k\":1}" reached PARSE_JSON with bare inner quotes — "Invalid JSON").
    • decodeContent

      public static String decodeContent(String content)
      Decode the inner text of a string literal (surrounding quotes already stripped by the caller).