Skip to content

Commit 502c84d

Browse files
authored
Add parser features and enable 12 more tests (#18)
1 parent 5df3fae commit 502c84d

40 files changed

Lines changed: 1622 additions & 95 deletions

File tree

ast/alter_database_set_statement.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,35 @@ type OnOffDatabaseOption struct {
3535
func (o *OnOffDatabaseOption) node() {}
3636
func (o *OnOffDatabaseOption) databaseOption() {}
3737

38+
// DelayedDurabilityDatabaseOption represents DELAYED_DURABILITY option
39+
type DelayedDurabilityDatabaseOption struct {
40+
OptionKind string // "DelayedDurability"
41+
Value string // "Disabled", "Allowed", "Forced"
42+
}
43+
44+
func (d *DelayedDurabilityDatabaseOption) node() {}
45+
func (d *DelayedDurabilityDatabaseOption) databaseOption() {}
46+
47+
// IdentifierDatabaseOption represents a database option with an identifier value
48+
type IdentifierDatabaseOption struct {
49+
OptionKind string `json:"OptionKind,omitempty"` // "CatalogCollation"
50+
Value *Identifier `json:"Value,omitempty"`
51+
}
52+
53+
func (i *IdentifierDatabaseOption) node() {}
54+
func (i *IdentifierDatabaseOption) databaseOption() {}
55+
56+
// CreateDatabaseOption is an interface for CREATE DATABASE options (can be DatabaseOption)
57+
type CreateDatabaseOption interface {
58+
node()
59+
createDatabaseOption()
60+
}
61+
62+
// Make existing database options implement CreateDatabaseOption
63+
func (o *OnOffDatabaseOption) createDatabaseOption() {}
64+
func (i *IdentifierDatabaseOption) createDatabaseOption() {}
65+
func (d *DelayedDurabilityDatabaseOption) createDatabaseOption() {}
66+
3867
// AlterDatabaseAddFileStatement represents ALTER DATABASE ... ADD FILE statement
3968
type AlterDatabaseAddFileStatement struct {
4069
DatabaseName *Identifier
@@ -97,6 +126,7 @@ func (a *AlterDatabaseRemoveFileStatement) statement() {}
97126
type AlterDatabaseRemoveFileGroupStatement struct {
98127
DatabaseName *Identifier
99128
FileGroupName *Identifier
129+
UseCurrent bool
100130
}
101131

102132
func (a *AlterDatabaseRemoveFileGroupStatement) node() {}

ast/alter_simple_statements.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func (s *AlterCertificateStatement) statement() {}
4848

4949
// AlterApplicationRoleStatement represents an ALTER APPLICATION ROLE statement.
5050
type AlterApplicationRoleStatement struct {
51-
Name *Identifier `json:"Name,omitempty"`
51+
Name *Identifier `json:"Name,omitempty"`
52+
ApplicationRoleOptions []*ApplicationRoleOption `json:"ApplicationRoleOptions,omitempty"`
5253
}
5354

5455
func (s *AlterApplicationRoleStatement) node() {}
@@ -64,7 +65,8 @@ func (s *AlterAsymmetricKeyStatement) statement() {}
6465

6566
// AlterQueueStatement represents an ALTER QUEUE statement.
6667
type AlterQueueStatement struct {
67-
Name *SchemaObjectName `json:"Name,omitempty"`
68+
Name *SchemaObjectName `json:"Name,omitempty"`
69+
QueueOptions []QueueOption `json:"QueueOptions,omitempty"`
6870
}
6971

7072
func (s *AlterQueueStatement) node() {}

ast/create_simple_statements.go

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package ast
22

33
// CreateDatabaseStatement represents a CREATE DATABASE statement.
44
type CreateDatabaseStatement struct {
5-
DatabaseName *Identifier `json:"DatabaseName,omitempty"`
5+
DatabaseName *Identifier `json:"DatabaseName,omitempty"`
6+
Options []CreateDatabaseOption `json:"Options,omitempty"`
7+
AttachMode string `json:"AttachMode,omitempty"` // "None", "Attach", "AttachRebuildLog"
68
}
79

810
func (s *CreateDatabaseStatement) node() {}
@@ -24,9 +26,33 @@ type CreateServiceStatement struct {
2426
func (s *CreateServiceStatement) node() {}
2527
func (s *CreateServiceStatement) statement() {}
2628

29+
// QueueOption is an interface for queue options.
30+
type QueueOption interface {
31+
node()
32+
queueOption()
33+
}
34+
35+
// QueueStateOption represents a queue state option (STATUS, RETENTION, POISON_MESSAGE_HANDLING).
36+
type QueueStateOption struct {
37+
OptionState string `json:"OptionState,omitempty"` // "On" or "Off"
38+
OptionKind string `json:"OptionKind,omitempty"` // "Status", "Retention", "PoisonMessageHandlingStatus"
39+
}
40+
41+
func (o *QueueStateOption) node() {}
42+
func (o *QueueStateOption) queueOption() {}
43+
44+
// QueueOptionSimple represents a simple queue option like ActivationDrop.
45+
type QueueOptionSimple struct {
46+
OptionKind string `json:"OptionKind,omitempty"` // e.g. "ActivationDrop"
47+
}
48+
49+
func (o *QueueOptionSimple) node() {}
50+
func (o *QueueOptionSimple) queueOption() {}
51+
2752
// CreateQueueStatement represents a CREATE QUEUE statement.
2853
type CreateQueueStatement struct {
29-
Name *SchemaObjectName `json:"Name,omitempty"`
54+
Name *SchemaObjectName `json:"Name,omitempty"`
55+
QueueOptions []QueueOption `json:"QueueOptions,omitempty"`
3056
}
3157

3258
func (s *CreateQueueStatement) node() {}
@@ -82,7 +108,10 @@ func (s *CreateSymmetricKeyStatement) statement() {}
82108

83109
// CreateMessageTypeStatement represents a CREATE MESSAGE TYPE statement.
84110
type CreateMessageTypeStatement struct {
85-
Name *Identifier `json:"Name,omitempty"`
111+
Name *Identifier `json:"Name,omitempty"`
112+
Owner *Identifier `json:"Owner,omitempty"`
113+
ValidationMethod string `json:"ValidationMethod,omitempty"`
114+
XmlSchemaCollectionName *SchemaObjectName `json:"XmlSchemaCollectionName,omitempty"`
86115
}
87116

88117
func (s *CreateMessageTypeStatement) node() {}
@@ -98,12 +127,21 @@ func (s *CreateRemoteServiceBindingStatement) statement() {}
98127

99128
// CreateApplicationRoleStatement represents a CREATE APPLICATION ROLE statement.
100129
type CreateApplicationRoleStatement struct {
101-
Name *Identifier `json:"Name,omitempty"`
130+
Name *Identifier `json:"Name,omitempty"`
131+
ApplicationRoleOptions []*ApplicationRoleOption `json:"ApplicationRoleOptions,omitempty"`
102132
}
103133

104134
func (s *CreateApplicationRoleStatement) node() {}
105135
func (s *CreateApplicationRoleStatement) statement() {}
106136

137+
// ApplicationRoleOption represents an option in CREATE/ALTER APPLICATION ROLE
138+
type ApplicationRoleOption struct {
139+
OptionKind string `json:"OptionKind,omitempty"`
140+
Value *IdentifierOrValueExpression `json:"Value,omitempty"`
141+
}
142+
143+
func (o *ApplicationRoleOption) node() {}
144+
107145
// CreateFulltextCatalogStatement represents a CREATE FULLTEXT CATALOG statement.
108146
type CreateFulltextCatalogStatement struct {
109147
Name *Identifier `json:"Name,omitempty"`
@@ -150,8 +188,11 @@ func (s *CreateIndexStatement) statement() {}
150188

151189
// CreateStatisticsStatement represents a CREATE STATISTICS statement.
152190
type CreateStatisticsStatement struct {
153-
Name *Identifier `json:"Name,omitempty"`
154-
OnName *SchemaObjectName `json:"OnName,omitempty"`
191+
Name *Identifier `json:"Name,omitempty"`
192+
OnName *SchemaObjectName `json:"OnName,omitempty"`
193+
Columns []*ColumnReferenceExpression `json:"Columns,omitempty"`
194+
StatisticsOptions []StatisticsOption `json:"StatisticsOptions,omitempty"`
195+
FilterPredicate BooleanExpression `json:"FilterPredicate,omitempty"`
155196
}
156197

157198
func (s *CreateStatisticsStatement) node() {}

ast/cursor_statements.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package ast
2+
3+
// FetchType represents the orientation for a FETCH statement.
4+
type FetchType struct {
5+
Orientation string `json:"Orientation,omitempty"`
6+
RowOffset ScalarExpression `json:"RowOffset,omitempty"`
7+
}
8+
9+
// DeclareCursorStatement represents DECLARE cursor_name CURSOR FOR SELECT.
10+
type DeclareCursorStatement struct {
11+
Name *Identifier `json:"Name,omitempty"`
12+
CursorDefinition *CursorDefinition `json:"CursorDefinition,omitempty"`
13+
}
14+
15+
func (s *DeclareCursorStatement) node() {}
16+
func (s *DeclareCursorStatement) statement() {}
17+
18+
// OpenCursorStatement represents OPEN cursor_name.
19+
type OpenCursorStatement struct {
20+
Cursor *CursorId `json:"Cursor,omitempty"`
21+
}
22+
23+
func (s *OpenCursorStatement) node() {}
24+
func (s *OpenCursorStatement) statement() {}
25+
26+
// CloseCursorStatement represents CLOSE cursor_name.
27+
type CloseCursorStatement struct {
28+
Cursor *CursorId `json:"Cursor,omitempty"`
29+
}
30+
31+
func (s *CloseCursorStatement) node() {}
32+
func (s *CloseCursorStatement) statement() {}
33+
34+
// DeallocateCursorStatement represents DEALLOCATE cursor_name.
35+
type DeallocateCursorStatement struct {
36+
Cursor *CursorId `json:"Cursor,omitempty"`
37+
}
38+
39+
func (s *DeallocateCursorStatement) node() {}
40+
func (s *DeallocateCursorStatement) statement() {}
41+
42+
// FetchCursorStatement represents FETCH cursor_name.
43+
type FetchCursorStatement struct {
44+
FetchType *FetchType `json:"FetchType,omitempty"`
45+
Cursor *CursorId `json:"Cursor,omitempty"`
46+
IntoVariables []ScalarExpression `json:"IntoVariables,omitempty"`
47+
}
48+
49+
func (s *FetchCursorStatement) node() {}
50+
func (s *FetchCursorStatement) statement() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ast
2+
3+
// EnableDisableTriggerStatement represents ENABLE/DISABLE TRIGGER statements
4+
type EnableDisableTriggerStatement struct {
5+
TriggerEnforcement string // "Enable" or "Disable"
6+
All bool // true if ENABLE/DISABLE TRIGGER ALL
7+
TriggerNames []*SchemaObjectName
8+
TriggerObject *TriggerObject
9+
}
10+
11+
func (s *EnableDisableTriggerStatement) statement() {}
12+
func (s *EnableDisableTriggerStatement) node() {}

ast/update_statistics_statement.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package ast
2+
3+
// UpdateStatisticsStatement represents UPDATE STATISTICS.
4+
type UpdateStatisticsStatement struct {
5+
SchemaObjectName *SchemaObjectName `json:"SchemaObjectName,omitempty"`
6+
SubElements []*Identifier `json:"SubElements,omitempty"`
7+
StatisticsOptions []StatisticsOption `json:"StatisticsOptions,omitempty"`
8+
}
9+
10+
func (u *UpdateStatisticsStatement) node() {}
11+
func (u *UpdateStatisticsStatement) statement() {}
12+
13+
// StatisticsOption is an interface for statistics options.
14+
type StatisticsOption interface {
15+
statisticsOption()
16+
}
17+
18+
// SimpleStatisticsOption represents a simple statistics option like ALL, FULLSCAN, etc.
19+
type SimpleStatisticsOption struct {
20+
OptionKind string `json:"OptionKind,omitempty"`
21+
}
22+
23+
func (s *SimpleStatisticsOption) statisticsOption() {}
24+
25+
// LiteralStatisticsOption represents a statistics option with a literal value.
26+
type LiteralStatisticsOption struct {
27+
OptionKind string `json:"OptionKind,omitempty"`
28+
Literal ScalarExpression `json:"Literal,omitempty"`
29+
}
30+
31+
func (l *LiteralStatisticsOption) statisticsOption() {}
32+
33+
// OnOffStatisticsOption represents a statistics option with ON/OFF value.
34+
type OnOffStatisticsOption struct {
35+
OptionKind string `json:"OptionKind,omitempty"`
36+
OptionState string `json:"OptionState,omitempty"`
37+
}
38+
39+
func (o *OnOffStatisticsOption) statisticsOption() {}
40+
41+
// ResampleStatisticsOption represents RESAMPLE statistics option.
42+
type ResampleStatisticsOption struct {
43+
OptionKind string `json:"OptionKind,omitempty"`
44+
Partitions []ScalarExpression `json:"Partitions,omitempty"`
45+
}
46+
47+
func (r *ResampleStatisticsOption) statisticsOption() {}

0 commit comments

Comments
 (0)