adapter_extensions 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,2 +1,11 @@
1
1
  0.1.0 - March 5, 2007
2
- * Initial release
2
+ * Initial release
3
+
4
+ 0.1.1 - March 5, 2007
5
+ * Bug fixes
6
+
7
+ 0.1.2 - March 5, 2007
8
+ * Bug fixes
9
+
10
+ 0.2.0 - March 6, 2007
11
+ * SQL Server adapter included
data/Rakefile CHANGED
@@ -121,6 +121,9 @@ end
121
121
 
122
122
  desc "Reinstall the gem from a local package copy"
123
123
  task :reinstall => [:package] do
124
- `sudo gem uninstall -x -i #{PKG_NAME}`
125
- `sudo gem install pkg/#{PKG_NAME}-#{PKG_VERSION}`
124
+ windows = RUBY_PLATFORM =~ /mswin/
125
+ sudo = windows ? '' : 'sudo'
126
+ gem = windows ? 'gem.bat' : 'gem'
127
+ `#{sudo} #{gem} uninstall -x -i #{PKG_NAME}`
128
+ `#{sudo} #{gem} install pkg/#{PKG_NAME}-#{PKG_VERSION}`
126
129
  end
@@ -1,19 +1,28 @@
1
1
  # This source file contains extensions to the abstract adapter.
2
2
  module ActiveRecord #:nodoc:
3
3
  module ConnectionAdapters #:nodoc:
4
- # Extensions to the AbstractAdapter. In some cases a default implementation is provided,
5
- # in others it is adapter-dependent and the method will raise a NotImplementedError if
6
- # the adapter does not implement that method
4
+ # Extensions to the AbstractAdapter. In some cases a default implementation
5
+ # is provided, in others it is adapter-dependent and the method will
6
+ # raise a NotImplementedError if the adapter does not implement that method
7
7
  class AbstractAdapter
8
8
  # Truncate the specified table
9
9
  def truncate(table_name)
10
- execute("TRUNCATE #{table_name}")
10
+ execute("TRUNCATE TABLE #{table_name}")
11
11
  end
12
12
 
13
- # Bulk loading interface. Load the data from the specified file into the given
14
- # table. Note that options will be adapter-dependent.
13
+ # Bulk loading interface. Load the data from the specified file into the
14
+ # given table. Note that options will be adapter-dependent.
15
15
  def bulk_load(file, table_name, options={})
16
- raise NotImplementedError, "bulk_load is an abstract method"
16
+ raise ArgumentError, "#{file} does not exist" unless File.exist?(file)
17
+ raise ArgumentError, "#{table_name} does not exist" unless tables.include?(table_name)
18
+ do_bulk_load(file, table_name, options)
19
+ end
20
+
21
+ protected
22
+
23
+ # for subclasses to implement
24
+ def do_bulk_load(file, table_name, options={})
25
+ raise NotImplementedError, "do_bulk_load is an abstract method"
17
26
  end
18
27
  end
19
28
  end
@@ -3,16 +3,20 @@ module ActiveRecord #:nodoc:
3
3
  module ConnectionAdapters #:nodoc:
4
4
  # Adds new functionality to ActiveRecord MysqlAdapter.
5
5
  class MysqlAdapter < AbstractAdapter
6
- # Bulk load the data in the specified file. This implementation always uses the LOCAL keyword
6
+
7
+ protected
8
+ # Call +bulk_load+, as that method wraps this method.
9
+ #
10
+ #Bulk load the data in the specified file. This implementation always uses the LOCAL keyword
7
11
  # so the file must be found locally, not on the remote server, to be loaded.
8
12
  #
9
13
  # Options:
10
14
  # * <tt>:ignore</tt> -- Ignore the specified number of lines from the source file
11
15
  # * <tt>:columns</tt> -- Array of column names defining the source file column order
12
16
  # * <tt>:fields</tt> -- Hash of options for fields:
13
- # * <tt>:delimited_by</tt> -- The field delimiter
14
- # * <tt>:enclosed_by</tt> -- The field enclosure
15
- def bulk_load(file, table_name, options={})
17
+ # * <tt>:delimited_by</tt> -- The field delimiter
18
+ # * <tt>:enclosed_by</tt> -- The field enclosure
19
+ def do_bulk_load(file, table_name, options={})
16
20
  q = "LOAD DATA LOCAL INFILE '#{file}' INTO TABLE #{table_name}"
17
21
  if options[:fields]
18
22
  q << " FIELDS"
@@ -0,0 +1,30 @@
1
+ # Source code for the SQLServerAdapter extensions.
2
+ module ActiveRecord #:nodoc:
3
+ module ConnectionAdapters #:nodoc:
4
+ # Adds new functionality to ActiveRecord SQLServerAdapter.
5
+ class SQLServerAdapter < AbstractAdapter
6
+ protected
7
+ # Call +bulk_load+, as that method wraps this method.
8
+ #
9
+ # Bulk load the data in the specified file. This implementation relies
10
+ # on bcp being in your PATH.
11
+ #
12
+ # Options:
13
+ # * <tt>:ignore</tt> -- Ignore the specified number of lines from the source file
14
+ # * <tt>:columns</tt> -- Array of column names defining the source file column order
15
+ # * <tt>:fields</tt> -- Hash of options for fields:
16
+ # * <tt>:delimited_by</tt> -- The field delimiter
17
+ # * <tt>:enclosed_by</tt> -- The field enclosure
18
+ def do_bulk_load(file, table_name, options={})
19
+ env_name = attrs[:env] || RAILS_ENV
20
+ config = ActiveRecord::Base.configurations[env_name]
21
+ puts "Loading table \"#{table_name}\" from file \"#{filename}\""
22
+ cmd = "bcp \"#{config['database']}.dbo.#{table_name}\" in " +
23
+ "\"#{filename}\" -S \"#{config['host']}\" -c " +
24
+ "-t \"#{options[:delimited_by]}\" -b10000 -a8192 -q -E -U \"#{config['username']}\" " +
25
+ "-P \"#{config['password']}\" -e \"#{filename}.in.errors\""
26
+ `#{cmd}`
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,8 +2,8 @@
2
2
  module AdapterExtensions#:nodoc:
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
- MINOR = 1
6
- TINY = 2
5
+ MINOR = 2
6
+ TINY = 0
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0.10
3
3
  specification_version: 1
4
4
  name: adapter_extensions
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.2
7
- date: 2007-03-05 00:00:00 -05:00
6
+ version: 0.2.0
7
+ date: 2007-03-06 00:00:00 -05:00
8
8
  summary: Extensions to Rails ActiveRecord adapters.
9
9
  require_paths:
10
10
  - lib
@@ -39,6 +39,7 @@ files:
39
39
  - lib/adapter_extensions/version.rb
40
40
  - lib/adapter_extensions/connection_adapters/abstract_adapter.rb
41
41
  - lib/adapter_extensions/connection_adapters/mysql_adapter.rb
42
+ - lib/adapter_extensions/connection_adapters/sqlserver_adapter.rb
42
43
  test_files: []
43
44
 
44
45
  rdoc_options: