activerecord 1.13.1 → 1.13.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,9 +1,31 @@
1
+ *
2
+ *1.13.2* (December 13th, 2005)
3
+
4
+ * Become part of Rails 1.0
5
+
6
+ * MySQL: allow encoding option for mysql.rb driver. [Jeremy Kemper]
7
+
8
+ * MySQL: fixes for the bundled mysql.rb driver. #3160 [Justin Forder]
9
+
10
+ * MySQL, PostgreSQL: reconnect! also reconfigures the connection. Otherwise, the connection 'loses' its settings if it times out and is reconnected. #2978 [Shugo Maeda]
11
+
12
+ * SQLServer: fix obscure optimistic locking bug. #3068 [kajism@yahoo.com]
13
+
14
+ * SQLServer: support uniqueidentifier columns. #2930 [keithm@infused.org]
15
+
16
+ * SQLServer: cope with tables names qualified by owner. #3067 [jeff@ministrycentered.com]
17
+
18
+ * SQLServer: cope with columns with "desc" in the name. #1950 [Ron Lusk, Ryan Tomayko]
19
+
20
+ * SQLServer: cope with primary keys with "select" in the name. #3057 [rdifrango@captechventures.com]
21
+
22
+ * Oracle: active? performs a select instead of a commit. #3133 [Michael Schoen]
23
+
24
+
1
25
  *1.13.1* (December 7th, 2005)
2
26
 
3
27
  * MySQL: more robust test for nullified result hashes. #3124 [Stefan Kaes]
4
28
 
5
- * SQLite: find database file when RAILS_ROOT is a symlink. #3116 [anna@wota.jp]
6
-
7
29
  * Reloading an instance refreshes its aggregations as well as its associations. #3024 [François Beausolei]
8
30
 
9
31
  * Fixed that using :include together with :conditions array in Base.find would cause NoMethodError #2887 [Paul Hammmond]
@@ -34,17 +34,7 @@ module ActiveRecord
34
34
 
35
35
  mysql = Mysql.init
36
36
  mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslkey]
37
- if config[:encoding]
38
- begin
39
- mysql.options(Mysql::SET_CHARSET_NAME, config[:encoding])
40
- rescue
41
- raise ActiveRecord::ConnectionFailed, 'The :encoding option is only available for MySQL 4.1 and later with the mysql-ruby driver. Again, this does not work with the ruby-mysql driver or MySQL < 4.1.'
42
- end
43
- end
44
-
45
- conn = mysql.real_connect(host, username, password, database, port, socket)
46
- conn.query("SET NAMES '#{config[:encoding]}'") if config[:encoding]
47
- ConnectionAdapters::MysqlAdapter.new(conn, logger, [host, username, password, database, port, socket], mysql)
37
+ ConnectionAdapters::MysqlAdapter.new(mysql, logger, [host, username, password, database, port, socket], config)
48
38
  end
49
39
  end
50
40
 
@@ -90,11 +80,11 @@ module ActiveRecord
90
80
  "MySQL server has gone away"
91
81
  ]
92
82
 
93
- def initialize(connection, logger, connection_options=nil, mysql=Mysql)
83
+ def initialize(connection, logger, connection_options, config)
94
84
  super(connection, logger)
95
- @connection_options = connection_options
85
+ @connection_options, @config = connection_options, config
96
86
  @null_values_in_each_hash = Mysql.const_defined?(:VERSION)
97
- @mysql = mysql
87
+ connect
98
88
  end
99
89
 
100
90
  def adapter_name #:nodoc:
@@ -138,7 +128,7 @@ module ActiveRecord
138
128
  end
139
129
 
140
130
  def quote_string(string) #:nodoc:
141
- @mysql.quote(string)
131
+ @connection.quote(string)
142
132
  end
143
133
 
144
134
  def quoted_true
@@ -321,11 +311,7 @@ module ActiveRecord
321
311
  def connect
322
312
  encoding = @config[:encoding]
323
313
  if encoding
324
- begin
325
- @connection.options(Mysql::SET_CHARSET_NAME, encoding)
326
- rescue
327
- raise ActiveRecord::ConnectionFailed, 'The :encoding option is only available for MySQL 4.1 and later with the mysql-ruby driver. Again, this does not work with the ruby-mysql driver or MySQL < 4.1.'
328
- end
314
+ @connection.options(Mysql::SET_CHARSET_NAME, encoding) rescue nil
329
315
  end
