Cerbero.SQL.Classifier (cerbero v0.1.0)

Copy Markdown View Source

Keyword-heuristic classification of raw SQL in execute/1,2. This is deliberately NOT a SQL parser: anchored patterns over normalized text, with :unknown as the honest fallback (surfaced as unclassified_sql). DML is detected (target table), never analyzed.

Statement splitting, comment stripping, and quote tracking all happen in one pass (scan/4) so that --//* */ comments and ; statement separators are only ever recognized outside of '...' strings, "..." identifiers, and $tag$...$tag$ dollar-quoted blocks — and, conversely, so that quote/comment markers appearing inside a comment don't do anything either. The scanner also degrades gracefully (byte-for-byte, never raising) on invalid or truncated UTF-8; any statement that turns out not to be valid UTF-8 after splitting classifies as :unknown rather than being fed to String.downcase/1 or Regex.

Known limitation: escaped quotes ('' inside a string literal, "" inside a quoted identifier) are not understood — the scanner treats the first repeated quote as a close/open pair. This is rare in migration SQL and, worst case, degrades a statement to :unknown rather than misclassifying it as something actionable.

Summary

Functions

classify(sql)