ddl_parser 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,6 +45,10 @@ module DDLParser
45
45
  (comma >> space? >> index_column_definition).repeat
46
46
  }
47
47
 
48
+ #rule(:element_list_index) { (space? >> index_column_definition >>
49
+ # (comma >> space? >> index_column_definition).repeat).as(elements)
50
+ # }
51
+
48
52
  rule(:add_constraint_clause) { (str('add constraint') >> space? >>
49
53
  constraint_name.as(:constraint_name) >> space? >>
50
54
  foreign_key_clause.as(:foreign_key_clause)).as(:add_constraint)
@@ -4,13 +4,17 @@ class DDLParser::Translator::CreateIndexHeader
4
4
 
5
5
 
6
6
  def initialize(index_hash)
7
-
8
- if index_hash.is_a?(Array) and index_hash.count > 1
9
- @index_head = index_hash.first.is_a?(Hash) ? index_hash.first : {}
10
- @index_columns = index_hash[1..-1]
7
+ if index_hash.is_a?(Hash) and index_hash.count > 1
8
+ @index_head = index_hash
9
+ @index_columns = [{:field =>index_hash[:field], :sort_id => index_hash[:sort_id]}]
11
10
  else
12
- @index_head = {}
13
- @index_columns = []
11
+ if index_hash.is_a?(Array) and index_hash.count > 1
12
+ @index_head = index_hash.first.is_a?(Hash) ? index_hash.first : {}
13
+ @index_columns = index_hash[1..-1]
14
+ else
15
+ @index_head = {}
16
+ @index_columns = []
17
+ end
14
18
  end
15
19
  end
16
20
 
@@ -1,3 +1,3 @@
1
1
  module DDLParser
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.14'
3
3
  end
@@ -32,6 +32,25 @@ EOF
32
32
  puts error.cause.ascii_tree
33
33
  end
34
34
 
35
+ result.count.should == 6
36
+ result.should include(:operation => 'create')
37
+ result.should include(:object_property => 'unique')
38
+ result.should include(:object_type => 'index')
39
+ result.should include(:index_name => 'cost_invoice_1')
40
+ result.should include(:table_name => 'cost_invoice')
41
+ result.should include(:field => 'doc_no')
42
+ end
43
+ it 'parses create_unique_index with two columns' do
44
+ sql = <<EOF
45
+ CREATE UNIQUE INDEX COST_INVOICE_1 ON COST_INVOICE
46
+ (DOC_NO, DOC_NO_1)
47
+ EOF
48
+ begin
49
+ result = parser.parse(sql.downcase)
50
+ rescue Parslet::ParseFailed => error
51
+ puts error.cause.ascii_tree
52
+ end
53
+
35
54
  result.count.should == 6
36
55
  result.should include(:operation => 'create')
37
56
  result.should include(:object_property => 'unique')
@@ -93,7 +93,7 @@ EOF
93
93
  end
94
94
  end
95
95
 
96
- context 'create index translate' do
96
+ context 'create index translate two index columns' do
97
97
  before :each do
98
98
  sql = 'CREATE UNIQUE INDEX REPLAN_ADDR_1 ON REPLAN_ADDR (CONSIGNMENT ASCENDING, COLLI DESCENDING)'
99
99
  @parser = DDLParser::Parser.new(sql)
@@ -109,6 +109,23 @@ EOF
109
109
  @parser.translate.columns.map(&:to_hash).should == [{:field=>"consignment", :sort_id=>"ascending"}, {:field=>"colli", :sort_id=>"descending"}]
110
110
  end
111
111
 
112
+ end
113
+ context 'create index translate one index column' do
114
+ before :each do
115
+ sql = 'CREATE UNIQUE INDEX REPLAN_ADDR_1 ON REPLAN_ADDR (CONSIGNMENT ASCENDING)'
116
+ @parser = DDLParser::Parser.new(sql)
117
+ end
118
+
119
+ it 'table name' do
120
+ @parser.translate.table_name.should == 'replan_addr'
121
+ end
122
+ it 'index name' do
123
+ @parser.translate.index_name.should == 'replan_addr_1'
124
+ end
125
+ it 'columns' do
126
+ @parser.translate.columns.map(&:to_hash).should == [{:field=>"consignment", :sort_id=>"ascending"}]
127
+ end
128
+
112
129
  end
113
130
 
114
131
  context 'report errors' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddl_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-24 00:00:00.000000000 Z
12
+ date: 2014-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet