activerecord-jdbc-adapter 0.9.6-java → 0.9.7-java

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,15 @@
1
+ == 0.9.7
2
+
3
+ - JRUBY-4781: Fix multiple database connection collision issue w/
4
+ Oracle
5
+ - ACTIVERECORD_JDBC-115: Support SAVEPOINTS for MySQL and PG so that
6
+ nested transactions can be faked
7
+ - ACTIVERECORD_JDBC-116: Handle schema.table better for MySQL (thanks
8
+ Dilshod Mukhtarov)
9
+ - Fix 'Wrong # of arguments (2 for 1)' issue with #create_database for
10
+ MySQL and AR 3.0
11
+ - SQLServer 2000 support (thanks Jay McGaffigan)
12
+
1
13
  == 0.9.6
2
14
 
3
15
  - The Oracle release!
@@ -74,7 +74,9 @@ module JdbcSpec
74
74
  alias :#{meth}_pre_pk :#{meth}
75
75
  def #{meth}(include_primary_key = true, *args) #:nodoc:
76
76
  aq = #{meth}_pre_pk(include_primary_key, *args)
77
- aq[#{pk_hash_key}] = #{pk_hash_value} if include_primary_key && aq[#{pk_hash_key}].nil?
77
+ if connection.is_a?(JdbcSpec::Oracle) || connection.is_a?(JdbcSpec::Mimer)
78
+ aq[#{pk_hash_key}] = #{pk_hash_value} if include_primary_key && aq[#{pk_hash_key}].nil?
79
+ end
78
80
  aq
79
81
  end
80
82
  }
@@ -16,7 +16,7 @@ module ::JdbcSpec
16
16
  end
17
17
 
18
18
  module MsSQL
19
-
19
+
20
20
  include TSqlMethods
21
21
 
22
22
  def self.extended(mod)
@@ -36,6 +36,7 @@ module ::JdbcSpec
36
36
  ActiveRecord::Base.after_save :after_save_with_mssql_lob
37
37
  @lob_callback_added = true
38
38
  end
39
+ mod.add_version_specific_add_limit_offset
39
40
  end
40
41
 
41
42
  def self.adapter_matcher(name, *)
@@ -50,15 +51,30 @@ module ::JdbcSpec
50
51
  ::ActiveRecord::ConnectionAdapters::MssqlJdbcConnection
51
52
  end
52
53
 
54
+ def sqlserver_version
55
+ @sqlserver_version ||= select_value("select @@version")[/Microsoft SQL Server\s+(\d{4})/, 1]
56
+ end
57
+
58
+ def add_version_specific_add_limit_offset
59
+ if sqlserver_version == "2000"
60
+ extend SqlServer2000LimitOffset
61
+ else
62
+ extend SqlServerLimitOffset
63
+ end
64
+ end
65
+
53
66
  def modify_types(tp) #:nodoc:
54
67
  super(tp)
55
68
  tp[:string] = {:name => "NVARCHAR", :limit => 255}
56
- tp[:text] = {:name => "NVARCHAR(MAX)"}
69
+ if sqlserver_version == "2000"
70
+ tp[:text] = {:name => "NTEXT"}
71
+ else
72
+ tp[:text] = {:name => "NVARCHAR(MAX)"}
73
+ end
57
74
  tp
58
75
  end
59
-
76
+
60
77
  module Column
61
-
62
78
  attr_accessor :identity, :is_special
63
79
 
64
80
  def simplified_type(field_type)
@@ -82,7 +98,7 @@ module ::JdbcSpec
82
98
  return $1 if value =~ /^\(N?'(.*)'\)$/
83
99
  value
84
100
  end
85
-
101
+
86
102
  def type_cast(value)
87
103
  return nil if value.nil? || value == "(null)" || value == "(NULL)"
88
104
  case type
@@ -97,7 +113,7 @@ module ::JdbcSpec
97
113
  when :binary then unquote value
98
114
  else value
99
115
  end
100
-
116
+
101
117
  end
102
118
 
103
119
  def is_utf8?
@@ -139,7 +155,7 @@ module ::JdbcSpec
139
155
  def self.string_to_binary(value)
140
156
  ''
141
157
  end
142
-
158
+
143
159
  end
144
160
 
145
161
  def quote(value, column = nil)
@@ -184,19 +200,52 @@ module ::JdbcSpec
184
200
  quote false
185
201
  end
186
202
 
187
- def add_limit_offset!(sql, options)
188
- limit = options[:limit]
189
- if limit
190
- offset = (options[:offset] || 0).to_i
191
- start_row = offset + 1
192
- end_row = offset + limit.to_i
193
- order = (options[:order] || determine_order_clause(sql))
194
- sql.sub!(/ ORDER BY.*$/i, '')
195
- find_select = /\b(SELECT(?:\s+DISTINCT)?)\b(.*)/i
196
- whole, select, rest_of_query = find_select.match(sql).to_a
197
- new_sql = "#{select} t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY #{order}) AS row_num, #{rest_of_query}"
198
- new_sql << ") AS t WHERE t.row_num BETWEEN #{start_row.to_s} AND #{end_row.to_s}"
199
- sql.replace(new_sql)
203
+ module SqlServer2000LimitOffset
204
+ def add_limit_offset!(sql, options)
205
+ limit = options[:limit]
206
+ if limit
207
+ offset = (options[:offset] || 0).to_i
208
+ start_row = offset + 1
209
+ end_row = offset + limit.to_i
210
+ order = (options[:order] || determine_order_clause(sql))
211
+ sql.sub!(/ ORDER BY.*$/i, '')
212
+ find_select = /\b(SELECT(?:\s+DISTINCT)?)\b(.*)/i
213
+ whole, select, rest_of_query = find_select.match(sql).to_a
214
+ if (start_row == 1) && (end_row ==1)
215
+ new_sql = "#{select} TOP 1 #{rest_of_query}"
216
+ sql.replace(new_sql)
217
+ else
218
+ #UGLY
219
+ #KLUDGY?
220
+ #removing out stuff before the FROM...
221
+ rest = rest_of_query[/FROM/i=~ rest_of_query.. -1]
222
+ #need the table name for avoiding amiguity
223
+ table_name = get_table_name(sql)
224
+ #I am not sure this will cover all bases. but all the tests pass
225
+ new_order = "#{order}, #{table_name}.id" if order.index("#{table_name}.id").nil?
226
+ new_order ||= order
227
+ new_sql = "#{select} TOP #{limit} #{rest_of_query} WHERE #{table_name}.id NOT IN (#{select} TOP #{offset} #{table_name}.id #{rest} ORDER BY #{new_order}) ORDER BY #{order} "
228
+ sql.replace(new_sql)
229
+ end
230
+ end
231
+ end
232
+ end
233
+
234
+ module SqlServerLimitOffset
235
+ def add_limit_offset!(sql, options)
236
+ limit = options[:limit]
237
+ if limit
238
+ offset = (options[:offset] || 0).to_i
239
+ start_row = offset + 1
240
+ end_row = offset + limit.to_i
241
+ order = (options[:order] || determine_order_clause(sql))
242
+ sql.sub!(/ ORDER BY.*$/i, '')
243
+ find_select = /\b(SELECT(?:\s+DISTINCT)?)\b(.*)/i
244
+ whole, select, rest_of_query = find_select.match(sql).to_a
245
+ new_sql = "#{select} t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY #{order}) AS row_num, #{rest_of_query}"
246
+ new_sql << ") AS t WHERE t.row_num BETWEEN #{start_row.to_s} AND #{end_row.to_s}"
247
+ sql.replace(new_sql)
248
+ end
200
249
  end
201
250
  end
202
251
 
@@ -251,7 +300,7 @@ module ::JdbcSpec
251
300
  change_column_type(table_name, column_name, type, options)
252
301
  change_column_default(table_name, column_name, options[:default]) if options_include_default?(options)
253
302
  end
254
-
303
+
255
304
  def change_column_type(table_name, column_name, type, options = {}) #:nodoc:
256
305
  sql = "ALTER TABLE #{table_name} ALTER COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
257
306
  if options.has_key?(:null)
@@ -259,14 +308,14 @@ module ::JdbcSpec
259
308
  end
260
309
  execute(sql)
261
310
  end
262
-
311
+
263
312
  def change_column_default(table_name, column_name, default) #:nodoc:
264
313
  remove_default_constraint(table_name, column_name)
265
314
  unless default.nil?
266
315
  execute "ALTER TABLE #{table_name} ADD CONSTRAINT DF_#{table_name}_#{column_name} DEFAULT #{quote(default)} FOR #{quote_column_name(column_name)}"
267
316
  end
268
317
  end
269
-
318
+
270
319
  def remove_column(table_name, column_name)
271
320
  remove_check_constraints(table_name, column_name)
272
321
  remove_default_constraint(table_name, column_name)
@@ -400,20 +449,20 @@ module ::JdbcSpec
400
449
  end
401
450
  sql
402
451
  end
403
-
452
+
404
453
  def determine_order_clause(sql)
405
454
  return $1 if sql =~ /ORDER BY (.*)$/
406
455
  sql =~ /FROM +(\w+?)\b/ || raise("can't determine table name")
407
- table_name = $1
408
- "#{table_name}.#{determine_primary_key(table_name)}"
456
+ table_name = $1
457
+ "#{table_name}.#{determine_primary_key(table_name)}"
409
458
  end
410
459
 
411
460
  def determine_primary_key(table_name)
412
461
  primary_key = columns(table_name).detect { |column| column.primary || column.identity }
413
462
  primary_key ? primary_key.name : "id"
414
463
  end
415
-
464
+
416
465
  end
417
-
466
+
418
467
  end
419
468
 
@@ -118,6 +118,22 @@ module ::JdbcSpec
118
118
  # Transactions aren't supported
119
119
  end
120
120
 
121
+ def supports_savepoints? #:nodoc:
122
+ true
123
+ end
124
+
125
+ def create_savepoint
126
+ execute("SAVEPOINT #{current_savepoint_name}")
127
+ end
128
+
129
+ def rollback_to_savepoint
130
+ execute("ROLLBACK TO SAVEPOINT #{current_savepoint_name}")
131
+ end
132
+
133
+ def release_savepoint
134
+ execute("RELEASE SAVEPOINT #{current_savepoint_name}")
135
+ end
136
+
121
137
  def disable_referential_integrity(&block) #:nodoc:
122
138
  old = select_value("SELECT @@FOREIGN_KEY_CHECKS")
123
139
  begin
@@ -150,9 +166,9 @@ module ::JdbcSpec
150
166
  end
151
167
  end
152
168
 
153
- def recreate_database(name) #:nodoc:
169
+ def recreate_database(name, options = {}) #:nodoc:
154
170
  drop_database(name)
155
- create_database(name)
171
+ create_database(name, options)
156
172
  end
157
173
 
158
174
  def character_set(options) #:nodoc:
@@ -144,6 +144,18 @@ module ::JdbcSpec
144
144
  true
145
145
  end
146
146
 
147
+ def create_savepoint
148
+ execute("SAVEPOINT #{current_savepoint_name}")
149
+ end
150
+
151
+ def rollback_to_savepoint
152
+ execute("ROLLBACK TO SAVEPOINT #{current_savepoint_name}")
153
+ end
154
+
155
+ def release_savepoint
156
+ execute("RELEASE SAVEPOINT #{current_savepoint_name}")
157
+ end
158
+
147
159
  # Returns the configured supported identifier length supported by PostgreSQL,
148
160
  # or report the default of 63 on PostgreSQL 7.x.
149
161
  def table_alias_length
@@ -1,5 +1,5 @@
1
1
  module JdbcAdapter
2
2
  module Version
3
- VERSION = "0.9.6"
3
+ VERSION = "0.9.7"
4
4
  end
5
5
  end
data/rakelib/package.rake CHANGED
@@ -24,7 +24,6 @@ begin
24
24
  p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
25
25
  p.description = p.paragraphs_of('README.txt', 0...1).join("\n\n")
26
26
  end
27
- hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" }
28
27
  task :gemspec do
29
28
  File.open("#{hoe.name}.gemspec", "w") {|f| f << hoe.spec.to_ruby }
30
29
  end
@@ -135,15 +135,18 @@ public class RubyJdbcConnection extends RubyObject {
135
135
  if (schemaName != null) schemaName = caseConvertIdentifierForJdbc(metadata, schemaName);
136
136
  table_name = caseConvertIdentifierForJdbc(metadata, table_name);
137
137
 
138
+ String catalog = c.getCatalog();
139
+ if (schemaName != null) { catalog = schemaName; }
140
+
138
141
  String[] tableTypes = new String[]{"TABLE","VIEW","SYNONYM"};
139
142
  RubyArray matchingTables = (RubyArray) tableLookupBlock(context.getRuntime(),
140
- c.getCatalog(), schemaName, table_name, tableTypes, false).call(c);
143
+ catalog, schemaName, table_name, tableTypes, false).call(c);
141
144
  if (matchingTables.isEmpty()) {
142
145
  throw new SQLException("Table " + table_name + " does not exist");
143
146
  }
144
147
 
145
- results = metadata.getColumns(c.getCatalog(),schemaName,table_name,null);
146
- pkeys = metadata.getPrimaryKeys(c.getCatalog(),schemaName,table_name);
148
+ results = metadata.getColumns(catalog,schemaName,table_name,null);
149
+ pkeys = metadata.getPrimaryKeys(catalog,schemaName,table_name);
147
150
  return unmarshal_columns(context, metadata, results, pkeys);
148
151
  } finally {
149
152
  close(results);
@@ -7,7 +7,7 @@ class MysqlDbCreateTest < Test::Unit::TestCase
7
7
  def db_config
8
8
  MSSQL_CONFIG
9
9
  end
10
-
10
+
11
11
  def test_rake_db_create
12
12
  begin
13
13
  Rake::Task["db:create"].invoke
@@ -18,7 +18,9 @@ class MysqlDbCreateTest < Test::Unit::TestCase
18
18
  end
19
19
  end
20
20
  ActiveRecord::Base.establish_connection(db_config.merge(:database => "master"))
21
- databases = ActiveRecord::Base.connection.select_rows("SELECT NAME FROM sys.sysdatabases").flatten
21
+ select = "SELECT NAME FROM sys.sysdatabases"
22
+ select = "SELECT name FROM master..sysdatabases ORDER BY name" if ActiveRecord::Base.connection.sqlserver_version == "2000"
23
+ databases = ActiveRecord::Base.connection.select_rows(select).flatten
22
24
  assert databases.include?(@db_name)
23
25
  end
24
26
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 6
9
- version: 0.9.6
8
+ - 7
9
+ version: 0.9.7
10
10
  platform: java
11
11
  authors:
12
12
  - Nick Sieger, Ola Bini and JRuby contributors
@@ -14,10 +14,24 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-05 00:00:00 -05:00
17
+ date: 2010-05-25 00:00:00 -05:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: hoe
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 3
31
+ - 3
32
+ version: 2.3.3
33
+ type: :development
34
+ version_requirements: *id001
21
35
  description: |-
22
36
  activerecord-jdbc-adapter is a database adapter for Rails' ActiveRecord
23
37
  component that can be used with JRuby[http://www.jruby.org/]. It allows use of
@@ -178,6 +192,7 @@ rdoc_options:
178
192
  require_paths:
179
193
  - lib
180
194
  required_ruby_version: !ruby/object:Gem::Requirement
195
+ none: false
181
196
  requirements:
182
197
  - - ">="
183
198
  - !ruby/object:Gem::Version
@@ -185,6 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
200
  - 0
186
201
  version: "0"
187
202
  required_rubygems_version: !ruby/object:Gem::Requirement
203
+ none: false
188
204
  requirements:
189
205
  - - ">="
190
206
  - !ruby/object:Gem::Version
@@ -194,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
210
  requirements: []
195
211
 
196
212
  rubyforge_project: jruby-extras
197
- rubygems_version: 1.3.6
213
+ rubygems_version: 1.3.7
198
214
  signing_key:
199
215
  specification_version: 3
200
216
  summary: JDBC adapter for ActiveRecord, for use within JRuby on Rails.