SQL Server exports DEFAULT constraints as nested parenthesized expressions like DEFAULT ((0)) or DEFAULT (newid()). The generic parser only needs the underlying expression, so collapse the redundant outer parentheses here.
(sql string)
| 56 | // like DEFAULT ((0)) or DEFAULT (newid()). The generic parser only needs the |
| 57 | // underlying expression, so collapse the redundant outer parentheses here. |
| 58 | func normalizeDefaultExpressions(sql string) string { |
| 59 | var b strings.Builder |
| 60 | |
| 61 | for i := 0; i < len(sql); { |
| 62 | switch { |
| 63 | case hasLineCommentPrefix(sql, i): |
| 64 | next := scanLineComment(sql, i) |
| 65 | b.WriteString(sql[i:next]) |
| 66 | i = next |
| 67 | case hasBlockCommentPrefix(sql, i): |
| 68 | next := scanBlockComment(sql, i) |
| 69 | b.WriteString(sql[i:next]) |
| 70 | i = next |
| 71 | case sql[i] == '\'': |
| 72 | next := scanSingleQuotedString(sql, i) |
| 73 | b.WriteString(sql[i:next]) |
| 74 | i = next |
| 75 | case sql[i] == '"': |
| 76 | next := scanDoubleQuotedString(sql, i) |
| 77 | b.WriteString(sql[i:next]) |
| 78 | i = next |
| 79 | case sql[i] == '[': |
| 80 | next := scanBracketIdentifier(sql, i) |
| 81 | b.WriteString(sql[i:next]) |
| 82 | i = next |
| 83 | case hasKeywordAt(sql, i, "DEFAULT"): |
| 84 | end := i + len("DEFAULT") |
| 85 | b.WriteString(sql[i:end]) |
| 86 | |
| 87 | j := end |
| 88 | for j < len(sql) && isSpace(sql[j]) { |
| 89 | b.WriteByte(sql[j]) |
| 90 | j++ |
| 91 | } |
| 92 | |
| 93 | if j < len(sql) && sql[j] == '(' { |
| 94 | expr, next, ok := scanBalancedParenthesizedSQL(sql, j) |
| 95 | if ok { |
| 96 | b.WriteString(stripOuterSQLParens(expr)) |
| 97 | i = next |
| 98 | continue |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | i = j |
| 103 | default: |
| 104 | b.WriteByte(sql[i]) |
| 105 | i++ |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return b.String() |
| 110 | } |
| 111 | |
| 112 | func normalizeQualifiedReservedIdentifiers(sql string) string { |
| 113 | var b strings.Builder |
no test coverage detected