activerecord-jdbc-adapter 1.3.17 → 1.3.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +24 -5
  3. data/History.md +54 -0
  4. data/lib/arel/visitors/compat.rb +30 -2
  5. data/lib/arel/visitors/db2.rb +118 -29
  6. data/lib/arel/visitors/derby.rb +84 -29
  7. data/lib/arel/visitors/firebird.rb +66 -9
  8. data/lib/arel/visitors/h2.rb +16 -0
  9. data/lib/arel/visitors/hsqldb.rb +6 -3
  10. data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
  11. data/lib/arel/visitors/sql_server.rb +121 -40
  12. data/lib/arel/visitors/sql_server/ng42.rb +293 -0
  13. data/lib/arjdbc.rb +1 -7
  14. data/lib/arjdbc/db2.rb +1 -0
  15. data/lib/arjdbc/db2/adapter.rb +118 -18
  16. data/lib/arjdbc/derby/adapter.rb +29 -8
  17. data/lib/arjdbc/firebird.rb +1 -0
  18. data/lib/arjdbc/firebird/adapter.rb +126 -11
  19. data/lib/arjdbc/hsqldb/adapter.rb +3 -0
  20. data/lib/arjdbc/informix.rb +1 -0
  21. data/lib/arjdbc/jdbc.rb +17 -0
  22. data/lib/arjdbc/jdbc/adapter.rb +28 -3
  23. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  24. data/lib/arjdbc/jdbc/column.rb +7 -3
  25. data/lib/arjdbc/jdbc/type_cast.rb +2 -0
  26. data/lib/arjdbc/jdbc/type_converter.rb +28 -15
  27. data/lib/arjdbc/mimer.rb +1 -0
  28. data/lib/arjdbc/mssql.rb +2 -1
  29. data/lib/arjdbc/mssql/adapter.rb +105 -30
  30. data/lib/arjdbc/mssql/column.rb +30 -7
  31. data/lib/arjdbc/mssql/limit_helpers.rb +22 -9
  32. data/lib/arjdbc/mssql/types.rb +343 -0
  33. data/lib/arjdbc/mssql/utils.rb +25 -2
  34. data/lib/arjdbc/mysql/adapter.rb +22 -21
  35. data/lib/arjdbc/oracle.rb +1 -0
  36. data/lib/arjdbc/oracle/adapter.rb +291 -19
  37. data/lib/arjdbc/oracle/column.rb +9 -5
  38. data/lib/arjdbc/oracle/connection_methods.rb +4 -1
  39. data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +21 -0
  40. data/lib/arjdbc/postgresql/adapter.rb +7 -1
  41. data/lib/arjdbc/postgresql/oid/bytea.rb +3 -0
  42. data/lib/arjdbc/postgresql/oid_types.rb +2 -1
  43. data/lib/arjdbc/tasks/database_tasks.rb +3 -0
  44. data/lib/arjdbc/util/quoted_cache.rb +2 -2
  45. data/lib/arjdbc/util/serialized_attributes.rb +11 -0
  46. data/lib/arjdbc/version.rb +1 -1
  47. data/rakelib/02-test.rake +1 -1
  48. data/rakelib/db.rake +3 -1
  49. data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +190 -0
  50. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +259 -61
  51. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +13 -2
  52. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +192 -15
  53. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +10 -2
  54. metadata +9 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 134cda5c81428ddd6306cfbf8de01390845e9332
4
- data.tar.gz: 5b4c2e9e1f691ab3cd0c8df0ab77a06a933bb433
3
+ metadata.gz: 86270ab993887f84a2f2bb4dbbb8826b95c23ca8
4
+ data.tar.gz: 7af7d89826ae8b430395bedbf64af8aeab0a3cfc
5
5
  SHA512:
6
- metadata.gz: bb750f2f8396290b6212c017350c1b9c2f38792122a2214e1c14a2e83e22f35e6d0dab9c808f384421a64d3c11c691d94e2909e5548ccafbc523c7c066cdd7f1
7
- data.tar.gz: 3cc35229994ff2f461fe35ff5e381c461d41d91ab80e51a8e89b054494f21283a9b897488cab748a1efe076abc3f86316939644a1dcfa2a22029a49c409fa800
6
+ metadata.gz: e2c2d95d0620b913bea2f02c5448bb709ed5e6e7033434ca367c011f0d6b6dc55d4b4862f6011fa0371fa9ae88d2396af143fe8b202da2f8ea10fe833c4dcc61
7
+ data.tar.gz: 87d7ffe54e5fe6e44871e85f16af7db741c1fec6cbd37b82dfb235d59cb0ad7f24af9f6074f7368bb613320f4fdfbcb017fa17f23337ba761b11f95dcfe5d112
@@ -3,7 +3,8 @@ sudo: false
3
3
  bundler_args: --without development
4
4
  script: bundle exec rake test_$DB
5
5
  before_script:
6
- - export JRUBY_OPTS="--server" # -Xcompile.invokedynamic=false
6
+ - export JRUBY_OPTS="--server $JRUBY_OPTS" # -Xcompile.invokedynamic=false
7
+ - mysql --version # to see if we're using MySQL or MariaDB
7
8
  before_install:
8
9
  - ((jruby -v | grep 1.8.7) && jruby --1.9 -S gem update --system 2.1.11) || true
9
10
  rvm:
@@ -45,10 +46,28 @@ branches:
45
46
  - /.*-stable$/
46
47
  - /^test-.*/
47
48
  matrix:
48
- allow_failures:
49
- - gemfile: gemfiles/rails42.gemfile
50
- - env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=jdbc
51
- - env: JRUBY_OPTS="--1.9 $JRUBY_OPTS" DB=jdbc PREPARED_STATEMENTS=true
49
+ #allow_failures:
50
+ # - env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=jdbc
51
+ # - env: JRUBY_OPTS="--1.9 $JRUBY_OPTS" DB=jdbc PREPARED_STATEMENTS=true
52
+ include: # testing against MariaDB
53
+ - addons:
54
+ mariadb: '5.5'
55
+ rvm: jruby-1.7.18
56
+ gemfile: gemfiles/rails32.gemfile
57
+ env: JRUBY_OPTS="$JRUBY_OPTS" DB=mysql
58
+ jdk: openjdk7
59
+ - addons:
60
+ mariadb: '10.0'
61
+ rvm: jruby-1.7.18
62
+ gemfile: gemfiles/rails40.gemfile
63
+ env: JRUBY_OPTS="$JRUBY_OPTS" DB=mariadb
64
+ jdk: openjdk7
65
+ - addons:
66
+ mariadb: '10.0'
67
+ rvm: jruby-1.7.18
68
+ gemfile: gemfiles/rails41.gemfile
69
+ env: JRUBY_OPTS="$JRUBY_OPTS" DB=mariadb PREPARED_STATEMENTS=true
70
+ jdk: openjdk7
52
71
  exclude:
53
72
  # Rails 4 prefers Ruby 2.0 (or at least >= 1.9.3) :
54
73
  - rvm: jruby-1.7.18
