activerecord-pedantmysql2-adapter 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d494c02a52cb2aac4d27b0023603f8508b412f6
|
4
|
+
data.tar.gz: c9aeafa57eaa2bfa596c30ee54eaf3862ab98f9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
50
|
-
|
51
|
-
|
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)
|
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 '
|
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 '
|
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.
|
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-
|
11
|
+
date: 2017-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|