Skip to content

Commit 8fedb49

Browse files
akoclaude
andcommitted
fix: SQL SHOW TABLES/VIEWS and DESCRIBE fail for all drivers
The grammar rule used bare IDENTIFIER for the target in SQL <alias> SHOW TABLES and SQL <alias> DESCRIBE <table>, but TABLES, VIEWS etc. are dedicated lexer tokens that don't match IDENTIFIER. The command fell through to the sqlQuery passthrough rule, sending raw "SHOW TABLES" to the database which fails on Oracle (ORA-00900) and SQL Server. Changed to identifierOrKeyword which matches both identifiers and keyword tokens. Updated visitor to use IdentifierOrKeyword() accordingly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b59c4fa commit 8fedb49

File tree

4 files changed

+51
-35
lines changed

4 files changed

+51
-35
lines changed

mdl/grammar/MDLParser.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,8 +2918,8 @@ sqlStatement
29182918
: SQL CONNECT IDENTIFIER STRING_LITERAL AS IDENTIFIER # sqlConnect
29192919
| SQL DISCONNECT IDENTIFIER # sqlDisconnect
29202920
| SQL CONNECTIONS # sqlConnections
2921-
| SQL IDENTIFIER SHOW IDENTIFIER # sqlShowTables
2922-
| SQL IDENTIFIER DESCRIBE IDENTIFIER # sqlDescribeTable
2921+
| SQL IDENTIFIER SHOW identifierOrKeyword # sqlShowTables
2922+
| SQL IDENTIFIER DESCRIBE identifierOrKeyword # sqlDescribeTable
29232923
| SQL IDENTIFIER GENERATE CONNECTOR INTO identifierOrKeyword
29242924
(TABLES LPAREN identifierOrKeyword (COMMA identifierOrKeyword)* RPAREN)?
29252925
(VIEWS LPAREN identifierOrKeyword (COMMA identifierOrKeyword)* RPAREN)?

mdl/grammar/parser/MDLParser.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

mdl/grammar/parser/mdl_parser.go

Lines changed: 40 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mdl/visitor/visitor_sql.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ func (b *Builder) ExitSqlConnections(ctx *parser.SqlConnectionsContext) {
4646

4747
// ExitSqlShowTables handles SQL <alias> SHOW TABLES|VIEWS|FUNCTIONS
4848
func (b *Builder) ExitSqlShowTables(ctx *parser.SqlShowTablesContext) {
49-
ids := ctx.AllIDENTIFIER()
50-
if len(ids) < 2 {
49+
alias := ctx.IDENTIFIER().GetText()
50+
iok := ctx.IdentifierOrKeyword()
51+
if iok == nil {
5152
return
5253
}
53-
alias := ids[0].GetText()
54-
target := strings.ToUpper(ids[1].GetText())
54+
target := strings.ToUpper(iok.GetText())
5555

5656
switch target {
5757
case "VIEWS":
@@ -66,12 +66,12 @@ func (b *Builder) ExitSqlShowTables(ctx *parser.SqlShowTablesContext) {
6666

6767
// ExitSqlDescribeTable handles SQL <alias> DESCRIBE <table>
6868
func (b *Builder) ExitSqlDescribeTable(ctx *parser.SqlDescribeTableContext) {
69-
ids := ctx.AllIDENTIFIER()
70-
if len(ids) < 2 {
69+
alias := ctx.IDENTIFIER().GetText()
70+
iok := ctx.IdentifierOrKeyword()
71+
if iok == nil {
7172
return
7273
}
73-
alias := ids[0].GetText()
74-
table := ids[1].GetText()
74+
table := iok.GetText()
7575
b.statements = append(b.statements, &ast.SQLDescribeTableStmt{
7676
Alias: alias,
7777
Table: table,

0 commit comments

Comments
 (0)