ddl_parser 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/Rakefile +1 -1
- data/ddl_parser.gemspec +10 -10
- data/lib/ddl_parser/ddl/db2/parser.rb +14 -14
- data/lib/ddl_parser/ddl/db2.rb +1 -1
- data/lib/ddl_parser/ddl.rb +1 -1
- data/lib/ddl_parser/parser.rb +9 -7
- data/lib/ddl_parser/shared_rules/constants.rb +12 -12
- data/lib/ddl_parser/shared_rules/data_types.rb +13 -13
- data/lib/ddl_parser/shared_rules.rb +3 -3
- data/lib/ddl_parser/sql/db2.rb +1 -1
- data/lib/ddl_parser/sql.rb +1 -1
- data/lib/ddl_parser/{translater → translator}/alter_table.rb +1 -1
- data/lib/ddl_parser/{translater → translator}/create_index.rb +1 -1
- data/lib/ddl_parser/{translater → translator}/create_table.rb +1 -1
- data/lib/ddl_parser/translator.rb +6 -0
- data/lib/ddl_parser/version.rb +1 -1
- data/lib/ddl_parser.rb +9 -9
- data/spec/ddl_parser/ddl/db2/alter_table_spec.rb +20 -20
- data/spec/ddl_parser/ddl/db2/create_index_spec.rb +5 -5
- data/spec/ddl_parser/ddl/db2/create_table_spec.rb +170 -171
- data/spec/ddl_parser/parser_spec.rb +39 -39
- data/spec/ddl_parser/shared_rules/constants_spec.rb +65 -65
- data/spec/ddl_parser/shared_rules/data_types_spec.rb +14 -14
- data/spec/ddl_parser/sql/db2/select_parser_spec.rb +58 -58
- data/spec/spec_helper.rb +6 -6
- metadata +14 -14
- data/lib/ddl_parser/translater.rb +0 -6
@@ -1,119 +1,119 @@
|
|
1
|
-
|
1
|
+
require_relative '../../../../spec/spec_helper'
|
2
2
|
|
3
3
|
describe DDLParser::DDL::DB2::Parser do
|
4
4
|
let(:parser) { DDLParser::DDL::DB2::Parser.new }
|
5
5
|
|
6
|
-
context
|
6
|
+
context 'building blocks' do
|
7
7
|
|
8
|
-
it
|
9
|
-
parser.arglist.parse(
|
10
|
-
parser.arglist.parse(
|
11
|
-
parser.arglist.parse(
|
8
|
+
it 'parses arglist' do
|
9
|
+
parser.arglist.parse('a').should == {:item=> 'a'}
|
10
|
+
parser.arglist.parse('a,b,c').should == [{:item=> 'a'}, {:item=> 'b'}, {:item=> 'c'}]
|
11
|
+
parser.arglist.parse('a, b, c').should == [{:item=> 'a'}, {:item=> 'b'}, {:item=> 'c'}]
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
15
15
|
|
16
|
-
context
|
17
|
-
it
|
18
|
-
expect(parser.column_options).to parse(
|
16
|
+
context 'column options parsing' do
|
17
|
+
it 'parses not null' do
|
18
|
+
expect(parser.column_options).to parse('not null')
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
expect(parser.column_options).to parse(
|
23
|
-
expect(parser.column_options).to parse(
|
24
|
-
expect(parser.column_options).to parse(
|
21
|
+
it 'parses default values' do
|
22
|
+
expect(parser.column_options).to parse('default 1')
|
23
|
+
expect(parser.column_options).to parse('with default 1')
|
24
|
+
expect(parser.column_options).to parse('default current timestamp')
|
25
25
|
expect(parser.column_options).to parse("default 'foobar'")
|
26
|
-
expect(parser.column_options).to parse(
|
26
|
+
expect(parser.column_options).to parse('default max(foo)')
|
27
27
|
|
28
28
|
expect(
|
29
|
-
parser.column_options.parse(
|
30
|
-
).to eq([{:default_clause=>[{:integer=>
|
29
|
+
parser.column_options.parse('default 1')
|
30
|
+
).to eq([{:default_clause=>[{:integer=> '1'}]}])
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
34
|
-
sql =
|
33
|
+
it 'parses generated by' do
|
34
|
+
sql = 'generated by default as identity (start with 1 increment by 1 cache 20 )'
|
35
35
|
begin
|
36
36
|
result = parser.column_options.parse(sql.downcase)
|
37
37
|
rescue Parslet::ParseFailed => error
|
38
38
|
puts error.cause.ascii_tree
|
39
39
|
end
|
40
|
-
result.should == [{:identity=>{:start_value=>{:integer=>
|
41
|
-
:increment_value=>{:integer=>
|
42
|
-
:cache_value=>{:integer=>
|
40
|
+
result.should == [{:identity=>{:start_value=>{:integer=> '1'},
|
41
|
+
:increment_value=>{:integer=> '1'},
|
42
|
+
:cache_value=>{:integer=> '20'}}}]
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
46
|
-
expect(parser.column_options).to parse(
|
45
|
+
it 'parses identity' do
|
46
|
+
expect(parser.column_options).to parse('as identity (start with 500, increment by 1)')
|
47
47
|
expect(
|
48
|
-
parser.column_options.parse(
|
49
|
-
).to eq([{:identity=>{:start_value=>{:integer=>
|
48
|
+
parser.column_options.parse('as identity (start with 500, increment by 1)')
|
49
|
+
).to eq([{:identity=>{:start_value=>{:integer=> '500'}, :increment_value=>{:integer=> '1'}}}])
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
53
|
-
expect(parser.column_options).to parse(
|
52
|
+
it 'parses multible' do
|
53
|
+
expect(parser.column_options).to parse('not null as identity (start with 500, increment by 1)')
|
54
54
|
|
55
|
-
result = parser.column_options.parse(
|
55
|
+
result = parser.column_options.parse('not null as identity (start with 500, increment by 1)')
|
56
56
|
result.first.should include(:column_option)
|
57
57
|
result.last.should include(:identity)
|
58
58
|
end
|
59
59
|
|
60
60
|
end
|
61
61
|
|
62
|
-
context
|
63
|
-
it
|
64
|
-
sql =
|
65
|
-
parser.primary_key.parse(sql).should == {:primary_key=>{:item=>
|
62
|
+
context 'constraint' do
|
63
|
+
it 'parses primary key' do
|
64
|
+
sql = 'primary key (id)'
|
65
|
+
parser.primary_key.parse(sql).should == {:primary_key=>{:item=> 'id'}}
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
69
|
-
sql =
|
70
|
-
parser.primary_key.parse(sql).should == {:primary_key=>[{:item=>
|
68
|
+
it 'parses composed primary key' do
|
69
|
+
sql = 'primary key (id,foo)'
|
70
|
+
parser.primary_key.parse(sql).should == {:primary_key=>[{:item=> 'id'}, {:item=> 'foo'}]}
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
74
|
-
sql =
|
73
|
+
it 'parses unique' do
|
74
|
+
sql = 'constraint emp_act_uniq unique (empno,projno,actno)'
|
75
75
|
|
76
|
-
parser.constraint.parse(sql).should == {:constraint=>{:column_name=>
|
77
|
-
:constraint_type=>
|
78
|
-
:constraint_arglist=>[{:item=>
|
79
|
-
{:item=>
|
80
|
-
{:item=>
|
76
|
+
parser.constraint.parse(sql).should == {:constraint=>{:column_name=> 'emp_act_uniq',
|
77
|
+
:constraint_type=> 'unique',
|
78
|
+
:constraint_arglist=>[{:item=> 'empno'},
|
79
|
+
{:item=> 'projno'},
|
80
|
+
{:item=> 'actno'}]}}
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
84
|
-
sql =
|
83
|
+
it 'parses foreign key' do
|
84
|
+
sql = 'constraint fk_act_proj foreign key (projno) references project (projno) on delete cascade'
|
85
85
|
begin
|
86
86
|
result = parser.constraint.parse(sql)
|
87
87
|
rescue Parslet::ParseFailed => error
|
88
88
|
puts error.cause.ascii_tree
|
89
89
|
end
|
90
|
-
result.should == {:constraint=>{:column_name=>
|
91
|
-
:constraint_type=>
|
92
|
-
:constraint_arglist=>{:item=>
|
93
|
-
:reference_arglist=>{:item=>
|
90
|
+
result.should == {:constraint=>{:column_name=> 'fk_act_proj',
|
91
|
+
:constraint_type=> 'foreign key',
|
92
|
+
:constraint_arglist=>{:item=> 'projno'},
|
93
|
+
:reference_arglist=>{:item=> 'projno'}}}
|
94
94
|
end
|
95
95
|
|
96
96
|
end
|
97
97
|
|
98
|
-
context
|
99
|
-
it
|
100
|
-
sql =
|
98
|
+
context 'column definition' do
|
99
|
+
it 'parses char not null' do
|
100
|
+
sql = 'deptno char(3) not null'
|
101
101
|
parser.column_definition.parse(sql).should == {:column => {
|
102
|
-
:field=>
|
103
|
-
:data_type=>{:char=>{:length=>{:integer=>
|
104
|
-
:options=>[{:column_option=>
|
102
|
+
:field=> 'deptno',
|
103
|
+
:data_type=>{:char=>{:length=>{:integer=> '3'}}},
|
104
|
+
:options=>[{:column_option=> 'not null'}]
|
105
105
|
}
|
106
106
|
}
|
107
107
|
|
108
108
|
end
|
109
|
-
it
|
110
|
-
sql =
|
109
|
+
it 'parses char not null - x' do
|
110
|
+
sql = 'BUDGET_AMOUNT_IN_CO DECIMAL(15,2) NOT NULL DEFAULT 0'
|
111
111
|
parser.column_definition.parse(sql.downcase).should == {:column => {
|
112
|
-
:field=>
|
112
|
+
:field=> 'budget_amount_in_co',
|
113
113
|
:data_type=>{:decimal=>{:precision=>
|
114
|
-
{:total=>{:integer=>
|
115
|
-
:scale=>{:integer=>
|
116
|
-
:options=>[{:column_option=>
|
114
|
+
{:total=>{:integer=> '15'},
|
115
|
+
:scale=>{:integer=> '2'}}}},
|
116
|
+
:options=>[{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
|
117
117
|
}
|
118
118
|
}
|
119
119
|
|
@@ -121,55 +121,55 @@ describe DDLParser::DDL::DB2::Parser do
|
|
121
121
|
|
122
122
|
end
|
123
123
|
|
124
|
-
context
|
125
|
-
it
|
126
|
-
sql =
|
127
|
-
parser.element_list.parse(sql).should == {:elements => {:column=>{:field=>
|
128
|
-
:data_type=>{:char=>{:length=>{:integer=>
|
129
|
-
:options=>[{:column_option=>
|
124
|
+
context 'element list' do
|
125
|
+
it 'parses one element' do
|
126
|
+
sql = '(deptno char(3) not null)'
|
127
|
+
parser.element_list.parse(sql).should == {:elements => {:column=>{:field=> 'deptno',
|
128
|
+
:data_type=>{:char=>{:length=>{:integer=> '3'}}},
|
129
|
+
:options=>[{:column_option=> 'not null'}]}}}
|
130
130
|
end
|
131
131
|
|
132
|
-
it
|
133
|
-
sql =
|
134
|
-
parser.element_list.parse(sql).should == {:elements => [{:column=>{:field=>
|
135
|
-
:data_type=>{:char=>{:length=>{:integer=>
|
136
|
-
:options=>[{:column_option=>
|
137
|
-
{:column=>{:field=>
|
138
|
-
:data_type=>{:char=>{:length=>{:integer=>
|
139
|
-
:options=>
|
132
|
+
it 'parses two element' do
|
133
|
+
sql = '(field1 char(1) not null, field2 char(2))'
|
134
|
+
parser.element_list.parse(sql).should == {:elements => [{:column=>{:field=> 'field1',
|
135
|
+
:data_type=>{:char=>{:length=>{:integer=> '1'}}},
|
136
|
+
:options=>[{:column_option=> 'not null'}]}},
|
137
|
+
{:column=>{:field=> 'field2',
|
138
|
+
:data_type=>{:char=>{:length=>{:integer=> '2'}}},
|
139
|
+
:options=> ''}}]}
|
140
140
|
end
|
141
141
|
|
142
|
-
it
|
142
|
+
it 'parses with new lines' do
|
143
143
|
sql = <<EOF
|
144
144
|
(
|
145
145
|
DEPTNO CHAR(3) NOT NULL,
|
146
146
|
DEPTNAME VARCHAR(36) NOT NULL
|
147
147
|
)
|
148
148
|
EOF
|
149
|
-
parser.element_list.parse(sql.downcase).should == {:elements => [{:column=>{:field=>
|
150
|
-
:data_type=>{:char=>{:length=>{:integer=>
|
151
|
-
:options=>[{:column_option=>
|
152
|
-
{:column=>{:field=>
|
153
|
-
:data_type=>{:varchar=>{:length=>{:integer=>
|
154
|
-
:options=>[{:column_option=>
|
149
|
+
parser.element_list.parse(sql.downcase).should == {:elements => [{:column=>{:field=> 'deptno',
|
150
|
+
:data_type=>{:char=>{:length=>{:integer=> '3'}}},
|
151
|
+
:options=>[{:column_option=> 'not null'}]}},
|
152
|
+
{:column=>{:field=> 'deptname',
|
153
|
+
:data_type=>{:varchar=>{:length=>{:integer=> '36'}}},
|
154
|
+
:options=>[{:column_option=> 'not null'}]}}]}
|
155
155
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
context
|
160
|
-
it
|
161
|
-
expect(parser.create_table_statement).to parse(
|
162
|
-
expect(parser.create_table_statement).not_to parse(
|
159
|
+
context 'create table' do
|
160
|
+
it 'parses simple create' do
|
161
|
+
expect(parser.create_table_statement).to parse('create table foobar')
|
162
|
+
expect(parser.create_table_statement).not_to parse('create table ')
|
163
163
|
|
164
|
-
parser.create_table_statement.parse(
|
164
|
+
parser.create_table_statement.parse('create table foobar').should == {:operation=> 'create table', :table_name => 'foobar'}
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
168
|
|
169
169
|
|
170
|
-
context
|
170
|
+
context 'simple statements' do
|
171
171
|
|
172
|
-
it
|
172
|
+
it 'parses Example 1' do
|
173
173
|
sql = <<EOF
|
174
174
|
CREATE TABLE TDEPT
|
175
175
|
(DEPTNO CHAR(3) NOT NULL,
|
@@ -178,44 +178,44 @@ EOF
|
|
178
178
|
ADMRDEPT DECIMAL(3,1) NOT NULL)
|
179
179
|
IN DEPARTX
|
180
180
|
EOF
|
181
|
-
parser.create_table.parse(sql.downcase).should == {:operation=>
|
182
|
-
:table_name=>
|
181
|
+
parser.create_table.parse(sql.downcase).should == {:operation=> 'create table',
|
182
|
+
:table_name=> 'tdept',
|
183
183
|
:elements => [
|
184
|
-
{:column=>{:field=>
|
185
|
-
:data_type=>{:char=>{:length=>{:integer=>
|
186
|
-
:options=>[{:column_option=>
|
187
|
-
{:column=>{:field=>
|
188
|
-
:data_type=>{:varchar=>{:length=>{:integer=>
|
189
|
-
:options=>[{:column_option=>
|
190
|
-
{:column=>{:field=>
|
191
|
-
:data_type=>
|
192
|
-
:options=>
|
193
|
-
{:column=>{:field=>
|
194
|
-
:data_type=>{:decimal=>{:precision=>{:total=>{:integer=>
|
195
|
-
:options=>[{:column_option=>
|
184
|
+
{:column=>{:field=> 'deptno',
|
185
|
+
:data_type=>{:char=>{:length=>{:integer=> '3'}}},
|
186
|
+
:options=>[{:column_option=> 'not null'}]}},
|
187
|
+
{:column=>{:field=> 'deptname',
|
188
|
+
:data_type=>{:varchar=>{:length=>{:integer=> '36'}}},
|
189
|
+
:options=>[{:column_option=> 'not null'}]}},
|
190
|
+
{:column=>{:field=> 'mgrno',
|
191
|
+
:data_type=> 'int',
|
192
|
+
:options=> ''}},
|
193
|
+
{:column=>{:field=> 'admrdept',
|
194
|
+
:data_type=>{:decimal=>{:precision=>{:total=>{:integer=> '3'}, :scale=>{:integer=> '1'}}}},
|
195
|
+
:options=>[{:column_option=> 'not null'}]}}
|
196
196
|
]}
|
197
197
|
end
|
198
198
|
|
199
|
-
it
|
199
|
+
it 'parses with primary key' do
|
200
200
|
sql = <<EOF
|
201
201
|
CREATE TABLE TEST
|
202
202
|
(ID INT,
|
203
203
|
PRIMARY KEY (ID))
|
204
204
|
EOF
|
205
|
-
parser.create_table.parse(sql.downcase).should == {:operation=>
|
206
|
-
:table_name=>
|
205
|
+
parser.create_table.parse(sql.downcase).should == {:operation=> 'create table',
|
206
|
+
:table_name=> 'test',
|
207
207
|
:elements=>[
|
208
|
-
{:column => {:field=>
|
209
|
-
{:primary_key=>{:item=>
|
208
|
+
{:column => {:field=> 'id', :data_type=> 'int', :options=> ''}},
|
209
|
+
{:primary_key=>{:item=> 'id'}}
|
210
210
|
]
|
211
211
|
}
|
212
212
|
end
|
213
213
|
|
214
214
|
end
|
215
215
|
|
216
|
-
context
|
216
|
+
context 'full statements' do
|
217
217
|
|
218
|
-
it
|
218
|
+
it 'parses Example 2' do
|
219
219
|
sql = <<EOF
|
220
220
|
CREATE TABLE PROJ
|
221
221
|
(PROJNO CHAR(6) NOT NULL,
|
@@ -231,7 +231,7 @@ EOF
|
|
231
231
|
expect(parser).to parse(sql.downcase)
|
232
232
|
end
|
233
233
|
|
234
|
-
it
|
234
|
+
it 'parses Example 3' do
|
235
235
|
sql = <<EOF
|
236
236
|
CREATE TABLE EMPLOYEE_SALARY
|
237
237
|
(DEPTNO CHAR(3) NOT NULL,
|
@@ -242,8 +242,8 @@ EOF
|
|
242
242
|
expect(parser).to parse(sql.downcase)
|
243
243
|
end
|
244
244
|
|
245
|
-
it
|
246
|
-
pending
|
245
|
+
it 'parses Example 6' do
|
246
|
+
pending 'we do not support CHECK statements'
|
247
247
|
sql = <<EOF
|
248
248
|
CREATE TABLE EMPLOYEE
|
249
249
|
(ID SMALLINT NOT NULL,
|
@@ -261,14 +261,13 @@ EOF
|
|
261
261
|
EOF
|
262
262
|
begin
|
263
263
|
result = parser.parse(sql.downcase)
|
264
|
-
rescue Parslet::ParseFailed => error
|
265
|
-
puts error.cause.ascii_tree
|
264
|
+
# rescue Parslet::ParseFailed => error
|
265
|
+
# puts error.cause.ascii_tree
|
266
266
|
end
|
267
|
-
result.should == [{:operation=>
|
268
|
-
|
267
|
+
result.should == [{:operation=> 'create table', :table_name=> 'emp_act'}]
|
269
268
|
end
|
270
269
|
|
271
|
-
it
|
270
|
+
it 'parses Example 11' do
|
272
271
|
sql = <<EOF
|
273
272
|
CREATE TABLE EMP_ACT
|
274
273
|
(EMPNO CHAR(6) NOT NULL,
|
@@ -288,45 +287,45 @@ EOF
|
|
288
287
|
rescue Parslet::ParseFailed => error
|
289
288
|
puts error.cause.ascii_tree
|
290
289
|
end
|
291
|
-
result.should == {:operation=>
|
292
|
-
:table_name=>
|
290
|
+
result.should == {:operation=> 'create table',
|
291
|
+
:table_name=> 'emp_act',
|
293
292
|
:elements => [
|
294
293
|
{:column=>
|
295
|
-
{:field=>
|
296
|
-
:data_type=>{:char=>{:length=>{:integer=>
|
297
|
-
:options=>[{:column_option=>
|
294
|
+
{:field=> 'empno',
|
295
|
+
:data_type=>{:char=>{:length=>{:integer=> '6'}}},
|
296
|
+
:options=>[{:column_option=> 'not null'}]}},
|
298
297
|
{:column=>
|
299
|
-
{:field=>
|
300
|
-
:data_type=>{:char=>{:length=>{:integer=>
|
301
|
-
:options=>[{:column_option=>
|
298
|
+
{:field=> 'projno',
|
299
|
+
:data_type=>{:char=>{:length=>{:integer=> '6'}}},
|
300
|
+
:options=>[{:column_option=> 'not null'}]}},
|
302
301
|
{:column=>
|
303
|
-
{:field=>
|
304
|
-
:data_type=>
|
305
|
-
:options=>[{:column_option=>
|
302
|
+
{:field=> 'actno',
|
303
|
+
:data_type=> 'smallint',
|
304
|
+
:options=>[{:column_option=> 'not null'}]}},
|
306
305
|
{:column=>
|
307
|
-
{:field=>
|
306
|
+
{:field=> 'emptime',
|
308
307
|
:data_type=>
|
309
308
|
{:decimal=>
|
310
309
|
{:precision=>
|
311
|
-
{:total=>{:integer=>
|
312
|
-
:options=>
|
313
|
-
{:column=>{:field=>
|
314
|
-
{:column=>{:field=>
|
310
|
+
{:total=>{:integer=> '5'}, :scale=>{:integer=> '2'}}}},
|
311
|
+
:options=> ''}},
|
312
|
+
{:column=>{:field=> 'emstdate', :data_type=> 'date', :options=> ''}},
|
313
|
+
{:column=>{:field=> 'emendate', :data_type=> 'date', :options=> ''}},
|
315
314
|
{:constraint=>
|
316
|
-
{:column_name=>
|
317
|
-
:constraint_type=>
|
315
|
+
{:column_name=> 'emp_act_uniq',
|
316
|
+
:constraint_type=> 'unique',
|
318
317
|
:constraint_arglist=>
|
319
|
-
[{:item=>
|
318
|
+
[{:item=> 'empno'}, {:item=> 'projno'}, {:item=> 'actno'}]}},
|
320
319
|
{:constraint=>
|
321
|
-
{:column_name=>
|
322
|
-
:constraint_type=>
|
323
|
-
:constraint_arglist=>{:item=>
|
324
|
-
:reference_arglist=>{:item=>
|
320
|
+
{:column_name=> 'fk_act_proj',
|
321
|
+
:constraint_type=> 'foreign key',
|
322
|
+
:constraint_arglist=>{:item=> 'projno'},
|
323
|
+
:reference_arglist=>{:item=> 'projno'}}}
|
325
324
|
]}
|
326
325
|
|
327
326
|
end
|
328
327
|
|
329
|
-
it
|
328
|
+
it 'parses Example 12' do
|
330
329
|
sql = <<EOF
|
331
330
|
CREATE TABLE HOCKEY_GOALS
|
332
331
|
( BY_PLAYER VARCHAR(30) NOT NULL,
|
@@ -341,17 +340,17 @@ EOF
|
|
341
340
|
rescue Parslet::ParseFailed => error
|
342
341
|
puts error.cause.ascii_tree
|
343
342
|
end
|
344
|
-
result.should == {:operation=>
|
343
|
+
result.should == {:operation=> 'create table', :table_name=> 'hockey_goals',
|
345
344
|
:elements => [
|
346
|
-
{:column=>{:field=>
|
347
|
-
{:column=>{:field=>
|
348
|
-
{:column=>{:field=>
|
349
|
-
{:column=>{:field=>
|
350
|
-
{:column=>{:field=>
|
351
|
-
{:column=>{:field=>
|
345
|
+
{:column=>{:field=> 'by_player', :data_type=>{:varchar=>{:length=>{:integer=> '30'}}}, :options=>[{:column_option=> 'not null'}]}},
|
346
|
+
{:column=>{:field=> 'by_team', :data_type=>{:varchar=>{:length=>{:integer=> '30'}}}, :options=>[{:column_option=> 'not null'}]}},
|
347
|
+
{:column=>{:field=> 'against_player', :data_type=>{:varchar=>{:length=>{:integer=> '30'}}}, :options=>[{:column_option=> 'not null'}]}},
|
348
|
+
{:column=>{:field=> 'against_team', :data_type=>{:varchar=>{:length=>{:integer=> '30'}}}, :options=>[{:column_option=> 'not null'}]}},
|
349
|
+
{:column=>{:field=> 'date_of_goal', :data_type=> 'date', :options=>[{:column_option=> 'not null'}]}},
|
350
|
+
{:column=>{:field=> 'description', :data_type=>{:clob=>{:length=>{:integer=> '5000'}}}, :options=> ''}}]}
|
352
351
|
end
|
353
352
|
|
354
|
-
it
|
353
|
+
it 'parses Example 16' do
|
355
354
|
sql = <<EOF
|
356
355
|
CREATE TABLE DEPT
|
357
356
|
(DEPTNO SMALLINT NOT NULL
|
@@ -369,31 +368,31 @@ EOF
|
|
369
368
|
puts error.cause.ascii_tree
|
370
369
|
end
|
371
370
|
|
372
|
-
result.should == {:operation=>
|
373
|
-
:table_name=>
|
371
|
+
result.should == {:operation=> 'create table',
|
372
|
+
:table_name=> 'dept',
|
374
373
|
:elements => [
|
375
|
-
{:column=>{:field=>
|
376
|
-
:data_type=>
|
377
|
-
:options=>[{:column_option=>
|
378
|
-
{:identity=>{:start_value=>{:integer=>
|
379
|
-
{:column=>{:field=>
|
380
|
-
:data_type=>{:varchar=>{:length=>{:integer=>
|
381
|
-
:options=>[{:column_option=>
|
382
|
-
{:column=>{:field=>
|
383
|
-
:data_type=>{:char=>{:length=>{:integer=>
|
384
|
-
:options=>
|
385
|
-
{:column=>{:field=>
|
386
|
-
:data_type=>
|
387
|
-
:options=>[{:column_option=>
|
388
|
-
{:column=>{:field=>
|
389
|
-
:data_type=>{:char=>{:length=>{:integer=>
|
390
|
-
:options=>
|
374
|
+
{:column=>{:field=> 'deptno',
|
375
|
+
:data_type=> 'smallint',
|
376
|
+
:options=>[{:column_option=> 'not null'},
|
377
|
+
{:identity=>{:start_value=>{:integer=> '500'}, :increment_value=>{:integer=> '1'}}}]}},
|
378
|
+
{:column=>{:field=> 'deptname',
|
379
|
+
:data_type=>{:varchar=>{:length=>{:integer=> '36'}}},
|
380
|
+
:options=>[{:column_option=> 'not null'}]}},
|
381
|
+
{:column=>{:field=> 'mgrno',
|
382
|
+
:data_type=>{:char=>{:length=>{:integer=> '6'}}},
|
383
|
+
:options=> ''}},
|
384
|
+
{:column=>{:field=> 'admrdept',
|
385
|
+
:data_type=> 'smallint',
|
386
|
+
:options=>[{:column_option=> 'not null'}]}},
|
387
|
+
{:column=>{:field=> 'location',
|
388
|
+
:data_type=>{:char=>{:length=>{:integer=> '30'}}},
|
389
|
+
:options=> ''}}]}
|
391
390
|
end
|
392
391
|
|
393
392
|
end
|
394
393
|
|
395
|
-
context
|
396
|
-
it
|
394
|
+
context 'real dsv examples' do
|
395
|
+
it 'parses Example 16' do
|
397
396
|
|
398
397
|
sql = <<EOF
|
399
398
|
Create table USER (USER_RW CHAR(4) NOT NULL,
|
@@ -418,8 +417,8 @@ EOF
|
|
418
417
|
puts error.cause.ascii_tree
|
419
418
|
end
|
420
419
|
|
421
|
-
result[:operation].should ==
|
422
|
-
result[:table_name].should ==
|
420
|
+
result[:operation].should == 'create table'
|
421
|
+
result[:table_name].should == 'user'
|
423
422
|
end
|
424
423
|
|
425
424
|
|