adapter_extensions 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -8,4 +8,9 @@
8
8
  * Bug fixes
9
9
 
10
10
  0.2.0 - March 6, 2007
11
- * SQL Server adapter included
11
+ * SQL Server adapter included (Seth Ladd)
12
+
13
+ 0.3.0 - March 8, 2007
14
+ * PostgreSQL adapter included
15
+ * Added tests for bulk loading
16
+ * bulk_load method now handles table missing and file missing as error cases
@@ -7,7 +7,7 @@ module ActiveRecord #:nodoc:
7
7
  protected
8
8
  # Call +bulk_load+, as that method wraps this method.
9
9
  #
10
- #Bulk load the data in the specified file. This implementation always uses the LOCAL keyword
10
+ # Bulk load the data in the specified file. This implementation always uses the LOCAL keyword
11
11
  # so the file must be found locally, not on the remote server, to be loaded.
12
12
  #
13
13
  # Options:
@@ -0,0 +1,37 @@
1
+ # Source code for the PostgreSQLAdapter extensions.
2
+ module ActiveRecord #:nodoc:
3
+ module ConnectionAdapters #:nodoc:
4
+ # Adds new functionality to ActiveRecord PostgreSQLAdapter.
5
+ class PostgreSQLAdapter < AbstractAdapter
6
+
7
+ protected
8
+ # Call +bulk_load+, as that method wraps this method.
9
+ #
10
+ # Bulk load the data in the specified file.
11
+ #
12
+ # Options:
13
+ # * <tt>:ignore</tt> -- Ignore the specified number of lines from the source file. In the case of PostgreSQL
14
+ # only the first line will be ignored from the source file regardless of the number of lines specified.
15
+ # * <tt>:columns</tt> -- Array of column names defining the source file column order
16
+ # * <tt>:fields</tt> -- Hash of options for fields:
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={})
20
+ q = "COPY #{table_name} "
21
+ q << "(#{options[:columns].join(',')}) " if options[:columns]
22
+ q << "FROM '#{File.expand_path(file)}' "
23
+ if options[:fields]
24
+ q << "WITH "
25
+ q << "DELIMITER '#{options[:fields][:delimited_by]}' " if options[:fields][:delimited_by]
26
+ if options[:fields][:enclosed_by]
27
+ q << "CSV "
28
+ q << "HEADER " if options[:ignore] > 0
29
+ q << "QUOTE '#{options[:fields][:enclosed_by]}' " if options[:fields][:enclosed_by]
30
+ end
31
+ end
32
+
33
+ execute(q)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -2,7 +2,7 @@
2
2
  module AdapterExtensions#:nodoc:
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
- MINOR = 2
5
+ MINOR = 3
6
6
  TINY = 0
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
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.2.0
7
- date: 2007-03-06 00:00:00 -05:00
6
+ version: 0.3.0
7
+ date: 2007-03-08 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/postgresql_adapter.rb
42
43
  - lib/adapter_extensions/connection_adapters/sqlserver_adapter.rb
43
44
  test_files: []
44
45