Class BindVariableSubstitutor

java.lang.Object
dev.frostlake.executor.BindVariableSubstitutor

public class BindVariableSubstitutor extends Object
Substitutes procedural scripting BIND variables (:var) into raw SQL text before it is parsed/executed. Holds a live reference to the procedural variable map.

A record field is not one of them. Inside a SQL statement rec.col is an ordinary column reference on the account: INSERT INTO t VALUES (r.a) is "invalid identifier 'R.A'", and over a table aliased r it reads that table's own column. Only a scripting EXPRESSION reads the field (x := r.a, RETURN r.a, an IF condition), and none of those comes through here.

The substitution is driven by the SQL lexer, not hand-rolled character scanning: the SQL is tokenized, and a bind variable is recognized as the token sequence ':' IDENTIFIER. Because the lexer classifies the text, a name that appears inside a FrostlakeLexer.STRING_LITERAL or a FrostlakeLexer.QUOTED_IDENTIFIER is never mistaken for a reference, and :: (cast) / := (assignment) — their own tokens — are never confused with a :var. The grammar's tokenizer stays the single source of truth about the SQL's lexical structure.

  • Constructor Details

    • BindVariableSubstitutor

      public BindVariableSubstitutor(Map<String,Object> variables)
    • BindVariableSubstitutor

      public BindVariableSubstitutor(Map<String,Object> variables, ProceduralExecutor declarations)
      A substitutor that also knows the names' DECLARED types, so a numeric variable is spelled with its type — (1)::NUMBER(9,0) for a FOR counter, (1.78)::NUMBER(5,2) for a declared NUMBER — and the statement it lands in types it as live does (a column derived from :i declares NUMBER(9,0), not the digits' own width).
  • Method Details

    • substitute

      public String substitute(String sql)
      Substitute colon bind variables into the SQL.