330
316
  @connection.real_connect(*@connection_options)
331
317
  execute("SET NAMES '#{encoding}'") if encoding
@@ -550,7 +550,7 @@ begin
550
550
  # checks the connection, while #active? simply returns the last
551
551
  # known state.
552
552
  def ping
553
- @connection.commit
553
+ @connection.exec("select 1 from dual") { |r| nil }
554
554
  @active = true
555
555
  rescue
556
556
  @active = false
@@ -55,7 +55,7 @@ module ActiveRecord
55
55
  # the database path is not the special path that tells
56
56
  # Sqlite build a database only in memory.
57
57
  if Object.const_defined?(:RAILS_ROOT) && ':memory:' != config[:database]
58
- config[:database] = File.join(RAILS_ROOT, config[:database])
58
+ config[:database] = File.expand_path(config[:database], RAILS_ROOT)
59
59
  end
60
60
  end
61
61
  end
@@ -68,6 +68,7 @@ module ActiveRecord
68
68
  when /binary|image|varbinary/i then :binary
69
69
  when /char|nchar|nvarchar|string|varchar/i then :string
70
70
  when /bit/i then :boolean
71
+ when /uniqueidentifier/i then :string
71
72
  end
72
73
  end
73
74
 
@@ -233,6 +234,9 @@ module ActiveRecord
233
234
  end
234
235
 
235
236
  def columns(table_name, name = nil)
237
+ return [] if table_name.blank?
238
+ table_name = table_name.to_s if table_name.is_a?(Symbol)
239
+ table_name = table_name.split('.')[-1] unless table_name.nil?
236
240
  sql = "SELECT COLUMN_NAME as ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType, COL_LENGTH('#{table_name}', COLUMN_NAME) as Length, COLUMNPROPERTY(OBJECT_ID('#{table_name}'), COLUMN_NAME, 'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '#{table_name}'"
237
241
  # Comment out if you want to have the Columns select statment logged.
238
242
  # Personnally, I think it adds unneccessary bloat to the log.
@@ -347,7 +351,7 @@ module ActiveRecord
347
351
 
348
352
  def add_limit_offset!(sql, options)
349
353
  if options[:limit] and options[:offset]
350
- total_rows = @connection.select_all("SELECT count(*) as TotalRows from (#{sql.gsub(/SELECT/i, "SELECT TOP 1000000000")}) tally")[0][:TotalRows].to_i
354
+ total_rows = @connection.select_all("SELECT count(*) as TotalRows from (#{sql.gsub(/\bSELECT\b/i, "SELECT TOP 1000000000")}) tally")[0][:TotalRows].to_i
351
355
  if (options[:limit] + options[:offset]) >= total_rows
352
356
  options[:limit] = (total_rows - options[:offset] >= 0) ? (total_rows - options[:offset]) : 0
353
357
  end
@@ -509,9 +513,9 @@ module ActiveRecord
509
513
 
510
514
  def change_order_direction(order)
511
515
  case order
512
- when /DESC/i then order.gsub(/DESC/i, "ASC")
513
- when /ASC/i then order.gsub(/ASC/i, "DESC")
514
- else String.new(order).split(',').join(' DESC,') + ' DESC'
516
+ when /\bDESC\b/i then order.gsub(/\bDESC\b/i, "ASC")
517
+ when /\bASC\b/i then order.gsub(/\bASC\b/i, "DESC")
518
+ else String.new(order).split(',').join(' DESC,') + ' DESC'
515
519
  end
516
520
  end
517
521
 
@@ -127,7 +127,8 @@ class Mysql
127
127
  flag |= @client_flag | CLIENT_CAPABILITIES
128
128
  flag |= CLIENT_CONNECT_WITH_DB if db
129
129
 
130
- if !@server_capabilities & PROTO_AUTH41
130
+ @pre_411 = (0 == @server_capabilities & PROTO_AUTH41)
131
+ if @pre_411
131
132
  data = Net::int2str(flag)+Net::int3str(@max_allowed_packet)+
132
133
  (user||"")+"\0"+
