activerecord-pedantmysql2-adapter 1.1.1 → 1.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4908d611c3be793a9b05bee55255aa2c26f95b90
4
- data.tar.gz: df0b20724934de0da44e92950b340033e567f8d0
3
+ metadata.gz: 9d494c02a52cb2aac4d27b0023603f8508b412f6
4
+ data.tar.gz: c9aeafa57eaa2bfa596c30ee54eaf3862ab98f9f
5
5
  SHA512:
6
- metadata.gz: e693a9dc9997acbac0b6810a7eeb6a7102204765193f90cfb70497ab504bd57e079b2cba7dc717b87cf09cc227071ada40028248f620f444fbaaec02d7ff38cc
7
- data.tar.gz: c729d4433b5f9810169eb2feb8665190f1a4043a345620df4df3edd97694dc9363d960fa2f0c6e4e403085d3ebdac8c9b19dcabb8634c4e27bb85a6e95d8a713
6
+ metadata.gz: 50ab85d2c548b1aa4132e1923dba96b262fa2aa8cb0d4a58b22f0e30ca13b207fd94a4c418e9107c4a2cb8dd5f72c300227c68e3eeb48a18641e16a9e032fac5
7
+ data.tar.gz: 467fe6fe8bd380364bb1266680634d7630ba485dab2542965f64e835de446a7a018429b5e9a110afd239aaa40de9f107a14d2b1aa2068026c5d1af68cca3b550
@@ -12,6 +12,7 @@ module ActiveRecord
12
12
  end
13
13
 
14
14
  client = Mysql2::Client.new(config)
15
+
15
16
  options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
16
17
  ActiveRecord::ConnectionAdapters::PedantMysql2Adapter.new(client, logger, options, config)
17
18
  rescue Mysql2::Error => error
@@ -37,8 +38,6 @@ class MysqlWarning < StandardError
37
38
  end
38
39
 
39
40
  class ActiveRecord::ConnectionAdapters::PedantMysql2Adapter < ActiveRecord::ConnectionAdapters::Mysql2Adapter
40
- alias_method :exec_delete_without_pedant, :exec_delete
41
-
42
41
  def execute(sql, name = nil)
43
42
  value = super
44
43
  log_warnings(sql)
@@ -46,10 +45,9 @@ class ActiveRecord::ConnectionAdapters::PedantMysql2Adapter < ActiveRecord::Conn
46
45
  end
47
46
 
48
47
  def exec_delete(sql, name, binds)
49
- exec_delete_without_pedant(to_sql(sql, binds), name, binds)
50
- affected_rows = @connection.affected_rows
51
- log_warnings(sql)
52
- affected_rows
48
+ @affected_rows_before_logging = nil
49
+ value = super
50
+ @affected_rows_before_logging || value
53
51
  end
54
52
 
55
53
  alias :exec_update :exec_delete
@@ -59,7 +57,9 @@ class ActiveRecord::ConnectionAdapters::PedantMysql2Adapter < ActiveRecord::Conn
59
57
  def log_warnings(sql)
60
58
  return unless @connection.warning_count > 0
61
59
 
60
+ @affected_rows_before_logging = @connection.affected_rows
62
61
  result = @connection.query('SHOW WARNINGS')
62
+
63
63
  result.each do |level, code, message|
64
64
  warning = MysqlWarning.new(message, code, level, sql)
65
65
  ::PedantMysql2.warn(warning)
@@ -1,3 +1,3 @@
1
1
  module PedantMysql2
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
data/spec/adapter_spec.rb CHANGED
@@ -55,13 +55,27 @@ describe PedantMysql2 do
55
55
  expect(result.to_a).to be == [[1.0]]
56
56
  end
57
57
 
58
- it 'do not change the returned value of exec_update' do
58
+ it 'does not change the returned value of exec_update' do
59
+ connection.execute('INSERT INTO comment VALUES (17)')
59
60
  result = connection.update('UPDATE comment SET id = 1 ORDER BY id LIMIT 1')
61
+ expect(result).to be == 1
62
+ end
63
+
64
+ it 'does not change the returned value of exec_update when there is warnings' do
65
+ PedantMysql2.silence_warnings!
66
+ result = connection.update('UPDATE comment SET id = 1 WHERE id > (42+"foo") ORDER BY id LIMIT 1')
60
67
  expect(result).to be_zero
61
68
  end
62
69
 
63
- it 'do not change the returned value of exec_delete' do
70
+ it 'does not change the returned value of exec_delete' do
71
+ connection.execute('INSERT INTO comment VALUES (17)')
64
72
  result = connection.delete('DELETE FROM comment ORDER BY id LIMIT 1')
73
+ expect(result).to be == 1
74
+ end
75
+
76
+ it 'does not change the returned value of exec_delete when there is warnings' do
77
+ PedantMysql2.silence_warnings!
78
+ result = connection.delete('DELETE FROM comment WHERE id > (42+"foo") ORDER BY id LIMIT 1')
65
79
  expect(result).to be_zero
66
80
  end
67
81
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-pedantmysql2-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-16 00:00:00.000000000 Z
11
+ date: 2017-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord