gda 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24187edab9ea611cc70441c2cd71e6ebf45b1e35
4
- data.tar.gz: ea34f33ca8d22358c1f9e3649179dfcfc403cabe
3
+ metadata.gz: 09209a9fa57de499346a00205d6192c1fdc814b2
4
+ data.tar.gz: e5f046ad0e79ad6cbd379348140455837fe458c9
5
5
  SHA512:
6
- metadata.gz: fdbad785a72ccd235f8b0cf214b776db7d3c7f0db20a7561fd02163a520c055858323994944f68fc714e535a1866400c0fd256581ed6f91c0b665521a86d918f
7
- data.tar.gz: 21f5de0090fdf3d28415f144eadf936a9021145c12de5f7cd29a6bb14b5aef3d1204eb9ca03bc3adea973a90c24ee52dc35e580d641004487a4f8389f168f961
6
+ metadata.gz: 05f0726618f23cf50ce0e78215401bdfc4729ebb6ee4058e558947ad984b31a6c9fa52717965453c797fdfd2b08a89b3e90244e57a0dd401bb61da4a194d39f5
7
+ data.tar.gz: 97f55889fb6c30db52176f9ed61d7b8678702f2627f1c87be1f67dee193eb8df4c78813ac0d3ea8d5ad5912a15ce033dcd54a4aeb2f6639ee0d0d1816c30a45b
@@ -34,7 +34,7 @@ parser.
34
34
 
35
35
  (The MIT License)
36
36
 
37
- Copyright (c) 2012-2013 Aaron Patterson
37
+ Copyright (c) 2012-2016 Aaron Patterson
38
38
 
39
39
  Permission is hereby granted, free of charge, to any person obtaining
40
40
  a copy of this software and associated documentation files (the
@@ -23,6 +23,7 @@ VALUE cSavepoint;
23
23
  VALUE cBegin;
24
24
  VALUE cRollback;
25
25
  VALUE cCommit;
26
+ VALUE cCompound;
26
27
 
27
28
  #define WrapInteger(klass, type, lname) \
28
29
  static VALUE rb_##klass##_##lname(VALUE self) \
@@ -146,6 +147,8 @@ WrapNode(cJoin, GdaSqlSelectJoin, expr);
146
147
  WrapList(cJoin, GdaSqlSelectJoin, use);
147
148
  WrapInteger(cJoin, GdaSqlSelectJoin, position);
148
149
 
150
+ WrapInteger(cCompound, GdaSqlStatementCompound, compound_type);
151
+
149
152
  WrapList(cUnknown, GdaSqlStatementUnknown, expressions);
150
153
 
151
154
  static VALUE distinct_p(VALUE self)
@@ -236,12 +239,36 @@ VALUE WrapAnyPart(VALUE stmt, GdaSqlAnyPart *part)
236
239
  case GDA_SQL_ANY_SQL_SELECT_JOIN:
237
240
  return Wrap(stmt, cJoin, part);
238
241
  break;
242
+ case GDA_SQL_ANY_STMT_COMPOUND:
243
+ return Wrap(stmt, cCompound, part);
244
+ break;
239
245
  default:
240
246
  rb_raise(rb_eRuntimeError, "unknown node type: %d\n", part->type);
241
247
  return Qnil;
242
248
  }
243
249
  }
244
250
 
251
+
252
+ static VALUE rb_cCompound_stmt_list(VALUE self)
253
+ {
254
+ GdaSqlStatementCompound * st;
255
+ GSList * list;
256
+ VALUE array;
257
+ VALUE stmt;
258
+
259
+ Data_Get_Struct(self, GdaSqlStatementCompound, st);
260
+ stmt = rb_iv_get(self, "stmt");
261
+ array = rb_ary_new();
262
+
263
+ for (list = st->stmt_list; list; list = list->next) {
264
+ GdaSqlStatement *sqlst = (GdaSqlStatement*) list->data;
265
+ VALUE obj = Wrap(stmt, cSelect, GDA_SQL_ANY_PART(sqlst->contents));
266
+ rb_ary_push(array, obj);
267
+ }
268
+ return array;
269
+ }
270
+
271
+
245
272
  static VALUE rb_cInsert_values_list(VALUE self)
246
273
  {
247
274
  GdaSqlStatementInsert * st;
@@ -477,6 +504,10 @@ void Init_gda_nodes()
477
504
  cField = rb_define_class_under(mNodes, "Field", cNode);
478
505
  WrapperMethod(cField, field_name);
479
506
 
507
+ cCompound = rb_define_class_under(mNodes, "Compound", cNode);
508
+ WrapperMethod(cCompound, compound_type);
509
+ WrapperMethod(cCompound, stmt_list);
510
+
480
511
  cBegin = rb_define_class_under(mNodes, "Begin", cNode);
481
512
  cRollback = rb_define_class_under(mNodes, "Rollback", cNode);
482
513
  cCommit = rb_define_class_under(mNodes, "Commit", cNode);
data/lib/gda.rb CHANGED
@@ -4,7 +4,7 @@ require 'gda/visitors/dot'
4
4
  require 'gda/visitors/max_depth'
5
5
 
6
6
  module GDA
7
- VERSION = '1.0.2'
7
+ VERSION = '1.1.0'
8
8
 
9
9
  module SQL
10
10
  class Statement
@@ -94,6 +94,10 @@ module GDA
94
94
  visit node.expressions
95
95
  end
96
96
 
97
+ def visit_GDA_Nodes_Compound node
98
+ visit node.stmt_list
99
+ end
100
+
97
101
  ## Terminal nodes
98
102
  def visit_GDA_Nodes_Table node
99
103
  end
@@ -22,5 +22,10 @@ module GDA
22
22
  stmt = parser.parse 'SELECT * FROM OMG WHERE 1 = 10'
23
23
  assert_operator stmt.ast.to_a.length, :>, 1
24
24
  end
25
+
26
+ def test_not_equal_operator
27
+ stmt = parser.parse 'SELECT id FROM comments WHERE issue_id = 1 AND type <> 3'
28
+ assert stmt.ast.is_a?(GDA::Nodes::Select)
29
+ end
25
30
  end
26
31
  end
@@ -2,6 +2,39 @@ require 'helper'
2
2
 
3
3
  module GDA
4
4
  module SQL
5
+ class TestUnion < TestCase
6
+ attr_reader :parser, :stmt
7
+
8
+ def setup
9
+ @parser = GDA::SQL::Parser.new
10
+ sql = <<-SQL.gsub(/^ */, "")
11
+ SELECT id FROM posts WHERE actor_id = 1 AND actor_type = 1
12
+ UNION
13
+ SELECT id FROM posts WHERE actor_id = 1 AND actor_type = 3
14
+ SQL
15
+
16
+ @stmt = parser.parse(sql)
17
+ end
18
+
19
+ def test_union_query
20
+ assert_equal 2, stmt.ast.stmt_list.count
21
+ assert_equal 0, stmt.ast.compound_type, "should be an UNION type"
22
+ end
23
+
24
+ def test_union_query_visitor
25
+ visitor = Class.new(Visitors::Visitor) do
26
+ attr_reader :selects_count
27
+ def visit_GDA_Nodes_Select(*)
28
+ @selects_count ||= 0
29
+ @selects_count += 1
30
+ end
31
+ end.new
32
+
33
+ visitor.accept stmt.ast
34
+ assert_equal 2, visitor.selects_count
35
+ end
36
+ end
37
+
5
38
  class TestStatement < TestCase
6
39
  attr_reader :parser, :stmt
7
40
 
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gda
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-09 00:00:00.000000000 Z
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: minitest
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '5.8'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '5.8'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rdoc
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -142,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
128
  version: '0'
143
129
  requirements: []
144
130
  rubyforge_project:
145
- rubygems_version: 2.4.5.1
131
+ rubygems_version: 2.2.5
146
132
  signing_key:
147
133
  specification_version: 4
148
134
  summary: An SQL parser