133
134
  scramble(passwd, @scramble_buff, @protocol_version==9)
@@ -139,13 +140,10 @@ class Mysql
139
140
  ([8] + Array.new(23, 0)).pack("c24") + (user||"")+"\0"+
140
141
  scramble41(passwd, @scramble_buff)
141
142
  end
142
-
143
- if db and @server_capabilities & CLIENT_CONNECT_WITH_DB != 0 then
144
- if PROTO_AUTH41
145
- data << db+"\0"
146
- else
147
- data << "\0"+db
148
- end
143
+
144
+ if db and @server_capabilities & CLIENT_CONNECT_WITH_DB != 0
145
+ data << "\0" if @pre_411
146
+ data << db
149
147
  @db = db.dup
150
148
  end
151
149
  write data
@@ -205,10 +203,10 @@ class Mysql
205
203
  end
206
204
 
207
205
  def change_user(user="", passwd="", db="")
208
- if !@server_capabilities & PROTO_AUTH41
209
- data = user+"\0"+scramble(passwd, @scramble_buff, @protocol_version==9)+"\0"+db
206
+ if @pre_411
207
+ data = user+"\0"+scramble(passwd, @scramble_buff, @protocol_version==9)+"\0"+db
210
208
  else
211
- data = user+"\0"+ scramble41(passwd, @scramble_buff)
209
+ data = user+"\0"+scramble41(passwd, @scramble_buff)+db
212
210
  end
213
211
  command COM_CHANGE_USER, data
214
212
  @user = user
@@ -270,8 +268,8 @@ class Mysql
270
268
 
271
269
  def list_fields(table, field=nil)
272
270
  command COM_FIELD_LIST, "#{table}\0#{field}", true
273
- if !@server_capabilities & PROTO_AUTH41
274
- f = read_rows 6
271
+ if @pre_411
272
+ f = read_rows 6
275
273
  else
276
274
  f = read_rows 7
277
275
  end
@@ -284,8 +282,8 @@ class Mysql
284
282
  def list_processes()
285
283
  data = command COM_PROCESS_INFO
286
284
  @field_count = get_length data
287
- if !@server_capabilities & PROTO_AUTH41
288
- fields = read_rows 5
285
+ if @pre_411
286
+ fields = read_rows 5
289
287
  else
290
288
  fields = read_rows 7
291
289
  end
@@ -402,8 +400,8 @@ class Mysql
402
400
  end
403
401
  else
404
402
  @extra_info = get_length(data, true)
405
- if !@server_capabilities & PROTO_AUTH41
406
- fields = read_rows 5
403
+ if @pre_411
404
+ fields = read_rows(5)
407
405
  else
408
406
  fields = read_rows(7)
409
407
  end
@@ -416,20 +414,20 @@ class Mysql
416
414
  def unpack_fields(data, long_flag_protocol)
417
415
  ret = []
418
416
  data.each do |f|
419
- if !@server_capabilities & PROTO_AUTH41
420
- table = org_table = f[0]
421
- name = f[1]
422
- length = f[2][0]+f[2][1]*256+f[2][2]*256*256
423
- type = f[3][0]
424
- if long_flag_protocol then
425
- flags = f[4][0]+f[4][1]*256
426
- decimals = f[4][2]
427
- else
428
- flags = f[4][0]
429
- decimals = f[4][1]
430
- end
431
- def_value = f[5]
432
- max_length = 0
417
+ if @pre_411
418
+ table = org_table = f[0]
419
+ name = f[1]
420
+ length = f[2][0]+f[2][1]*256+f[2][2]*256*256
421
+ type = f[3][0]
422
+ if long_flag_protocol then
423
+ flags = f[4][0]+f[4][1]*256
424
+ decimals = f[4][2]
425
+ else
426
+ flags = f[4][0]
427
+ decimals = f[4][1]
428
+ end
429
+ def_value = f[5]
430
+ max_length = 0
433
431
  else
434
432
  catalog = f[0]
435
433
  db = f[1]
@@ -443,9 +441,9 @@ class Mysql
443
441
  decimals = f[6][9]
444
442
  def_value = ""
445
443
  max_length = 0
444
+ end
446
445
  ret << Field::new(table, org_table, name, length, type, flags, decimals, def_value, max_length)
447
446
  end
448
- end
449
447
  ret
450
448
  end
451
449
 
@@ -548,16 +546,13 @@ class Mysql
548
546
  end
549
547
 
550
548
  def scramble41(password, message)
551
- if password.length != 0
552
- buf = [0x14]
553
- s1 = Digest::SHA1.new(password).digest
554
- s2 = Digest::SHA1.new(s1).digest
555
- x = Digest::SHA1.new(message + s2).digest
556
- (0..s1.length - 1).each {|i| buf.push(s1[i] ^ x[i])}
557
- buf.pack("C*")
558
- else
559
- 0x00.chr
560
- end
549
+ return 0x00.chr if password.nil? or password.empty?
550
+ buf = [0x14]
551
+ s1 = Digest::SHA1.new(password).digest
552
+ s2 = Digest::SHA1.new(s1).digest
553
+ x = Digest::SHA1.new(message + s2).digest
554
+ (0..s1.length - 1).each {|i| buf.push(s1[i] ^ x[i])}
555
+ buf.pack("C*")
561
556
  end
562
557
 
563
558
  def error(errno)
@@ -2,7 +2,7 @@ module ActiveRecord
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 13
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/rakefile CHANGED
@@ -106,7 +106,7 @@ spec = Gem::Specification.new do |s|
106
106
  s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
107
107
  end
108
108
 
109
- s.add_dependency('activesupport', '= 1.2.4' + PKG_BUILD)
109
+ s.add_dependency('activesupport', '= 1.2.5' + PKG_BUILD)
110
110
 
111
111
  s.files.delete "test/fixtures/fixture_database.sqlite"
112
112
  s.files.delete "test/fixtures/fixture_database_2.sqlite"
@@ -222,17 +222,23 @@ class EagerAssociationTest < Test::Unit::TestCase
222
222
 
223
223
  def test_preconfigured_includes_with_has_many
224
224
  posts = authors(:david).posts_with_comments
225
- assert_equal 2, posts.first.comments.size
225
+ one = posts.detect { |p| p.id == 1 }
226
+ assert_equal 5, posts.size
227
+ assert_equal 2, one.comments.size
226
228
  end
227
229
 
228
230
  def test_preconfigured_includes_with_habtm
229
231
  posts = authors(:david).posts_with_categories
230
- assert_equal 2, posts.first.categories.size
232
+ one = posts.detect { |p| p.id == 1 }
233
+ assert_equal 5, posts.size
234
+ assert_equal 2, one.categories.size
231
235
  end
232
236
 
233
237
  def test_preconfigured_includes_with_has_many_and_habtm
234
238
  posts = authors(:david).posts_with_comments_and_categories
235
- assert_equal 2, posts.first.comments.size
236
- assert_equal 2, posts.first.categories.size
239
+ one = posts.detect { |p| p.id == 1 }
240
+ assert_equal 5, posts.size
241
+ assert_equal 2, one.comments.size
242
+ assert_equal 2, one.categories.size
237
243
  end
238
244
  end
@@ -1388,7 +1388,10 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
1388
1388
  assert developer.save
1389
1389
  developer.projects << project
1390
1390
  developer.update_attribute("name", "Bruza")
1391
- assert_equal 1, developer.connection.select_one("SELECT count(*) FROM developers_projects WHERE
1392
- project_id = #{project.id} AND developer_id = #{developer.id}")["count(*)"].to_i
1391
+ assert_equal 1, Developer.connection.select_value(<<-end_sql).to_i
1392
+ SELECT count(*) FROM developers_projects
1393
+ WHERE project_id = #{project.id}
1394
+ AND developer_id = #{developer.id}
1395
+ end_sql
1393
1396
  end
1394
1397
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: activerecord
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.13.1
7
- date: 2005-12-07 00:00:00 -06:00
6
+ version: 1.13.2
7
+ date: 2005-12-13 00:00:00 -06:00
8
8
  summary: Implements the ActiveRecord pattern for ORM.
9
9
  require_paths:
10
10
  - lib
@@ -285,5 +285,5 @@ dependencies:
285
285
  -
286
286
  - "="
287
287
  - !ruby/object:Gem::Version
288
- version: 1.2.4
288
+ version: 1.2.5
289
289
  version: