activerecord-jdbc-adapter 1.3.7 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +33 -3
  3. data/Appraisals +11 -5
  4. data/Gemfile +21 -15
  5. data/History.md +31 -1
  6. data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
  7. data/lib/arel/visitors/firebird.rb +7 -10
  8. data/lib/arel/visitors/h2.rb +9 -0
  9. data/lib/arel/visitors/sql_server.rb +21 -2
  10. data/lib/arjdbc/h2/adapter.rb +31 -2
  11. data/lib/arjdbc/h2/connection_methods.rb +1 -1
  12. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  13. data/lib/arjdbc/jdbc/column.rb +2 -1
  14. data/lib/arjdbc/mssql/adapter.rb +40 -23
  15. data/lib/arjdbc/mssql/column.rb +4 -4
  16. data/lib/arjdbc/mysql/adapter.rb +36 -10
  17. data/lib/arjdbc/mysql/column.rb +12 -7
  18. data/lib/arjdbc/mysql/connection_methods.rb +53 -21
  19. data/lib/arjdbc/oracle/adapter.rb +22 -5
  20. data/lib/arjdbc/postgresql/adapter.rb +54 -18
  21. data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
  22. data/lib/arjdbc/postgresql/base/oid.rb +460 -0
  23. data/lib/arjdbc/postgresql/column.rb +50 -15
  24. data/lib/arjdbc/postgresql/oid_types.rb +126 -0
  25. data/lib/arjdbc/tasks/h2_database_tasks.rb +4 -2
  26. data/lib/arjdbc/version.rb +1 -1
  27. data/rakelib/02-test.rake +3 -30
  28. data/src/java/arjdbc/derby/DerbyModule.java +0 -8
  29. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +1 -0
  30. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +2 -0
  31. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +8 -8
  32. data/src/java/arjdbc/mssql/MSSQLModule.java +50 -19
  33. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +1 -0
  34. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +6 -6
  35. data/src/java/arjdbc/oracle/OracleModule.java +1 -1
  36. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +66 -2
  37. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +23 -10
  38. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +1 -0
  39. data/src/java/arjdbc/util/CallResultSet.java +826 -0
  40. data/src/java/arjdbc/util/QuotingUtils.java +14 -7
  41. metadata +8 -3
  42. data/lib/arjdbc/postgresql/array_parser.rb +0 -89
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23a7dd04ff60809e25a4e3353934e7333eb95f85
4
- data.tar.gz: 5e5f2405ab90b8162afb541ca07149b1c1905359
3
+ metadata.gz: bdd070e64ed269bffd40cf0a8664f09964f771d5
4
+ data.tar.gz: 1e14ca7c497d7bddb3bbdca2bcfa4da04acfebcf
5
5
  SHA512:
6
- metadata.gz: 2f7e7f103b585be60afc053e89c60f4826409740b8a223380292ab57dd4d141a22e7ac2974b2c4c9b06e6ddb2f5971e32c5a01a20d73fc011f227adc5086322a
7
- data.tar.gz: bd7e172e76bb7e2f492f4735124361060a5ddde25f036a67d80d9422e6b69d793ce270e19c33ddf74f659b820aa85eb4ea62c346ad9ddcbb104c4ac45cd84a34
6
+ metadata.gz: 19d45b4f7f4edcace3341a1641b24ee7e3e98bb8e2f7a4853cfa9cc6877eeffbbc5e56f86e2f98e37c9df6af3a85a0afa02a346f381498a87e71d36ddffa3eae
7
+ data.tar.gz: 349a9d32b318d73fc0f549a81c2dc5d38367629e1694597e47efae4aeea2ff6ca70e1f07cb750d453955781378f021149a2ae46994b111667db66d39a3a5f87c
@@ -13,6 +13,7 @@ gemfile:
13
13
  - gemfiles/rails32.gemfile
14
14
  - gemfiles/rails40.gemfile
15
15
  - gemfiles/rails41.gemfile
16
+ - gemfiles/rails42.gemfile
16
17
  env:
17
18
  - JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=mysql
18
19
  - JRUBY_OPTS="--1.9 $JRUBY_OPTS" DB=mysql PREPARED_STATEMENTS=false
@@ -34,13 +35,17 @@ env:
34
35
  # TODO: not sure why it can't connect :
35
36
  #- JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=jdbc
36
37
  #- JRUBY_OPTS="--1.9 $JRUBY_OPTS" DB=jdbc
38
+ jdk:
39
+ - openjdk6
37
40
  branches:
38
41
  only:
39
42
  - master
40
- - 1-2-stable
43
+ - /.*-stable$/
44
+ - next
45
+ - /^test-.*/
41
46
  matrix:
42
- #allow_failures:
43
- #- gemfile: gemfiles/rails41.gemfile
47
+ allow_failures:
48
+ - gemfile: gemfiles/rails42.gemfile
44
49
  exclude:
45
50
  # Rails 4 prefers Ruby 2.0 (or at least >= 1.9.3) :
46
51
  - rvm: jruby
@@ -92,3 +97,28 @@ matrix:
92
97
  - rvm: jruby
93
98
  gemfile: gemfiles/rails41.gemfile
94
99
  env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=jdbc
100
+ # Rails 4.2 will not support Ruby 1.8 :
101
+ - rvm: jruby
102
+ gemfile: gemfiles/rails42.gemfile
103
+ env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=mysql
104
+ - rvm: jruby
105
+ gemfile: gemfiles/rails42.gemfile
106
+ env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=postgresql
107
+ - rvm: jruby
108
+ gemfile: gemfiles/rails42.gemfile
109
+ env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=sqlite3
110
+ - rvm: jruby
111
+ gemfile: gemfiles/rails42.gemfile
112
+ env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=derby
113
+ - rvm: jruby
114
+ gemfile: gemfiles/rails42.gemfile
115
+ env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=h2
116
+ - rvm: jruby
117
+ gemfile: gemfiles/rails42.gemfile
118
+ env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=hsqldb
119
+ - rvm: jruby
120
+ gemfile: gemfiles/rails42.gemfile
121
+ env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=jndi
122
+ - rvm: jruby
123
+ gemfile: gemfiles/rails42.gemfile
124
+ env: JRUBY_OPTS="--1.8 $JRUBY_OPTS" DB=jdbc
data/Appraisals CHANGED
@@ -12,20 +12,26 @@ appraise "rails31" do
12
12
  end
13
13
 
14
14
  appraise "rails32" do
15
- gem "activerecord", "~> 3.2.17", :require => false
15
+ gem "activerecord", "~> 3.2.18", :require => false
16
16
  end
17
17
 
18
18
  appraise "rails40" do
19
19
  # NOTE: make sure you're using --1.9 with AR-4.0
20
- gem "activerecord", "~> 4.0.4", :require => false
20
+ gem "activerecord", "~> 4.0.6", :require => false
21
21
  end
22
22
 
23
23
  appraise "rails41" do
24
- # NOTE: make sure you're using --1.9 with AR-4.1
25
- if branch = ENV['rails_branch']
24
+ # NOTE: make sure you're using --1.9 with AR-4.0
25
+ gem "activerecord", "~> 4.1.2", :require => false
26
+ end
27
+
28
+ appraise "rails42" do
29
+ # NOTE: make sure you're using --1.9 with AR-4.0
30
+ if branch = ( ENV['rails_branch'] || 'master' )
26
31
  gem "activerecord", :github => 'rails/rails', :branch => branch, :require => false
27
32
  gem 'rails', :github => 'rails/rails', :branch => branch
33
+ gem 'arel', :github => 'rails/arel', :branch => 'master'
28
34
  else
29
- gem "activerecord", '4.1.0.rc1', :require => false
35
+ # gem "activerecord", '4.2.0.rc1', :require => false
30
36
  end
31
37
  end
data/Gemfile CHANGED
@@ -1,29 +1,26 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  if version = ENV['AR_VERSION']
4
- gem 'activerecord', version, :require => nil
4
+ if version.index('/') && ::File.exist?(version)
5
+ gem 'activerecord', :path => version
6
+ elsif version =~ /^[0-9abcdef]+$/
7
+ gem 'activerecord', :github => 'rails/rails', :ref => version
8
+ elsif version.index('.').nil?
9
+ gem 'activerecord', :github => 'rails/rails', :branch => version
10
+ else
11
+ gem 'activerecord', version, :require => nil
12
+ end
5
13
  else
6
14
  gem 'activerecord', :require => nil
7
15
  end
16
+
8
17
  gem 'thread_safe', :require => nil # "optional" - we can roll without it
18
+
9
19
  if defined?(JRUBY_VERSION) && JRUBY_VERSION < '1.7.0'
10
20
  gem 'jruby-openssl', :platform => :jruby
11
21
  end
12
22
 
13
- group :development do
14
- gem 'ruby-debug', :require => nil # if ENV['DEBUG']
15
- group :doc do
16
- gem 'yard', :require => nil
17
- gem 'yard-method-overrides', :github => 'kares/yard-method-overrides', :require => nil
18
- gem 'kramdown', :require => nil
19
- end
20
- end
21
-
22
- if RUBY_VERSION < '1.9'
23
- gem 'rake', '< 10.2.0', :require => nil
24
- else
25
- gem 'rake', :require => nil
26
- end
23
+ gem 'rake', '~> 10.3.2', :require => nil
27
24
  gem 'appraisal', '~> 0.5.2', :require => nil
28
25
 
29
26
  # appraisal ignores group block declarations :
@@ -36,6 +33,15 @@ gem 'simplecov', :require => nil, :group => :test
36
33
  gem 'bcrypt-ruby', '~> 3.0.0', :require => nil, :group => :test
37
34
  #gem 'trinidad_dbpool', :require => nil, :group => :test
38
35
 
36
+ group :development do
37
+ gem 'ruby-debug', :require => nil # if ENV['DEBUG']
38
+ group :doc do
39
+ gem 'yard', :require => nil
40
+ gem 'yard-method-overrides', :github => 'kares/yard-method-overrides', :require => nil
41
+ gem 'kramdown', :require => nil
42
+ end
43
+ end
44
+
39
45
  group :rails do
40
46
  gem 'erubis', :require => nil
41
47
  # NOTE: due rails/activerecord/test/cases/session_store/session_test.rb
data/History.md CHANGED
@@ -1,3 +1,33 @@
1
+ ## 1.3.8 (06/27/14)
2
+
3
+ - [mysql] updated so that we can run with non-official driver (+ against MariaDB)
4
+ - [postgres] quote fix failure with ColumnDefinition on AR 4.0.6.rc2
5
+ - [mssql] performance improvements :
6
+ * "optimized" quote_name_part in Java + avoid bytes copying in quoteCharWith
7
+ * throwing exceptions in the hot path results in slow code
8
+ * minor performance improvements to mssql type_cast
9
+ - [mssql] fix remove_column on AR < 3.2
10
+ - [mssql] dealing with column that need quoting (e.g. ids with spaces) in ORDER
11
+ special care needs to be performed on AR <= 3.2 - Arel < '4.0' (closing #551)
12
+ - [mssql] correct default value quoting + update on change when non null with default
13
+ - [mssql] backport database ('.' in name) quoting fix from sqlserver adapter
14
+ - get the "correct" (AR::Base) record.class on AR 4.1 (#555)
15
+ - [oracle] support disabling generated keys `-Darjdbc.oracle.generated_keys=false`
16
+ - [postgres] fix returning generated keys + use *arjdbc.postgresql.generated_keys*
17
+ - [oracle] working `config[:insert_returning] = true` support (using prepared calls)
18
+ - [mysql] improve column instantiation - make sure strict/extra passed correctly
19
+ - [postgres] backport rails fix for not quoting array defaults correctly
20
+ - [postgres] handle the accessor (e.g. for hstore) added in AR 4.1 (#535)
21
+ - [postgres] handle oid_types resolution on AR 4.x (compat with MRI on Rails)
22
+ - [postgres] align Column's (string) cast helpers with AR 4.1
23
+ - [postgres] quote/cast compat with 4.x + do not quote default function values
24
+ - [postgres] align array parser with latest from AR 4.1
25
+ - [postgresl] Column AR 4.x compatibility methods: `number?` and `text?`
26
+ - [h2] should have it's own arel visitor class (`Arel::Visitors::H2`)
27
+ - [h2] support for latest beta of next major release - H2 database **1.4**
28
+
29
+ Code Contributors (in no particular order): Michael J. Cohen
30
+
1
31
  ## 1.3.7 (04/14/14)
2
32
 
3
33
  - [postgres] set prepared values with array columns on AR < 4.0 correctly
@@ -14,7 +44,7 @@
14
44
  - FireBird's DB meta-identifier is 31 chars maximum, thanks @mariuz (#538)
15
45
  - [derby] add emulate booleans option for derby adapter
16
46
 
17
- Code Contributors (in no particular order): mark100net, Pierrick Rouxel, @iaddict
47
+ Code Contributors (in no particular order): Mark Fraser, Pierrick Rouxel, @iaddict
18
48
 
19
49
  ## 1.3.6 (02/04/14)
20
50
 
@@ -0,0 +1 @@
1
+ require 'arjdbc/mysql'
@@ -5,18 +5,15 @@ module Arel
5
5
  class Firebird < Arel::Visitors::ToSql
6
6
 
7
7
  def visit_Arel_Nodes_SelectStatement o, a = nil
8
- lim_off = [
9
- ("FIRST #{do_visit o.limit.expr, a}" if o.limit),
10
- ("SKIP #{do_visit o.offset.expr, a}" if o.offset)
11
- ].compact.join(' ').strip
8
+ lim_off = ''
9
+ lim_off << "FIRST #{do_visit o.limit.expr, a} " if o.limit
10
+ lim_off << " SKIP #{do_visit o.offset.expr, a}" if o.offset
11
+ lim_off.strip!
12
12
 
13
- sql = [
14
- o.cores.map { |x| do_visit_select_core x, a }.join,
15
- ("ORDER BY #{o.orders.map { |x| do_visit x, a }.join(', ')}" unless o.orders.empty?),
16
- ].compact.join ' '
17
-
18
- sql.sub!(/\A(\s*SELECT\s)/i, '\&' + lim_off + ' ') unless lim_off.empty?
13
+ sql = o.cores.map { |x| do_visit_select_core x, a }.join
14
+ sql << " ORDER BY #{o.orders.map { |x| do_visit x, a }.join(', ')}" unless o.orders.empty?
19
15
 
16
+ sql.sub!(/\A(\s*SELECT\s)/i, "\&#{lim_off} ") unless lim_off.empty?
20
17
  sql
21
18
  end
22
19
 
@@ -0,0 +1,9 @@
1
+ require 'arel/visitors/compat'
2
+ require 'arel/visitors/hsqldb'
3
+
4
+ module Arel
5
+ module Visitors
6
+ class H2 < Arel::Visitors::HSQLDB
7
+ end
8
+ end
9
+ end
@@ -15,7 +15,7 @@ module Arel
15
15
  end
16
16
 
17
17
  unless o.orders.empty?
18
- select_order_by = "ORDER BY #{o.orders.map { |x| do_visit x, a }.join(', ')}"
18
+ select_order_by = "ORDER BY #{do_visit_columns(o.orders, a).join(', ')}"
19
19
  end
20
20
 
21
21
  select_count = false
@@ -95,13 +95,32 @@ module Arel
95
95
 
96
96
  def determine_order_by x, a
97
97
  unless x.groups.empty?
98
- "ORDER BY #{x.groups.map { |g| do_visit g, a }.join(', ')}"
98
+ "ORDER BY #{do_visit_columns(x.groups, a).join(', ')}"
99
99
  else
100
100
  table_pk = find_left_table_pk(x.froms, a)
101
101
  table_pk == 'NULL' ? nil : "ORDER BY #{table_pk}"
102
102
  end
103
103
  end
104
104
 
105
+ def do_visit_columns(colls, a)
106
+ colls.map { |x| do_visit x, a }
107
+ end
108
+
109
+ # @private
110
+ NON_SIMPLE_ORDER_COLUMN = /\sASC|\sDESC|\sCASE|\sCOLLATE|[\.,\[\(]/i # MIN(width)
111
+
112
+ def do_visit_columns(colls, a)
113
+ colls = colls.map { |x| do_visit x, a }
114
+ colls.map! do |x|
115
+ if x !~ NON_SIMPLE_ORDER_COLUMN && x.to_i == 0
116
+ @connection.quote_column_name(x)
117
+ else
118
+ x
119
+ end
120
+ end
121
+ colls
122
+ end if Arel::VERSION < '4.0.0'
123
+
105
124
  def row_num_literal order_by
106
125
  Arel::Nodes::SqlLiteral.new("ROW_NUMBER() OVER (#{order_by}) as _row_num")
107
126
  end
@@ -74,7 +74,7 @@ module ArJdbc
74
74
 
75
75
  # @see ActiveRecord::ConnectionAdapters::Jdbc::ArelSupport
76
76
  def self.arel_visitor_type(config = nil)
77
- HSQLDB.arel_visitor_type(config)
77
+ require 'arel/visitors/h2'; ::Arel::Visitors::H2
78
78
  end
79
79
 
80
80
  ADAPTER_NAME = 'H2'.freeze
@@ -242,6 +242,35 @@ module ArJdbc
242
242
  execute('DROP ALL OBJECTS')
243
243
  end
244
244
 
245
+ # @private
246
+ def database_path(base_only = false)
247
+ db_path = jdbc_connection(true).getSession.getDataHandler.getDatabasePath
248
+ return db_path if base_only
249
+ if File.exist?(mv_path = "#{db_path}.mv.db")
250
+ return mv_path
251
+ else
252
+ "#{db_path}.h2.db"
253
+ end
254
+ end
255
+
256
+ # @override
257
+ def jdbc_connection(unwrap = nil)
258
+ java_connection = raw_connection.connection
259
+ return java_connection unless unwrap
260
+ if java_connection.java_class.name == 'org.h2.jdbc.JdbcConnection'
261
+ return java_connection
262
+ end
263
+ connection_class = java.sql.Connection.java_class
264
+ if java_connection.wrapper_for?(connection_class)
265
+ java_connection.unwrap(connection_class) # java.sql.Wrapper.unwrap
266
+ elsif java_connection.respond_to?(:connection)
267
+ # e.g. org.apache.tomcat.jdbc.pool.PooledConnection
268
+ java_connection.connection # getConnection
269
+ else
270
+ java_connection
271
+ end
272
+ end
273
+
245
274
  private
246
275
 
247
276
  def change_column_null(table_name, column_name, null, default = nil)
@@ -267,5 +296,5 @@ module ActiveRecord::ConnectionAdapters
267
296
  class H2Adapter < JdbcAdapter
268
297
  include ArJdbc::H2
269
298
  end
270
-
299
+
271
300
  end
@@ -16,7 +16,7 @@ ArJdbc::ConnectionMethods.module_eval do
16
16
  if db[0, 4] == 'mem:' || db[0, 5] == 'file:' || db[0, 5] == 'hsql:'
17
17
  "jdbc:h2:#{db}"
18
18
  else
19
- "jdbc:h2:file:#{db}"
19
+ "jdbc:h2:file:#{File.expand_path(db)}"
20
20
  end
21
21
  end
22
22
  config[:driver] ||= defined?(::Jdbc::H2.driver_name) ? ::Jdbc::H2.driver_name : 'org.h2.Driver'
@@ -21,7 +21,8 @@ module ActiveRecord
21
21
  default = args.shift
22
22
  end
23
23
  end
24
- # super : (name, default, sql_type = nil, null = true)
24
+ # super <= 4.1: (name, default, sql_type = nil, null = true)
25
+ # super master: (name, default, cast_type, sql_type = nil, null = true)
25
26
  super(name, default_value(default), *args)
26
27
  init_column(name, default, *args)
27
28
  end
@@ -220,9 +220,22 @@ module ArJdbc
220
220
  end
221
221
 
222
222
  def quote_column_name(name)
223
- name.to_s.split('.').map do |n| # "[#{name}]"
224
- n =~ /^\[.*\]$/ ? n : "[#{n.gsub(']', ']]')}]"
225
- end.join('.')
223
+ name = name.to_s.split('.')
224
+ name.map! { |n| quote_name_part(n) } # "[#{name}]"
225
+ name.join('.')
226
+ end
227
+
228
+ def quote_database_name(name)
229
+ quote_name_part(name.to_s)
230
+ end
231
+
232
+ # Does not quote function default values for UUID columns
233
+ def quote_default_value(value, column)
234
+ if column.type == :uuid && value =~ /\(\)/
235
+ value
236
+ else
237
+ quote(value)
238
+ end
226
239
  end
227
240
 
228
241
  ADAPTER_NAME = 'MSSQL'.freeze
@@ -303,7 +316,7 @@ module ArJdbc
303
316
 
304
317
  def use_database(database = nil)
305
318
  database ||= config[:database]
306
- execute "USE #{quote_table_name(database)}" unless database.blank?
319
+ execute "USE #{quote_database_name(database)}" unless database.blank?
307
320
  end
308
321
 
309
322
  # @private
@@ -326,11 +339,11 @@ module ArJdbc
326
339
  def drop_database(name)
327
340
  current_db = current_database
328
341
  use_database('master') if current_db.to_s == name
329
- execute "DROP DATABASE #{quote_table_name(name)}"
342
+ execute "DROP DATABASE #{quote_database_name(name)}"
330
343
  end
331
344
 
332
345
  def create_database(name, options = {})
333
- execute "CREATE DATABASE #{quote_table_name(name)}"
346
+ execute "CREATE DATABASE #{quote_database_name(name)}"
334
347
  end
335
348
 
336
349
  def database_exists?(name)
@@ -388,38 +401,43 @@ module ArJdbc
388
401
 
389
402
  # @override
390
403
  def change_column(table_name, column_name, type, options = {})
404
+ column = columns(table_name).find { |c| c.name.to_s == column_name.to_s }
391
405
 
392
- indexes = []
393
- column_object = columns(table_name).detect { |c| c.name.to_s == column_name.to_s }
394
-
395
- if options_include_default?(options) || (column_object && column_object.type != type.to_sym)
406
+ indexes = EMPTY_ARRAY
407
+ if options_include_default?(options) || (column && column.type != type.to_sym)
396
408
  remove_default_constraint(table_name, column_name)
397
409
  indexes = indexes(table_name).select{ |index| index.columns.include?(column_name.to_s) }
398
410
  remove_indexes(table_name, column_name)
399
411
  end
400
412
 
401
- clear_cached_table(table_name)
413
+ if ! options[:null].nil? && options[:null] == false && ! options[:default].nil?
414
+ execute "UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote_default_value(options[:default], column)} WHERE #{quote_column_name(column_name)} IS NULL"
415
+ clear_cached_table(table_name)
416
+ end
402
417
  change_column_type(table_name, column_name, type, options)
403
418
  change_column_default(table_name, column_name, options[:default]) if options_include_default?(options)
404
419
 
405
- #Add any removed indexes back
406
- indexes.each do |index|
407
- execute "CREATE INDEX #{quote_table_name(index.name)} ON #{quote_table_name(table_name)} (#{index.columns.collect {|c|quote_column_name(c)}.join(', ')})"
420
+ indexes.each do |index| # add any removed indexes back
421
+ index_columns = index.columns.map { |c| quote_column_name(c) }.join(', ')
422
+ execute "CREATE INDEX #{quote_table_name(index.name)} ON #{quote_table_name(table_name)} (#{index_columns})"
408
423
  end
409
424
  end
410
425
 
411
426
  def change_column_type(table_name, column_name, type, options = {})
412
- clear_cached_table(table_name)
413
427
  sql = "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
414
- sql += (options[:null] ? " NULL" : " NOT NULL") if options.has_key?(:null)
415
- execute(sql)
428
+ sql << (options[:null] ? " NULL" : " NOT NULL") if options.has_key?(:null)
429
+ result = execute(sql)
430
+ clear_cached_table(table_name)
431
+ result
416
432
  end
417
433
 
418
434
  def change_column_default(table_name, column_name, default)
419
- clear_cached_table(table_name)
420
435
  remove_default_constraint(table_name, column_name)
421
436
  unless default.nil?
422
- execute "ALTER TABLE #{quote_table_name(table_name)} ADD CONSTRAINT DF_#{table_name}_#{column_name} DEFAULT #{quote(default)} FOR #{quote_column_name(column_name)}"
437
+ column = columns(table_name).find { |c| c.name.to_s == column_name.to_s }
438
+ result = execute "ALTER TABLE #{quote_table_name(table_name)} ADD CONSTRAINT DF_#{table_name}_#{column_name} DEFAULT #{quote_default_value(default, column)} FOR #{quote_column_name(column_name)}"
439
+ clear_cached_table(table_name)
440
+ result
423
441
  end
424
442
  end
425
443
 
@@ -428,10 +446,9 @@ module ArJdbc
428
446
  # remove_columns(:posts, :foo, :bar) old syntax : remove_columns(:posts, [:foo, :bar])
429
447
  clear_cached_table(table_name)
430
448
 
449
+ column_names = column_names.flatten
431
450
  return do_remove_column(table_name, column_names.first) if column_names.size == 1
432
- column_names.flatten.each do |column_name|
433
- do_remove_column(table_name, column_name)
434
- end
451
+ column_names.each { |column_name| do_remove_column(table_name, column_name) }
435
452
  end
436
453
 
437
454
  def do_remove_column(table_name, column_name)
@@ -569,7 +586,7 @@ module ArJdbc
569
586
  raise "no columns for table: #{table_name}" if columns.empty?
570
587
  end
571
588
  # NOTE: if still no PK column simply get something for ORDER BY ...
572
- "#{table_name}.#{(primary_column || columns.first).name}"
589
+ "#{quote_table_name(table_name)}.#{quote_column_name((primary_column || columns.first).name)}"
573
590
  end
574
591
 
575
592
  # Support for executing a stored procedure.