adapter_extensions 0.4.0 → 0.5.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.
data/CHANGELOG CHANGED
@@ -20,4 +20,7 @@
20
20
 
21
21
  0.4 - September 17, 2007
22
22
  * Added copy_table method that can copy the structure and data from one table to another. Currently implemented in MySQL (tested), PostgreSQL (tested) and SQL Server adapters (untested).
23
- * Added support for SELECT..INTO for PostgreSQL.
23
+ * Added support for SELECT..INTO for PostgreSQL.
24
+
25
+ 0.5 -
26
+ * Updated dependencies for gem to current versions of ActiveRecord, ActiveSupport and Rake. May not be compatible with Rails versions less than 2.x.
data/README CHANGED
@@ -1,3 +1,7 @@
1
1
  This library provides extensions to Rails' ActiveRecord adapters.
2
2
 
3
+ As of version 0.5, adapter_extensions has dependencies on ActiveSupport and ActiveRecord 2.1.x or higher.
4
+
5
+ To use the MySQL adapter extensions with Rails 2.x, you must patch the mysql_adapter with the mysql_adapter_opt_local_infile.patch.
6
+
3
7
  To execute the unit tests you must first construct a adapter_extensions_unittest database.
data/Rakefile CHANGED
@@ -4,6 +4,7 @@ require 'rake/rdoctask'
4
4
  require 'rake/packagetask'
5
5
  require 'rake/gempackagetask'
6
6
  require 'rake/contrib/rubyforgepublisher'
7
+ require 'date'
7
8
 
8
9
  require File.join(File.dirname(__FILE__), 'lib/adapter_extensions', 'version')
9
10
 
@@ -66,9 +67,9 @@ spec = Gem::Specification.new do |s|
66
67
  Provides various extensions to the Rails ActiveRecord adapters.
67
68
  EOF
68
69
 
69
- s.add_dependency('rake', '>= 0.7.1')
70
- s.add_dependency('activesupport', '>= 1.3.1')
71
- s.add_dependency('activerecord', '>= 1.14.4')
70
+ s.add_dependency('rake', '>= 0.8.3')
71
+ s.add_dependency('activesupport', '>= 2.1.0')
72
+ s.add_dependency('activerecord', '>= 2.1.0')
72
73
  s.add_dependency('fastercsv', '>= 1.0.0')
73
74
 
74
75
  s.rdoc_options << '--exclude' << '.'
@@ -89,6 +90,15 @@ Rake::GemPackageTask.new(spec) do |pkg|
89
90
  pkg.need_zip = true
90
91
  end
91
92
 
93
+ namespace :github do
94
+ desc "Update Github Gemspec"
95
+ task :update_gemspec do
96
+ File.open(File.join(File.dirname(__FILE__), "#{spec.name}.gemspec"), "w"){|f| f << spec.to_ruby}
97
+ end
98
+ end
99
+
100
+
101
+
92
102
  desc "Generate code statistics"
93
103
  task :lines do
94
104
  lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
@@ -130,11 +140,19 @@ task :pdoc => [:rdoc] do
130
140
  Rake::SshDirPublisher.new("aeden@rubyforge.org", "/var/www/gforge-projects/activewarehouse/adapter_extensions/rdoc", "rdoc").upload
131
141
  end
132
142
 
143
+ desc "Install the gem from a local generated package"
144
+ task :install => [:package] do
145
+ windows = RUBY_PLATFORM =~ /mswin/
146
+ sudo = windows ? '' : 'sudo'
147
+ gem = windows ? 'gem.bat' : 'gem'
148
+ `#{sudo} #{gem} install pkg/#{PKG_NAME}-#{PKG_VERSION}`
149
+ end
150
+
133
151
  desc "Reinstall the gem from a local package copy"
134
152
  task :reinstall => [:package] do
135
153
  windows = RUBY_PLATFORM =~ /mswin/
136
154
  sudo = windows ? '' : 'sudo'
137
155
  gem = windows ? 'gem.bat' : 'gem'
138
- `#{sudo} #{gem} uninstall -x -i #{PKG_NAME}`
156
+ `#{sudo} #{gem} uninstall #{PKG_NAME} -x`
139
157
  `#{sudo} #{gem} install pkg/#{PKG_NAME}-#{PKG_VERSION}`
140
158
  end
@@ -5,19 +5,8 @@
5
5
  puts "Using AdapterExtensions"
