diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-02-29 13:26:12 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-02-29 13:26:12 +0900 |
commit | 3cc62a977626bc9964d9f4bad85a997edf3a02c8 (patch) | |
tree | 33fd70b6f41cf853daf7f3e59e377d9c73776cc0 /activerecord/lib | |
parent | caa6fb3eb40e40b7c7487a1815482951cd162d7a (diff) | |
download | rails-3cc62a977626bc9964d9f4bad85a997edf3a02c8.tar.gz rails-3cc62a977626bc9964d9f4bad85a997edf3a02c8.tar.bz2 rails-3cc62a977626bc9964d9f4bad85a997edf3a02c8.zip |
Fix `NoMethodError: undefined method `fields' for nil:NilClass`
Currently `exec_query` raises `NoMethodError` when executing no result
queries (`INSERT`, `UPDATE`, `DELETE`, and all DDL) in mysql2 adapter.
```
irb(main):002:0> conn.execute("create table t(a int)")
(43.3ms) create table t(a int)
=> nil
irb(main):003:0> conn.execute("insert into t values (1)")
(19.3ms) insert into t values (1)
=> nil
irb(main):004:0> conn.exec_query("insert into t values (1)")
SQL (28.6ms) insert into t values (1)
NoMethodError: undefined method `fields' for nil:NilClass
```
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index 57d8867bb4..ed8cfae657 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -131,7 +131,7 @@ module ActiveRecord def exec_query(sql, name = 'SQL', binds = [], prepare: false) result = execute(sql, name) @connection.next_result while @connection.more_results? - ActiveRecord::Result.new(result.fields, result.to_a) + ActiveRecord::Result.new(result.fields, result.to_a) if result end def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) |