data/History.md CHANGED
@@ -1,3 +1,57 @@
1
+ ## 1.3.18 (09/14/15)
2
+
3
+ - since arel visitor instances might get re-used we need to avoid the @instance
4
+ - [postgres] work-around BC time parsing issue (on JRuby 1.7.x) by a patch
5
+ - [mssql] fix broken ordering on an aggregate queries (from #646 closing #532)
6
+ - [mssql] default to using a string limit: 4000 with newer AR
7
+ - [mssql] setup type map for SQLServer ... backwards compat as much as possible
8
+ - for better AR alignment on 4.2 shall do the AR type-casting of booleans/dates
9
+ - [mssql] ... port over visitor from sqlserver-adapter (to be used on AR 4.2)
10
+ - [mssql] allow to tune collation equality operator with *cs_equality_operator*
11
+ - [mssql] setup BINARY/TEXT types as binary_basic/text_basic (needed on 4.2)
12
+ - [mssql] setup a NATIVE_DATABASE_TYPES constant (for SQLServer > 2K) (#508)
13
+ - [jdbc] prefer BIT(1) as a better match for :boolean type than TINYINT
14
+ - [mssql] get_table_name bug with unusual queries has been fixed (#583)
15
+ - [mssql] make sure we set @primary on column instances even on AR 4.2
16
+ - [mssql] issue when using joins with distinct (#590) ... fixed with #608
17
+ - [firebird] tune arel visitor (limit/offset handling) to work on AR 4.2
18
+ - [firebird] avoid prefetch_primary_key? depending on column.primary due AR 4.2
19
+ - [firebird] introduce type map on AR 4.2 (not sure about :timestamp handling
20
+ - [firebird] boolean parameter with prepared-statements should be set as CHAR
21
+ - [firebird] standalone column and adapter classes +
22
+ standalone custom (native) JdbcConnection class for firebird due CHAR handling
23
+ - [firebird] handle schema-prefixed table names in default_sequence_name
24
+ - [oracle] support for handling NUMBER(1) type as boolean just like on AR < 4.2
25
+ - [oracle] generic optimized NUMBER type extraction (with scale == 0 as integer)
26
+ - [oracle] support XMLTYPE as a custom type on AR 4.2
27
+ - [oracle] add disable_referential_integrity helper (for the duration of a block)
28
+ - base (adapter: jdbc) foreign_keys support for all (for AR 4.2 compatibility)
29
+ - [oracle] AR 4.2 type map support (ported over from oracle-enhanced adapter)
30
+ - [oracle] avoid error logging optional DROP SEQUENCE on drop_table
31
+ - [oracle] default config[:database] (when not provided) to **XE**
32
+ - [oracle] improved index + primary_key (detection) support not just for AR 4.2
33
+ - [oracle] update default_sequence_name to strip prefix + add trigger name
34
+ - [oracle] set statement_escape_processing: true by default on AR 4.x (#479)
35
+ - handle serialized attributes the AR 4.2 way (serialized_attributes deprecated)
36
+ - [db2] custom type map for AR 4.2 based on IBM_DB gem
37
+ - [db2] support XML as type on AR 4.2
38
+ - type-casting on our native side should now handle AR 4.2 right!
39
+ - jdbc connection should not attempt to type-cast date/time on AR 4.2
40
+ - [db2] arel visitor + handle basic type mapping the AR 4.2 way
41
+ - no longer warn on 4.2 + but still warn with (unsupported) adapters
42
+ - restore Ruby 1.8 (syntax) compatibility - was broken for MySQL/Derby
43
+ - use standard AREL with H2/HSQLDB as H2/HSQLDB support standard LIMIT and OFFSET
44
+ - [h2] working AR 4.2 support
45
+ - [hsqldb] working AR 4.2 support
46
+ - [rake] support adapter: mariadb as if it were mysql (on AR 4.x)
47
+ - [postgres] changes to avoid double cast for AR42 (with prepared statements)
48
+ - [postgres] use standard JDBC bind arguments marker "?" instead of "$n"
49
+ - [postgres] allow reading "infinity" and "BC timestamps on 4.2
50
+ - type cast bind arguments in RubyJdbcConnection (prepared statements)
51
+ - [derby] ActiveRecord 4.2 reports xml columns as XML(2147483647)
52
+ - [derby] working AR 4.2 support
53
+ - support cast_type on the JdbcConnection side for improved AR 4.2 compatibility
54
+
1
55
  ## 1.3.17 (06/30/15)
2
56
 
3
57
  - [mysql] bulk compatibility with AR 4.2 - all _sql helper accept an options (hash)
@@ -22,8 +22,36 @@ module Arel
22
22
 
23
23
  private
24
24
 
25
- def limit_for(limit_or_node)
26
- limit_or_node.respond_to?(:expr) ? limit_or_node.expr.to_i : limit_or_node
25
+ if ArJdbc::AR42
26
+ if Arel::VERSION < '6.0.2'
27
+ def limit_for(limit_or_node)
28
+ if limit_or_node.respond_to?(:expr)
29
+ expr = limit_or_node.expr
30
+ # NOTE(uwe): Different behavior for Arel 6.0.0 and 6.0.2
31
+ expr.respond_to?(:value) ? expr.value.to_i : expr.to_i
32
+ else
33
+ limit_or_node
34
+ end
35
+ end
36
+ else
37
+ def limit_for(limit_or_node)
38
+ limit_or_node.respond_to?(:expr) ? limit_or_node.expr.to_i : limit_or_node
39
+ end
40
+ end
41
+ else
42
+ def limit_for(limit_or_node)
43
+ limit_or_node.respond_to?(:expr) ? limit_or_node.expr.to_i : limit_or_node
44
+ end
45
+ end
46
+ module_function :limit_for
47
+
48
+ def node_value(node)
49
+ return nil unless node
50
+ case expr = node.expr
51
+ when NilClass then nil
52
+ when Numeric then expr
53
+ when Arel::Nodes::Unary then expr.expr
54
+ end
27
55
  end
28
56
 
29
57
  end
@@ -1,48 +1,137 @@
1
+ # NOTE: file contains code adapted from **ruby-ibmdb**'s adapter, license follows
2
+ =begin
3
+ Copyright (c) 2006 - 2015 IBM Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+ =end
11
+
1
12
  require 'arel/visitors/compat'
2
13
 
3
14
  module Arel
4
15
  module Visitors
5
16
  class DB2 < Arel::Visitors::ToSql
6
17
 
7
- def visit_Arel_Nodes_SelectStatement o, a = nil
8
- sql = o.cores.map { |x| do_visit_select_core x, a }.join
9
- sql << " ORDER BY #{o.orders.map { |x| do_visit x, a }.join(', ')}" unless o.orders.empty?
10
- add_limit_offset(sql, o)
18
+ if ArJdbc::AR42
19
+ def visit_Arel_Nodes_SelectStatement(o, a = nil)
20
+ a = o.cores.inject(a) { |c, x| visit_Arel_Nodes_SelectCore(x, c) }
21
+
22
+ unless o.orders.empty?
23
+ a << ' ORDER BY '
24
+ last = o.orders.length - 1
25
+ o.orders.each_with_index do |x, i|
26
+ visit(x, a); a << ', ' unless last == i
27
+ end
28
+ end
29
+
30
+ if limit = o.limit
31
+ if limit = limit.value
32
+ limit = limit.to_i
33
+ end
34
+ end
35
+ if offset = o.offset
36
+ if offset = offset.value
37
+ offset = offset.to_i
38
+ end
39
+ end
40
+
41
+ if limit || offset
42
+ add_limit_offset(a, o, limit, offset)
43
+ else
44
+ a
45
+ end
46
+ end
47
+
48
+ def visit_Arel_Nodes_Limit o, collector
49
+ # visit o.expr, collector
50
+ end
51
+
52
+ def visit_Arel_Nodes_Offset o, collector
53
+ # visit o.expr, collector
54
+ end
55
+
56
+ else
57
+ def visit_Arel_Nodes_SelectStatement o, a = nil
58
+ sql = o.cores.map { |x| do_visit_select_core x, a }.join
59
+ sql << " ORDER BY #{o.orders.map { |x| do_visit x, a }.join(', ')}" unless o.orders.empty?
60
+
61
+ if limit = o.limit
62
+ if limit = limit.value
63
+ limit = limit.to_i
64
+ end
65
+ end
66
+ if offset = o.offset
67
+ if offset = offset.value
68
+ offset = offset.to_i
69
+ end
70
+ end
71
+
72
+ if limit || offset
73
+ add_limit_offset(sql, o, limit, offset)
74
+ else
75
+ sql
76
+ end
77
+ end
11
78
  end
12
79
 
13
- def visit_Arel_Nodes_InsertStatement o, a = nil
14
- sql = "INSERT INTO "
15
- sql << visit(o.relation, a)
16
-
17
- values = o.values
18
-
19
- if o.columns.any?
20
- cols = o.columns.map { |x| quote_column_name x.name }
21
- sql << ' (' << cols.join(', ') << ') '
22
- # should depend the other way around but who cares it's AR
23
- elsif o.values.eql? ArJdbc::DB2::VALUES_DEFAULT
24
- cols = o.relation.engine.columns.map { |c| c.name }
25
- sql << ' (' << cols.join(', ') << ')'
26
- sql << ' VALUES '
27
- sql << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')'
28
- values = nil
80
+ if ArJdbc::AR42
81
+ def visit_Arel_Nodes_InsertStatement o, a = nil
82
+ a << "INSERT INTO "
83
+ visit(o.relation, a)
84
+
85
+ values = o.values
86
+
87
+ if o.columns.any?
88
+ cols = o.columns.map { |x| quote_column_name x.name }
89
+ a << ' (' << cols.join(', ') << ') '
90
+ elsif o.values.eql? ArJdbc::DB2::VALUES_DEFAULT
91
+ cols = o.relation.engine.columns.map { |c| c.name }
92
+ a << ' (' << cols.join(', ') << ')'
93
+ a << ' VALUES '
94
+ a << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')'
95
+ values = false
96
+ end
97
+ visit(values, a) if values
98
+ a
29
99
  end
100
+ elsif Arel::VERSION >= '4.0' # AR 4.0 ... AREL 5.0 since AR >= 4.1
101
+ def visit_Arel_Nodes_InsertStatement o, a = nil
102
+ sql = "INSERT INTO "
103
+ sql << visit(o.relation, a)
30
104
 
31
- sql << visit(values, a) if values
105
+ values = o.values
32
106
 
33
- sql
34
- end if Arel::VERSION >= '4.0' # AR 4.0 ... AREL 5.0 since AR >= 4.1
107
+ if o.columns.any?
108
+ cols = o.columns.map { |x| quote_column_name x.name }
109
+ sql << ' (' << cols.join(', ') << ') '
110
+ # should depend the other way around but who cares it's AR
111
+ elsif o.values.eql? ArJdbc::DB2::VALUES_DEFAULT
112
+ cols = o.relation.engine.columns.map { |c| c.name }
113
+ sql << ' (' << cols.join(', ') << ')'
114
+ sql << ' VALUES '
115
+ sql << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')'
116
+ values = nil
117
+ end
35
118
 
36
- private
119
+ sql << visit(values, a) if values
37
120
 
38
- def add_limit_offset(sql, o)
39
- if o.offset && o.offset.value && o.limit && o.limit.value
40
- @connection.replace_limit_offset_with_ordering! sql, o.limit.value, o.offset.value, o.orders
41
- else
42
- @connection.replace_limit_offset! sql, limit_for(o.limit), o.offset && o.offset.value
121
+ sql
43
122
  end
44
123
  end
45
124
 
125
+ private
126
+
127
+ def add_limit_offset(sql, o, limit, offset)
128
+ @connection.replace_limit_offset! sql, limit, offset, o.orders
129
+ end
130
+
46
131
  end
47
132
  end
48
133
  end
134
+
135
+ Arel::Collectors::Bind.class_eval do
136
+ attr_reader :parts
137
+ end if defined? Arel::Collectors::Bind
@@ -4,21 +4,55 @@ module Arel
4
4
  module Visitors
5
5
  class Derby < Arel::Visitors::ToSql
6
6
 
7
- def visit_Arel_Nodes_SelectStatement o, a = nil
8
- sql = o.cores.map { |x| do_visit(x, a) }.join
9
- sql << " ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?
10
- sql << " #{do_visit o.offset, a}" if o.offset
11
- sql << " #{do_visit o.limit, a}" if o.limit
12
- sql << " #{do_visit o.lock, a}" if o.lock
13
- sql
7
+ # @private
8
+ STR_1 = ' '
9
+
10
+ if ArJdbc::AR42
11
+ def visit_Arel_Nodes_SelectStatement(o, a = nil)
12
+ a = o.cores.inject(a) { |c, x| visit_Arel_Nodes_SelectCore(x, c) }
13
+ unless o.orders.empty?
14
+ a << ' ORDER BY '
15
+ last = o.orders.length - 1
16
+ o.orders.each_with_index do |x, i|
17
+ visit(x, a); a << ', ' unless last == i
18
+ end
19
+ end
20
+ if o.offset
21
+ a << STR_1; visit(o.offset, a)
22
+ end
23
+ if o.limit
24
+ a << STR_1; visit(o.limit, a)
25
+ end
26
+ if o.lock
27
+ a << STR_1; visit(o.lock, a)
28
+ end
29
+ a
30
+ end
31
+ else
32
+ def visit_Arel_Nodes_SelectStatement(o, a = nil)
33
+ sql = o.cores.map { |x| do_visit(x, a) }.join
34
+ sql << " ORDER BY #{o.orders.map { |x| do_visit x, a }.join(', ')}" unless o.orders.empty?
35
+ sql << " #{do_visit o.offset, a}" if o.offset
36
+ sql << " #{do_visit o.limit, a}" if o.limit
37
+ sql << " #{do_visit o.lock, a}" if o.lock
38
+ sql
39
+ end
14
40
  end
15
41
 
16
- def visit_Arel_Nodes_Limit o, a = nil
17
- "FETCH FIRST #{limit_for(o)} ROWS ONLY"
42
+ def visit_Arel_Nodes_Limit(o, a = nil)
43
+ limit = "FETCH FIRST #{limit_for(o)} ROWS ONLY"
44
+ a << limit if a
45
+ limit
18
46
  end
19
47
 
20
- def visit_Arel_Nodes_Offset o, a = nil
21
- "OFFSET #{do_visit o.value, a} ROWS"
48
+ def visit_Arel_Nodes_Offset(o, a = nil)
49
+ if a
50
+ a << 'OFFSET '
51
+ do_visit(o.value, a)
52
+ a << ' ROWS'
53
+ else
54
+ "OFFSET #{do_visit o.value, a} ROWS"
55
+ end
22
56
  end
23
57
 
24
58
  # This generates SELECT...FOR UPDATE, but it will only work if the
@@ -31,27 +65,48 @@ module Arel
31
65
  # @private
32
66
  VALUES_DEFAULT = 'VALUES ( DEFAULT )' # NOTE: marker set by ArJdbc::Derby
33
67
 
34
- def visit_Arel_Nodes_InsertStatement o, a = nil
35
- sql = "INSERT INTO "
36
- sql << visit(o.relation, a)
37
-
38
- values = o.values
39
-
40
- if o.columns.any?
41
- cols = o.columns.map { |x| quote_column_name x.name }
42
- sql << ' (' << cols.join(', ') << ') '
43
- elsif o.values.eql? VALUES_DEFAULT
44
- cols = o.relation.engine.columns.map { |c| c.name }
45
- sql << ' (' << cols.join(', ') << ')'
46
- sql << ' VALUES '
47
- sql << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')'
48
- values = false
68
+ if ArJdbc::AR42
69
+ def visit_Arel_Nodes_InsertStatement o, a = nil
70
+ a << "INSERT INTO "
71
+ visit(o.relation, a)
72
+
73
+ values = o.values
74
+
75
+ if o.columns.any?
76
+ cols = o.columns.map { |x| quote_column_name x.name }
77
+ a << ' (' << cols.join(', ') << ') '
78
+ elsif o.values.eql? VALUES_DEFAULT
79
+ cols = o.relation.engine.columns.map { |c| c.name }
80
+ a << ' (' << cols.join(', ') << ')'
81
+ a << ' VALUES '
82
+ a << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')'
83
+ values = false
84
+ end
85
+ visit(values, a) if values
86
+ a
49
87
  end
88
+ elsif Arel::VERSION >= '4.0' # AR 4.0 ... AREL 5.0 since AR >= 4.1
89
+ def visit_Arel_Nodes_InsertStatement o, a = nil
90
+ sql = 'INSERT INTO '
91
+ sql << visit(o.relation, a)
92
+
93
+ values = o.values
50
94
 
51
- sql << visit(values, a) if values
52
- sql
53
- end if Arel::VERSION >= '4.0' # AR 4.0 ... AREL 5.0 since AR >= 4.1
95
+ if o.columns.any?
96
+ cols = o.columns.map { |x| quote_column_name x.name }
97
+ sql << ' (' << cols.join(', ') << ') '
98
+ elsif o.values.eql? VALUES_DEFAULT
99
+ cols = o.relation.engine.columns.map { |c| c.name }
100
+ sql << ' (' << cols.join(', ') << ')'
101
+ sql << ' VALUES '
102
+ sql << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')'
103
+ values = false
104
+ end
54
105
 
106
+ sql << visit(values, a) if values
107
+ sql
108
+ end
109
+ end
55
110
  end
56
111
  end
57
112
  end