MCPcopy Create free account
hub / github.com/bytebase/dbhub / scanSingleLineCommentMySQL

Function scanSingleLineCommentMySQL

src/utils/sql-parser.ts:31–43  ·  view source on GitHub ↗

* MySQL/MariaDB single-line comment scanner. Unlike ANSI SQL, MySQL and MariaDB * only begin a `--` comment when the two dashes are followed by whitespace, a * control character, or end of input. Otherwise the dashes are two minus * operators and the rest of the line is ordinary SQL (e.g. `SELECT

(sql: string, i: number)

Source from the content-addressed store, hash-verified

29 * while the engine still executes the DROP.
30 */
31function scanSingleLineCommentMySQL(sql: string, i: number): SQLToken | null {
32 if (sql[i] !== "-" || sql[i + 1] !== "-") { return null; }
33 const next = sql[i + 2];
34 // Comment trigger = whitespace, control char, or EOL. MySQL's lexer uses
35 // my_isspace() || my_iscntrl(), so besides bytes <= 0x20 this also includes
36 // ASCII DEL (0x7F). Anything else means the dashes are minus operators.
37 if (next !== undefined && next.charCodeAt(0) > 0x20 && next.charCodeAt(0) !== 0x7f) {
38 return null;
39 }
40 let j = i;
41 while (j < sql.length && sql[j] !== "\n") { j++; }
42 return { type: TokenType.Comment, end: j };
43}
44
45function scanMultiLineComment(sql: string, i: number): SQLToken | null {
46 if (sql[i] !== "/" || sql[i + 1] !== "*") { return null; }

Callers 1

scanTokenMySQLFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected