ghazel-ar-extensions 0.9.3.1 → 0.9.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,57 @@
1
- ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
1
+ module ActiveRecord::Extensions::ConnectionAdapters::MysqlAdapter # :nodoc:
2
+
3
+ include ActiveRecord::Extensions::Import::ImportSupport
4
+ include ActiveRecord::Extensions::Import::OnDuplicateKeyUpdateSupport
5
+
2
6
  # Returns the maximum number of bytes that the server will allow
3
7
  # in a single packet
4
8
  def max_allowed_packet # :nodoc:
5
9
  result = execute( "SHOW VARIABLES like 'max_allowed_packet';" )
6
- result.fetch_row[1].to_i
10
+ # original Mysql gem responds to #fetch_row while Mysql2 responds to #first
11
+ val = result.respond_to?(:fetch_row) ? result.fetch_row[1] : result.first[1]
12
+ val.to_i
7
13
  end
8
14
 
9
15
  def rollup_sql; " WITH ROLLUP "; end
16
+
17
+ # Returns a generated ON DUPLICATE KEY UPDATE statement given the passed
18
+ # in +args+.
19
+ def sql_for_on_duplicate_key_update( table_name, *args ) # :nodoc:
20
+ sql = ' ON DUPLICATE KEY UPDATE '
21
+ arg = args.first
22
+ if arg.is_a?( Array )
23
+ sql << sql_for_on_duplicate_key_update_as_array( table_name, arg )
24
+ elsif arg.is_a?( Hash )
25
+ sql << sql_for_on_duplicate_key_update_as_hash( table_name, arg )
26
+ elsif arg.is_a?( String )
27
+ sql << arg
28
+ else
29
+ raise ArgumentError.new( "Expected Array or Hash" )
30
+ end
31
+ sql
32
+ end
33
+
34
+ def sql_for_on_duplicate_key_update_as_array( table_name, arr ) # :nodoc:
35
+ results = arr.map do |column|
36
+ qc = quote_column_name( column )
37
+ "#{table_name}.#{qc}=VALUES(#{qc})"
38
+ end
39
+ results.join( ',' )
40
+ end
41
+
42
+ def sql_for_on_duplicate_key_update_as_hash( table_name, hsh ) # :nodoc:
43
+ sql = ' ON DUPLICATE KEY UPDATE '
44
+ results = hsh.map do |column1, column2|
45
+ qc1 = quote_column_name( column1 )
46
+ qc2 = quote_column_name( column2 )
47
+ "#{table_name}.#{qc1}=VALUES( #{qc2} )"
48
+ end
49
+ results.join( ',')
50
+ end
51
+
52
+ #return true if the statement is a duplicate key record error
53
+ def duplicate_key_update_error?(exception)# :nodoc:
54
+ exception.is_a?(ActiveRecord::StatementInvalid) && exception.to_s.include?('Duplicate entry')
55
+ end
56
+
10
57
  end
@@ -1,50 +1,3 @@
1
- module ActiveRecord::Extensions::ConnectionAdapters::MysqlAdapter # :nodoc:
2
-
3
- include ActiveRecord::Extensions::Import::ImportSupport
4
- include ActiveRecord::Extensions::Import::OnDuplicateKeyUpdateSupport
5
-
6
- # Returns a generated ON DUPLICATE KEY UPDATE statement given the passed
7
- # in +args+.
8
- def sql_for_on_duplicate_key_update( table_name, *args ) # :nodoc:
9
- sql = ' ON DUPLICATE KEY UPDATE '
10
- arg = args.first
11
- if arg.is_a?( Array )
12
- sql << sql_for_on_duplicate_key_update_as_array( table_name, arg )
13
- elsif arg.is_a?( Hash )
14
- sql << sql_for_on_duplicate_key_update_as_hash( table_name, arg )
15
- elsif arg.is_a?( String )
16
- sql << arg
17
- else
18
- raise ArgumentError.new( "Expected Array or Hash" )
19
- end
20
- sql
21
- end
22
-
23
- def sql_for_on_duplicate_key_update_as_array( table_name, arr ) # :nodoc:
24
- results = arr.map do |column|
25
- qc = quote_column_name( column )
26
- "#{table_name}.#{qc}=VALUES(#{qc})"
27
- end
28
- results.join( ',' )
29
- end
30
-
31
- def sql_for_on_duplicate_key_update_as_hash( table_name, hsh ) # :nodoc:
32
- sql = ' ON DUPLICATE KEY UPDATE '
33
- results = hsh.map do |column1, column2|
34
- qc1 = quote_column_name( column1 )
35
- qc2 = quote_column_name( column2 )
36
- "#{table_name}.#{qc1}=VALUES( #{qc2} )"
37
- end
38
- results.join( ',')
39
- end
40
-
41
- #return true if the statement is a duplicate key record error
42
- def duplicate_key_update_error?(exception)# :nodoc:
43
- exception.is_a?(ActiveRecord::StatementInvalid) && exception.to_s.include?('Duplicate entry')
44
- end
45
-
46
- end
47
-
48
1
  ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
49
2
  include ActiveRecord::Extensions::ConnectionAdapters::MysqlAdapter
50
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghazel-ar-extensions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 3
10
- - 1
11
- version: 0.9.3.1
10
+ - 2
11
+ version: 0.9.3.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Zach Dennis
@@ -59,7 +59,6 @@ files:
59
59
  - config/postgresql.schema
60
60
  - lib/ar-extensions/adapters/abstract_adapter.rb
61
61
  - lib/ar-extensions/adapters/mysql.rb
62
- - lib/ar-extensions/adapters/mysql2.rb
63
62
  - lib/ar-extensions/adapters/oracle.rb
64
63
  - lib/ar-extensions/adapters/postgresql.rb
65
64
  - lib/ar-extensions/adapters/sqlite.rb
@@ -1,10 +0,0 @@
1
- ActiveRecord::ConnectionAdapters::Mysql2Adapter.class_eval do
2
- # Returns the maximum number of bytes that the server will allow
3
- # in a single packet
4
- def max_allowed_packet # :nodoc:
5
- result = execute( "SHOW VARIABLES like 'max_allowed_packet';" )
6
- result.first[1].to_i
7
- end
8
-
9
- def rollup_sql; " WITH ROLLUP "; end
10
- end