@@ -13,7 +13,6 @@ import (
13
13
"github.com/cockroachdb/cockroach/pkg/sql/parser/statements"
14
14
"github.com/cockroachdb/cockroach/pkg/sql/scanner"
15
15
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
16
- "github.com/cockroachdb/cockroach/pkg/sql/types"
17
16
"github.com/cockroachdb/errors"
18
17
)
19
18
@@ -38,17 +37,6 @@ type Parser struct {
38
37
tokBuf [8 ]plpgsqlSymType
39
38
}
40
39
41
- // INT8 is the historical interpretation of INT. This should be left
42
- // alone in the future, since there are many sql fragments stored
43
- // in various descriptors. Any user input that was created after
44
- // INT := INT4 will simply use INT4 in any resulting code.
45
- var defaultNakedIntType = types .Int
46
-
47
- // Parse parses the sql and returns a list of statements.
48
- func (p * Parser ) Parse (sql string ) (statements.PLpgStatement , error ) {
49
- return p .parseWithDepth (1 , sql , defaultNakedIntType )
50
- }
51
-
52
40
func (p * Parser ) scanFnBlock () (sql string , tokens []plpgsqlSymType , done bool ) {
53
41
var lval plpgsqlSymType
54
42
tokens = p .tokBuf [:0 ]
@@ -79,27 +67,9 @@ func (p *Parser) scanFnBlock() (sql string, tokens []plpgsqlSymType, done bool)
79
67
}
80
68
}
81
69
82
- func (p * Parser ) parseWithDepth (
83
- depth int , plpgsql string , nakedIntType * types.T ,
84
- ) (statements.PLpgStatement , error ) {
85
- p .scanner .Init (plpgsql )
86
- defer p .scanner .Cleanup ()
87
- sql , tokens , done := p .scanFnBlock ()
88
- stmt , err := p .parse (depth + 1 , sql , tokens , nakedIntType )
89
- if err != nil {
90
- return statements.PLpgStatement {}, err
91
- }
92
- if ! done {
93
- return statements.PLpgStatement {}, errors .AssertionFailedf ("invalid plpgsql function: %s" , plpgsql )
94
- }
95
- return stmt , nil
96
- }
97
-
98
70
// parse parses a statement from the given scanned tokens.
99
- func (p * Parser ) parse (
100
- depth int , sql string , tokens []plpgsqlSymType , nakedIntType * types.T ,
101
- ) (statements.PLpgStatement , error ) {
102
- p .lexer .init (sql , tokens , nakedIntType , & p .parserImpl )
71
+ func (p * Parser ) parse (sql string , tokens []plpgsqlSymType ) (statements.PLpgStatement , error ) {
72
+ p .lexer .init (sql , tokens , & p .parserImpl )
103
73
defer p .lexer .cleanup ()
104
74
if p .parserImpl .Parse (& p .lexer ) != 0 {
105
75
if p .lexer .lastError == nil {
@@ -125,10 +95,9 @@ func (p *Parser) parse(
125
95
return statements.PLpgStatement {}, err
126
96
}
127
97
return statements.PLpgStatement {
128
- AST : p .lexer .stmt ,
129
- SQL : sql ,
130
- NumPlaceholders : p .lexer .numPlaceholders ,
131
- NumAnnotations : p .lexer .numAnnotations ,
98
+ AST : p .lexer .stmt ,
99
+ SQL : sql ,
100
+ NumAnnotations : p .lexer .numAnnotations ,
132
101
}, nil
133
102
}
134
103
@@ -144,5 +113,15 @@ func (p *Parser) parse(
144
113
// operate with table OIDTypeReferences.
145
114
func Parse (sql string ) (statements.PLpgStatement , error ) {
146
115
var p Parser
147
- return p .parseWithDepth (1 , sql , defaultNakedIntType )
116
+ p .scanner .Init (sql )
117
+ defer p .scanner .Cleanup ()
118
+ sql , tokens , done := p .scanFnBlock ()
119
+ stmt , err := p .parse (sql , tokens )
120
+ if err != nil {
121
+ return statements.PLpgStatement {}, err
122
+ }
123
+ if ! done {
124
+ return statements.PLpgStatement {}, errors .AssertionFailedf ("invalid plpgsql function: %s" , sql )
125
+ }
126
+ return stmt , nil
148
127
}
0 commit comments