ForgeOpsTracker.SqlStatement (forge_ops_tracker v0.14.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.

statement with every string and number replaced by ?, or nil when it's blank. Pass the query's db.system as system: when it's known: on "mysql" and "mariadb", "double quotes" are a string too, so they're masked there and left alone everywhere else.

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, opts \\ [])

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

statement with every string and number replaced by ?, or nil when it's blank. Pass the query's db.system as system: when it's known: on "mysql" and "mariadb", "double quotes" are a string too, so they're masked there and left alone everywhere else.

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.