ForgeOpsTracker.SqlStatement (forge_ops_tracker v0.13.0)

Copy Markdown View Source

Finds the SQL behind a database error and reduces it to something safe to send: the names of the stored procedures, tables and views it touched, and (only if capture_sql_statement is on) the statement itself with every string and number replaced by ?. Ported from gems/forge_ops_tracker's SqlStatement, which is itself ported from the server's own SqlStatementMasker/SqlObjectExtractor: same rules everywhere, and the server applies them again on arrival, so a difference here can only ever mean less is masked client-side, never that something unmasked gets stored.

Deliberately a single pass over a few patterns, not a SQL parser.

Summary

Functions

The raw statement off the exception itself, or nil when it carries none.

Takes an already-masked statement (so a keyword inside a string value can't be mistaken for SQL). Returns nil when nothing recognizable was found.

Functions

find_in(reason)

@spec find_in(term()) :: String.t() | nil

The raw statement off the exception itself, or nil when it carries none.

mask(statement)

@spec mask(String.t() | nil) :: String.t() | nil

objects(masked)

@spec objects(String.t() | nil) :: map() | nil

Takes an already-masked statement (so a keyword inside a string value can't be mistaken for SQL). Returns nil when nothing recognizable was found.