snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
This commit is contained in:
1199
internal/engine/mssql/convert.go
Normal file
1199
internal/engine/mssql/convert.go
Normal file
File diff suppressed because it is too large
Load Diff
84
internal/engine/mssql/dialect/dialect.json
Normal file
84
internal/engine/mssql/dialect/dialect.json
Normal file
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"dialect": "mssql",
|
||||
"default_schema": "dbo",
|
||||
"const": {
|
||||
"integer": "int",
|
||||
"float": "float",
|
||||
"string": "varchar",
|
||||
"bool": "bit"
|
||||
},
|
||||
"bool": "bit",
|
||||
"comparison": ["=", "<>", "!=", "<", "<=", ">", ">="],
|
||||
"comparison_categories": "NBSD",
|
||||
"arithmetic": ["+", "-", "*", "/", "%"],
|
||||
"arithmetic_categories": "N",
|
||||
"cast_categories": "NSD",
|
||||
"idents": ["max"],
|
||||
"rewrites": [
|
||||
{
|
||||
"from": "sysname",
|
||||
"to": "nvarchar(128)"
|
||||
},
|
||||
{
|
||||
"from": "float($1)",
|
||||
"to": "real",
|
||||
"where": "$1 <= 24"
|
||||
},
|
||||
{
|
||||
"from": "float($1)",
|
||||
"to": "float"
|
||||
},
|
||||
{
|
||||
"from": "char",
|
||||
"to": "char(1)"
|
||||
},
|
||||
{
|
||||
"from": "varchar",
|
||||
"to": "varchar(1)"
|
||||
},
|
||||
{
|
||||
"from": "nchar",
|
||||
"to": "nchar(1)"
|
||||
},
|
||||
{
|
||||
"from": "nvarchar",
|
||||
"to": "nvarchar(1)"
|
||||
},
|
||||
{
|
||||
"from": "binary",
|
||||
"to": "binary(1)"
|
||||
},
|
||||
{
|
||||
"from": "varbinary",
|
||||
"to": "varbinary(1)"
|
||||
},
|
||||
{
|
||||
"from": "decimal",
|
||||
"to": "decimal(18, 0)"
|
||||
},
|
||||
{
|
||||
"from": "decimal($1)",
|
||||
"to": "decimal($1, 0)"
|
||||
},
|
||||
{
|
||||
"from": "numeric",
|
||||
"to": "numeric(18, 0)"
|
||||
},
|
||||
{
|
||||
"from": "numeric($1)",
|
||||
"to": "numeric($1, 0)"
|
||||
},
|
||||
{
|
||||
"from": "datetime2",
|
||||
"to": "datetime2(7)"
|
||||
},
|
||||
{
|
||||
"from": "time",
|
||||
"to": "time(7)"
|
||||
},
|
||||
{
|
||||
"from": "datetimeoffset",
|
||||
"to": "datetimeoffset(7)"
|
||||
}
|
||||
]
|
||||
}
|
||||
76
internal/engine/mssql/dialect/functions.jsonl
Normal file
76
internal/engine/mssql/dialect/functions.jsonl
Normal file
@@ -0,0 +1,76 @@
|
||||
{"name": "count", "kind": "a", "returns": "int"}
|
||||
{"name": "count_big", "kind": "a", "returns": "bigint"}
|
||||
{"name": "sum", "kind": "a", "args": [{"type": "bigint"}], "returns": "bigint", "nullable": true}
|
||||
{"name": "sum", "kind": "a", "args": [{"type": "int"}], "returns": "int", "nullable": true}
|
||||
{"name": "sum", "kind": "a", "args": [{"type": "smallint"}], "returns": "int", "nullable": true}
|
||||
{"name": "sum", "kind": "a", "args": [{"type": "tinyint"}], "returns": "int", "nullable": true}
|
||||
{"name": "sum", "kind": "a", "args": [{"type": "decimal"}], "returns": "decimal", "nullable": true}
|
||||
{"name": "sum", "kind": "a", "args": [{"type": "money"}], "returns": "money", "nullable": true}
|
||||
{"name": "sum", "kind": "a", "args": [{"type": "float"}], "returns": "float", "nullable": true}
|
||||
{"name": "sum", "kind": "a", "args": [{"type": "real"}], "returns": "float", "nullable": true}
|
||||
{"name": "avg", "kind": "a", "args": [{"type": "bigint"}], "returns": "bigint", "nullable": true}
|
||||
{"name": "avg", "kind": "a", "args": [{"type": "int"}], "returns": "int", "nullable": true}
|
||||
{"name": "avg", "kind": "a", "args": [{"type": "smallint"}], "returns": "int", "nullable": true}
|
||||
{"name": "avg", "kind": "a", "args": [{"type": "tinyint"}], "returns": "int", "nullable": true}
|
||||
{"name": "avg", "kind": "a", "args": [{"type": "decimal"}], "returns": "decimal", "nullable": true}
|
||||
{"name": "avg", "kind": "a", "args": [{"type": "money"}], "returns": "money", "nullable": true}
|
||||
{"name": "avg", "kind": "a", "args": [{"type": "float"}], "returns": "float", "nullable": true}
|
||||
{"name": "avg", "kind": "a", "args": [{"type": "real"}], "returns": "float", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "bigint"}], "returns": "bigint", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "int"}], "returns": "int", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "smallint"}], "returns": "smallint", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "tinyint"}], "returns": "tinyint", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "decimal"}], "returns": "decimal", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "money"}], "returns": "money", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "float"}], "returns": "float", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "real"}], "returns": "real", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "date"}], "returns": "date", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "datetime"}], "returns": "datetime", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "datetime2"}], "returns": "datetime2", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "datetimeoffset"}], "returns": "datetimeoffset", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "time"}], "returns": "time", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "varchar"}], "returns": "varchar", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "nvarchar"}], "returns": "nvarchar", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "char"}], "returns": "char", "nullable": true}
|
||||
{"name": "min", "kind": "a", "args": [{"type": "nchar"}], "returns": "nchar", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "bigint"}], "returns": "bigint", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "int"}], "returns": "int", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "smallint"}], "returns": "smallint", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "tinyint"}], "returns": "tinyint", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "decimal"}], "returns": "decimal", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "money"}], "returns": "money", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "float"}], "returns": "float", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "real"}], "returns": "real", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "date"}], "returns": "date", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "datetime"}], "returns": "datetime", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "datetime2"}], "returns": "datetime2", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "datetimeoffset"}], "returns": "datetimeoffset", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "time"}], "returns": "time", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "varchar"}], "returns": "varchar", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "nvarchar"}], "returns": "nvarchar", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "char"}], "returns": "char", "nullable": true}
|
||||
{"name": "max", "kind": "a", "args": [{"type": "nchar"}], "returns": "nchar", "nullable": true}
|
||||
{"name": "getdate", "returns": "datetime"}
|
||||
{"name": "getutcdate", "returns": "datetime"}
|
||||
{"name": "sysdatetime", "returns": "datetime2"}
|
||||
{"name": "sysutcdatetime", "returns": "datetime2"}
|
||||
{"name": "sysdatetimeoffset", "returns": "datetimeoffset"}
|
||||
{"name": "current_timestamp", "returns": "datetime"}
|
||||
{"name": "newid", "returns": "uniqueidentifier"}
|
||||
{"name": "newsequentialid", "returns": "uniqueidentifier"}
|
||||
{"name": "scope_identity", "returns": "decimal"}
|
||||
{"name": "len", "args": [{"type": "varchar"}], "returns": "int"}
|
||||
{"name": "len", "args": [{"type": "nvarchar"}], "returns": "int"}
|
||||
{"name": "datalength", "args": [{"type": "varchar"}], "returns": "int"}
|
||||
{"name": "datalength", "args": [{"type": "nvarchar"}], "returns": "int"}
|
||||
{"name": "datalength", "args": [{"type": "varbinary"}], "returns": "int"}
|
||||
{"name": "lower", "args": [{"type": "varchar"}], "returns": "varchar"}
|
||||
{"name": "lower", "args": [{"type": "nvarchar"}], "returns": "nvarchar"}
|
||||
{"name": "upper", "args": [{"type": "varchar"}], "returns": "varchar"}
|
||||
{"name": "upper", "args": [{"type": "nvarchar"}], "returns": "nvarchar"}
|
||||
{"name": "ltrim", "args": [{"type": "varchar"}], "returns": "varchar"}
|
||||
{"name": "ltrim", "args": [{"type": "nvarchar"}], "returns": "nvarchar"}
|
||||
{"name": "rtrim", "args": [{"type": "varchar"}], "returns": "varchar"}
|
||||
{"name": "rtrim", "args": [{"type": "nvarchar"}], "returns": "nvarchar"}
|
||||
{"name": "trim", "args": [{"type": "varchar"}], "returns": "varchar"}
|
||||
{"name": "trim", "args": [{"type": "nvarchar"}], "returns": "nvarchar"}
|
||||
34
internal/engine/mssql/dialect/types.jsonl
Normal file
34
internal/engine/mssql/dialect/types.jsonl
Normal file
@@ -0,0 +1,34 @@
|
||||
{"name": "bigint", "category": "N"}
|
||||
{"name": "int", "category": "N", "aliases": ["integer"]}
|
||||
{"name": "smallint", "category": "N"}
|
||||
{"name": "tinyint", "category": "N"}
|
||||
{"name": "bit", "category": "B"}
|
||||
{"name": "decimal", "category": "N", "aliases": ["dec", "numeric"]}
|
||||
{"name": "money", "category": "N"}
|
||||
{"name": "smallmoney", "category": "N"}
|
||||
{"name": "float", "category": "N", "aliases": ["double precision"]}
|
||||
{"name": "real", "category": "N"}
|
||||
{"name": "date", "category": "D"}
|
||||
{"name": "datetime", "category": "D"}
|
||||
{"name": "datetime2", "category": "D"}
|
||||
{"name": "smalldatetime", "category": "D"}
|
||||
{"name": "datetimeoffset", "category": "D"}
|
||||
{"name": "time", "category": "D"}
|
||||
{"name": "char", "category": "S", "aliases": ["character"]}
|
||||
{"name": "varchar", "category": "S"}
|
||||
{"name": "text", "category": "S"}
|
||||
{"name": "nchar", "category": "S"}
|
||||
{"name": "nvarchar", "category": "S"}
|
||||
{"name": "ntext", "category": "S"}
|
||||
{"name": "binary", "category": "S"}
|
||||
{"name": "varbinary", "category": "S"}
|
||||
{"name": "image", "category": "S"}
|
||||
{"name": "uniqueidentifier", "category": "S"}
|
||||
{"name": "xml", "category": "U"}
|
||||
{"name": "json", "category": "U"}
|
||||
{"name": "sql_variant", "category": "U"}
|
||||
{"name": "rowversion", "category": "U", "aliases": ["timestamp"]}
|
||||
{"name": "hierarchyid", "category": "U"}
|
||||
{"name": "geography", "category": "U"}
|
||||
{"name": "geometry", "category": "U"}
|
||||
{"name": "vector", "category": "U"}
|
||||
187
internal/engine/mssql/parse.go
Normal file
187
internal/engine/mssql/parse.go
Normal file
@@ -0,0 +1,187 @@
|
||||
package mssql
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/sqlc-dev/teesql/parser"
|
||||
|
||||
"github.com/sqlc-dev/sqlc/internal/source"
|
||||
"github.com/sqlc-dev/sqlc/internal/sql/ast"
|
||||
)
|
||||
|
||||
func NewParser() *Parser {
|
||||
return &Parser{}
|
||||
}
|
||||
|
||||
type Parser struct{}
|
||||
|
||||
func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) {
|
||||
blob, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
script, err := parser.Parse(ctx, bytes.NewReader(blob))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
toByte := byteOffsets(blob)
|
||||
|
||||
var stmts []ast.Statement
|
||||
loc := 0
|
||||
for _, batch := range script.Batches {
|
||||
for _, stmt := range batch.Statements {
|
||||
start := loc
|
||||
if frag, ok := stmt.(fragmented); ok && frag.Frag().HasSpan() {
|
||||
if s := toByte(frag.Frag().StartOffset); s > start {
|
||||
start = s
|
||||
}
|
||||
}
|
||||
end := statementEnd(blob, start)
|
||||
|
||||
converter := &cc{toByte: toByte}
|
||||
out := converter.convert(stmt)
|
||||
if _, ok := out.(*ast.TODO); ok {
|
||||
loc = end
|
||||
continue
|
||||
}
|
||||
|
||||
stmts = append(stmts, ast.Statement{
|
||||
Raw: &ast.RawStmt{
|
||||
Stmt: out,
|
||||
StmtLocation: loc,
|
||||
StmtLen: end - loc,
|
||||
},
|
||||
})
|
||||
loc = end
|
||||
}
|
||||
}
|
||||
|
||||
return stmts, nil
|
||||
}
|
||||
|
||||
// byteOffsets returns a function mapping a UTF-16 code-unit offset — how
|
||||
// teesql records source spans, mirroring ScriptDom — to a byte offset in
|
||||
// blob. For ASCII input the two are identical and the identity is returned.
|
||||
func byteOffsets(blob []byte) func(int) int {
|
||||
ascii := true
|
||||
for _, b := range blob {
|
||||
if b >= utf8.RuneSelf {
|
||||
ascii = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if ascii {
|
||||
return func(off int) int { return off }
|
||||
}
|
||||
// Walk the blob once, recording the byte index at which each UTF-16
|
||||
// offset begins.
|
||||
byteAt := make([]int, 0, len(blob)+1)
|
||||
for i := 0; i < len(blob); {
|
||||
r, size := utf8.DecodeRune(blob[i:])
|
||||
units := 1
|
||||
if r > 0xFFFF {
|
||||
units = 2
|
||||
}
|
||||
for u := 0; u < units; u++ {
|
||||
byteAt = append(byteAt, i)
|
||||
}
|
||||
i += size
|
||||
}
|
||||
byteAt = append(byteAt, len(blob))
|
||||
return func(off int) int {
|
||||
if off < 0 {
|
||||
return 0
|
||||
}
|
||||
if off >= len(byteAt) {
|
||||
return len(blob)
|
||||
}
|
||||
return byteAt[off]
|
||||
}
|
||||
}
|
||||
|
||||
// statementEnd scans from start for the semicolon ending the statement,
|
||||
// skipping string literals, quoted and bracketed identifiers, and comments.
|
||||
func statementEnd(blob []byte, start int) int {
|
||||
for i := start; i < len(blob); i++ {
|
||||
switch blob[i] {
|
||||
case '\'', '"':
|
||||
i = skipQuoted(blob, i)
|
||||
case '[':
|
||||
i = skipBracketed(blob, i)
|
||||
case '-':
|
||||
if i+1 < len(blob) && blob[i+1] == '-' {
|
||||
i = skipLineComment(blob, i)
|
||||
}
|
||||
case '/':
|
||||
if i+1 < len(blob) && blob[i+1] == '*' {
|
||||
i = skipBlockComment(blob, i)
|
||||
}
|
||||
case ';':
|
||||
return i + 1
|
||||
}
|
||||
}
|
||||
return len(blob)
|
||||
}
|
||||
|
||||
// skipQuoted skips a string literal or quoted identifier; T-SQL escapes the
|
||||
// quote character by doubling it.
|
||||
func skipQuoted(blob []byte, i int) int {
|
||||
q := blob[i]
|
||||
for j := i + 1; j < len(blob); j++ {
|
||||
if blob[j] == q {
|
||||
if j+1 < len(blob) && blob[j+1] == q {
|
||||
j++
|
||||
continue
|
||||
}
|
||||
return j
|
||||
}
|
||||
}
|
||||
return len(blob) - 1
|
||||
}
|
||||
|
||||
// skipBracketed skips a [bracketed identifier]; a closing bracket is escaped
|
||||
// by doubling it.
|
||||
func skipBracketed(blob []byte, i int) int {
|
||||
for j := i + 1; j < len(blob); j++ {
|
||||
if blob[j] == ']' {
|
||||
if j+1 < len(blob) && blob[j+1] == ']' {
|
||||
j++
|
||||
continue
|
||||
}
|
||||
return j
|
||||
}
|
||||
}
|
||||
return len(blob) - 1
|
||||
}
|
||||
|
||||
func skipLineComment(blob []byte, i int) int {
|
||||
for j := i; j < len(blob); j++ {
|
||||
if blob[j] == '\n' {
|
||||
return j
|
||||
}
|
||||
}
|
||||
return len(blob) - 1
|
||||
}
|
||||
|
||||
func skipBlockComment(blob []byte, i int) int {
|
||||
for j := i + 2; j < len(blob); j++ {
|
||||
if blob[j] == '*' && j+1 < len(blob) && blob[j+1] == '/' {
|
||||
return j + 1
|
||||
}
|
||||
}
|
||||
return len(blob) - 1
|
||||
}
|
||||
|
||||
// https://learn.microsoft.com/en-us/sql/t-sql/language-elements/comment-transact-sql
|
||||
func (p *Parser) CommentSyntax() source.CommentSyntax {
|
||||
return source.CommentSyntax{
|
||||
Dash: true, // -- comment
|
||||
SlashStar: true, // /* comment */
|
||||
}
|
||||
}
|
||||
196
internal/engine/mssql/reserved.go
Normal file
196
internal/engine/mssql/reserved.go
Normal file
@@ -0,0 +1,196 @@
|
||||
package mssql
|
||||
|
||||
import "strings"
|
||||
|
||||
// https://learn.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql
|
||||
func (p *Parser) IsReservedKeyword(s string) bool {
|
||||
switch strings.ToLower(s) {
|
||||
case "add":
|
||||
case "all":
|
||||
case "alter":
|
||||
case "and":
|
||||
case "any":
|
||||
case "as":
|
||||
case "asc":
|
||||
case "authorization":
|
||||
case "backup":
|
||||
case "begin":
|
||||
case "between":
|
||||
case "break":
|
||||
case "browse":
|
||||
case "bulk":
|
||||
case "by":
|
||||
case "cascade":
|
||||
case "case":
|
||||
case "check":
|
||||
case "checkpoint":
|
||||
case "close":
|
||||
case "clustered":
|
||||
case "coalesce":
|
||||
case "collate":
|
||||
case "column":
|
||||
case "commit":
|
||||
case "compute":
|
||||
case "constraint":
|
||||
case "contains":
|
||||
case "containstable":
|
||||
case "continue":
|
||||
case "convert":
|
||||
case "create":
|
||||
case "cross":
|
||||
case "current":
|
||||
case "current_date":
|
||||
case "current_time":
|
||||
case "current_timestamp":
|
||||
case "current_user":
|
||||
case "cursor":
|
||||
case "database":
|
||||
case "dbcc":
|
||||
case "deallocate":
|
||||
case "declare":
|
||||
case "default":
|
||||
case "delete":
|
||||
case "deny":
|
||||
case "desc":
|
||||
case "disk":
|
||||
case "distinct":
|
||||
case "distributed":
|
||||
case "double":
|
||||
case "drop":
|
||||
case "dump":
|
||||
case "else":
|
||||
case "end":
|
||||
case "errlvl":
|
||||
case "escape":
|
||||
case "except":
|
||||
case "exec":
|
||||
case "execute":
|
||||
case "exists":
|
||||
case "exit":
|
||||
case "external":
|
||||
case "fetch":
|
||||
case "file":
|
||||
case "fillfactor":
|
||||
case "for":
|
||||
case "foreign":
|
||||
case "freetext":
|
||||
case "freetexttable":
|
||||
case "from":
|
||||
case "full":
|
||||
case "function":
|
||||
case "goto":
|
||||
case "grant":
|
||||
case "group":
|
||||
case "having":
|
||||
case "holdlock":
|
||||
case "identity":
|
||||
case "identity_insert":
|
||||
case "identitycol":
|
||||
case "if":
|
||||
case "in":
|
||||
case "index":
|
||||
case "inner":
|
||||
case "insert":
|
||||
case "intersect":
|
||||
case "into":
|
||||
case "is":
|
||||
case "join":
|
||||
case "key":
|
||||
case "kill":
|
||||
case "left":
|
||||
case "like":
|
||||
case "lineno":
|
||||
case "load":
|
||||
case "merge":
|
||||
case "national":
|
||||
case "nocheck":
|
||||
case "nonclustered":
|
||||
case "not":
|
||||
case "null":
|
||||
case "nullif":
|
||||
case "of":
|
||||
case "off":
|
||||
case "offsets":
|
||||
case "on":
|
||||
case "open":
|
||||
case "opendatasource":
|
||||
case "openquery":
|
||||
case "openrowset":
|
||||
case "openxml":
|
||||
case "option":
|
||||
case "or":
|
||||
case "order":
|
||||
case "outer":
|
||||
case "over":
|
||||
case "percent":
|
||||
case "pivot":
|
||||
case "plan":
|
||||
case "precision":
|
||||
case "primary":
|
||||
case "print":
|
||||
case "proc":
|
||||
case "procedure":
|
||||
case "public":
|
||||
case "raiserror":
|
||||
case "read":
|
||||
case "readtext":
|
||||
case "reconfigure":
|
||||
case "references":
|
||||
case "replication":
|
||||
case "restore":
|
||||
case "restrict":
|
||||
case "return":
|
||||
case "revert":
|
||||
case "revoke":
|
||||
case "right":
|
||||
case "rollback":
|
||||
case "rowcount":
|
||||
case "rowguidcol":
|
||||
case "rule":
|
||||
case "save":
|
||||
case "schema":
|
||||
case "securityaudit":
|
||||
case "select":
|
||||
case "semantickeyphrasetable":
|
||||
case "semanticsimilaritydetailstable":
|
||||
case "semanticsimilaritytable":
|
||||
case "session_user":
|
||||
case "set":
|
||||
case "setuser":
|
||||
case "shutdown":
|
||||
case "some":
|
||||
case "statistics":
|
||||
case "system_user":
|
||||
case "table":
|
||||
case "tablesample":
|
||||
case "textsize":
|
||||
case "then":
|
||||
case "to":
|
||||
case "top":
|
||||
case "tran":
|
||||
case "transaction":
|
||||
case "trigger":
|
||||
case "truncate":
|
||||
case "try_convert":
|
||||
case "tsequal":
|
||||
case "union":
|
||||
case "unique":
|
||||
case "unpivot":
|
||||
case "update":
|
||||
case "updatetext":
|
||||
case "use":
|
||||
case "user":
|
||||
case "values":
|
||||
case "varying":
|
||||
case "view":
|
||||
case "waitfor":
|
||||
case "when":
|
||||
case "where":
|
||||
case "while":
|
||||
case "with":
|
||||
case "writetext":
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
16
internal/engine/mssql/seed.go
Normal file
16
internal/engine/mssql/seed.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package mssql
|
||||
|
||||
import (
|
||||
"embed"
|
||||
|
||||
"github.com/sqlc-dev/sqlc/internal/core"
|
||||
"github.com/sqlc-dev/sqlc/internal/core/seed"
|
||||
)
|
||||
|
||||
//go:embed dialect
|
||||
var dialectFS embed.FS
|
||||
|
||||
// Dialect returns the catalog option that seeds SQL Server's type system.
|
||||
func Dialect() core.Option {
|
||||
return seed.Dialect(dialectFS, "dialect")
|
||||
}
|
||||
65
internal/engine/mssql/utils.go
Normal file
65
internal/engine/mssql/utils.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package mssql
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
tsql "github.com/sqlc-dev/teesql/ast"
|
||||
|
||||
"github.com/sqlc-dev/sqlc/internal/debug"
|
||||
"github.com/sqlc-dev/sqlc/internal/sql/ast"
|
||||
)
|
||||
|
||||
// fragmented is satisfied by every teesql node via its embedded Fragment.
|
||||
type fragmented interface {
|
||||
Frag() *tsql.Fragment
|
||||
}
|
||||
|
||||
func todo(n tsql.Node) *ast.TODO {
|
||||
if debug.Active {
|
||||
log.Printf("mssql.convert: Unknown node type %T\n", n)
|
||||
}
|
||||
return &ast.TODO{}
|
||||
}
|
||||
|
||||
// identifier normalizes an identifier. T-SQL identifiers are
|
||||
// case-insensitive under the default collations.
|
||||
func identifier(id string) string {
|
||||
return strings.ToLower(id)
|
||||
}
|
||||
|
||||
func NewIdentifier(t string) *ast.String {
|
||||
return &ast.String{Str: identifier(t)}
|
||||
}
|
||||
|
||||
func identifierValue(id *tsql.Identifier) string {
|
||||
if id == nil {
|
||||
return ""
|
||||
}
|
||||
return identifier(id.Value)
|
||||
}
|
||||
|
||||
// schemaName returns the schema an object name qualifies it with. The "dbo"
|
||||
// default schema maps to the catalog's default namespace, so it is treated
|
||||
// as unqualified.
|
||||
func schemaName(n *tsql.SchemaObjectName) string {
|
||||
if n == nil || n.SchemaIdentifier == nil {
|
||||
return ""
|
||||
}
|
||||
s := identifier(n.SchemaIdentifier.Value)
|
||||
if s == "dbo" {
|
||||
return ""
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func parseTableName(n *tsql.SchemaObjectName) *ast.TableName {
|
||||
if n == nil {
|
||||
return &ast.TableName{}
|
||||
}
|
||||
return &ast.TableName{
|
||||
Schema: schemaName(n),
|
||||
Name: identifierValue(n.BaseIdentifier),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user