6
6
 
7
7
  require 'rubygems'
8
- unless Kernel.respond_to?(:gem)
9
- Kernel.send :alias_method, :gem, :require_gem
10
- end
11
-
12
- unless defined?(ActiveSupport)
13
- gem 'activesupport'
14
- require 'active_support'
15
- end
16
-
17
- unless defined?(ActiveRecord)
18
- gem 'activerecord'
19
- require 'active_record'
20
- end
8
+ require 'active_support'
9
+ require 'active_record'
21
10
 
22
11
  $:.unshift(File.dirname(__FILE__))
23
12
  Dir[File.dirname(__FILE__) + "/adapter_extensions/**/*.rb"].each { |file| require(file) }
@@ -35,6 +35,18 @@ module ActiveRecord #:nodoc:
35
35
  # * <tt>:enclosed_by</tt> -- The field enclosure
36
36
  def do_bulk_load(file, table_name, options={})
37
37
  return if File.size(file) == 0
38
+
39
+ # an unfortunate hack - setting the bulk load option after the connection has been
40
+ # established does not seem to have any effect, and since the connection is made when
41
+ # active-record is loaded, there's no chance for us to sneak it in earlier. So we
42
+ # disconnect, set the option, then reconnect - fortunately, this only needs to happen once.
43
+ unless @bulk_load_enabled
44
+ disconnect!
45
+ @connection.options(Mysql::OPT_LOCAL_INFILE, true)
46
+ connect
47
+ @bulk_load_enabled = true
48
+ end
49
+
38
50
  q = "LOAD DATA LOCAL INFILE '#{file}' INTO TABLE #{table_name}"
39
51
  if options[:fields]
40
52
  q << " FIELDS"
@@ -46,21 +58,6 @@ module ActiveRecord #:nodoc:
46
58
  execute(q)
47
59
  end
48
60
 
49
- private
50
- def connect
51
- encoding = @config[:encoding]
52
- if encoding
53
- @connection.options(Mysql::SET_CHARSET_NAME, encoding) rescue nil
54
- end
55
- @connection.options(Mysql::OPT_LOCAL_INFILE, true)
56
- @connection.ssl_set(@config[:sslkey], @config[:sslcert], @config[:sslca], @config[:sslcapath], @config[:sslcipher]) if @config[:sslkey]
57
- @connection.real_connect(*@connection_options)
58
- execute("SET NAMES '#{encoding}'") if encoding
59
-
60
- # By default, MySQL 'where id is null' selects the last inserted id.
61
- # Turn this off. http://dev.rubyonrails.org/ticket/6778
62
- execute("SET SQL_AUTO_IS_NULL=0")
63
- end
64
61
  end
65
62
  end
66
63
  end
@@ -28,6 +28,7 @@ module ActiveRecord #:nodoc:
28
28
  # * <tt>:columns</tt> -- Array of column names defining the source file column order
29
29
  # * <tt>:fields</tt> -- Hash of options for fields:
30
30
  # * <tt>:delimited_by</tt> -- The field delimiter
31
+ # * <tt>:null_string</tt> -- The string that should be interpreted as NULL (in addition to \N)
31
32
  # * <tt>:enclosed_by</tt> -- The field enclosure
32
33
  def do_bulk_load(file, table_name, options={})
33
34
  q = "COPY #{table_name} "
@@ -36,7 +37,8 @@ module ActiveRecord #:nodoc:
36
37
  if options[:fields]
37
38
  q << "WITH "
38
39
  q << "DELIMITER '#{options[:fields][:delimited_by]}' " if options[:fields][:delimited_by]
39
- if options[:fields][:enclosed_by]
40
+ q << "NULL '#{options[:fields][:null_string]}'" if options[:fields][:null_string]
41
+ if options[:fields][:enclosed_by] || options[:ignore] && options[:ignore] > 0
40
42
  q << "CSV "
41
43
  q << "HEADER " if options[:ignore] && options[:ignore] > 0
42
44
  q << "QUOTE '#{options[:fields][:enclosed_by]}' " if options[:fields][:enclosed_by]
@@ -2,7 +2,7 @@
2
2
  module AdapterExtensions#:nodoc:
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
- MINOR = 4
5
+ MINOR = 5
6
6
  TINY = 0
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,93 +1,104 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: adapter_extensions
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.4.0
7
- date: 2007-09-17 00:00:00 +02:00
8
- summary: Extensions to Rails ActiveRecord adapters.
9
- require_paths:
10
- - lib
11
- email: anthonyeden@gmail.com
12
- homepage: http://activewarehouse.rubyforge.org/adapter_extensions
13
- rubyforge_project: activewarehouse
14
- description: Provides various extensions to the Rails ActiveRecord adapters.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.5.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Anthony Eden
31
- files:
32
- - CHANGELOG
33
- - README
34
- - LICENSE
35
- - Rakefile
36
- - lib/adapter_extensions
37
- - lib/adapter_extensions/connection_adapters
38
- - lib/adapter_extensions/connection_adapters/abstract_adapter.rb
39
- - lib/adapter_extensions/connection_adapters/mysql_adapter.rb
40
- - lib/adapter_extensions/connection_adapters/postgresql_adapter.rb
41
- - lib/adapter_extensions/connection_adapters/sqlserver_adapter.rb
42
- - lib/adapter_extensions/version.rb
43
- - lib/adapter_extensions.rb
44
- test_files: []
45
-
46
- rdoc_options:
47
- - --exclude
48
- - .
49
- extra_rdoc_files: []
50
-
51
- executables: []
52
-
53
- extensions: []
54
-
55
- requirements: []
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
56
11
 
12
+ date: 2009-01-14 00:00:00 -05:00
13
+ default_executable:
57
14
  dependencies:
58
15
  - !ruby/object:Gem::Dependency
59
16
  name: rake
17
+ type: :runtime
60
18
  version_requirement:
61
- version_requirements: !ruby/object:Gem::Version::Requirement
19
+ version_requirements: !ruby/object:Gem::Requirement
62
20
  requirements:
63
21
  - - ">="
64
22
  - !ruby/object:Gem::Version
65
- version: 0.7.1
23
+ version: 0.8.3
66
24
  version:
67
25
  - !ruby/object:Gem::Dependency
68
26
  name: activesupport
27
+ type: :runtime
69
28
  version_requirement:
70
- version_requirements: !ruby/object:Gem::Version::Requirement
29
+ version_requirements: !ruby/object:Gem::Requirement
71
30
  requirements:
72
31
  - - ">="
73
32
  - !ruby/object:Gem::Version
74
- version: 1.3.1
33
+ version: 2.1.0
75
34
  version:
76
35
  - !ruby/object:Gem::Dependency
77
36
  name: activerecord
37
+ type: :runtime
78
38
  version_requirement:
79
- version_requirements: !ruby/object:Gem::Version::Requirement
39
+ version_requirements: !ruby/object:Gem::Requirement
80
40
  requirements:
81
41
  - - ">="
82
42
  - !ruby/object:Gem::Version
83
- version: 1.14.4
43
+ version: 2.1.0
84
44
  version:
85
45
  - !ruby/object:Gem::Dependency
86
46
  name: fastercsv
47
+ type: :runtime
87
48
  version_requirement:
88
- version_requirements: !ruby/object:Gem::Version::Requirement
49
+ version_requirements: !ruby/object:Gem::Requirement
89
50
  requirements:
90
51
  - - ">="
91
52
  - !ruby/object:Gem::Version
92
53
  version: 1.0.0
93
54
  version:
55
+ description: Provides various extensions to the Rails ActiveRecord adapters.
56
+ email: anthonyeden@gmail.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files: []
62
+
63
+ files:
64
+ - CHANGELOG
65
+ - README
66
+ - LICENSE
67
+ - Rakefile
68
+ - lib/adapter_extensions
69
+ - lib/adapter_extensions/connection_adapters
70
+ - lib/adapter_extensions/connection_adapters/abstract_adapter.rb
71
+ - lib/adapter_extensions/connection_adapters/mysql_adapter.rb
72
+ - lib/adapter_extensions/connection_adapters/postgresql_adapter.rb
73
+ - lib/adapter_extensions/connection_adapters/sqlserver_adapter.rb
74
+ - lib/adapter_extensions/version.rb
75
+ - lib/adapter_extensions.rb
76
+ has_rdoc: false
77
+ homepage: http://activewarehouse.rubyforge.org/adapter_extensions
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --exclude
81
+ - .
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project: activewarehouse
99
+ rubygems_version: 1.3.1
100
+ signing_key:
101
+ specification_version: 2
102
+ summary: Extensions to Rails ActiveRecord adapters.
103
+ test_files: []
104
+