Skip to content

Commit 41f8b32

Browse files
committed
Parse query_info to a hash
1 parent 0d9c806 commit 41f8b32

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

ext/mysql2/client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ void init_mysql2_client() {
11431143
rb_define_method(cMysql2Client, "store_result", rb_mysql_client_store_result, 0);
11441144
rb_define_method(cMysql2Client, "reconnect=", set_reconnect, 1);
11451145
rb_define_method(cMysql2Client, "warning_count", rb_mysql_client_warning_count, 0);
1146-
rb_define_method(cMysql2Client, "query_info", rb_mysql_info, 0);
1146+
rb_define_method(cMysql2Client, "query_info_string", rb_mysql_info, 0);
11471147
#ifdef HAVE_RUBY_ENCODING_H
11481148
rb_define_method(cMysql2Client, "encoding", rb_mysql_client_encoding, 0);
11491149
#endif

lib/mysql2/client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def self.default_query_options
6161
@@default_query_options
6262
end
6363

64+
def query_info
65+
info = query_info_string
66+
return {} unless info
67+
info_hash = {}
68+
info.split.each_slice(2) { |s| info_hash[s[0].downcase.delete(':').to_sym] = s[1].to_i }
69+
info_hash
70+
end
71+
6472
private
6573
def self.local_offset
6674
::Time.local(2010).utc_offset.to_r / 86400

spec/mysql2/client_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ def connect *args
140140
@client.query('select 1')
141141
end
142142
it "should 0" do
143-
@client.query_info.should be_nil
143+
@client.query_info.should be_empty
144+
@client.query_info_string.should be_nil
144145
end
145146
end
146147
context "when has some info" do
@@ -159,7 +160,8 @@ def connect *args
159160
@client.query("INSERT INTO infoTest (blah) VALUES (1234),(4535)")
160161
end
161162
it "should retrieve it" do
162-
@client.query_info.should eq 'Records: 2 Duplicates: 0 Warnings: 0'
163+
@client.query_info.should == {:records => 2, :duplicates => 0, :warnings => 0}
164+
@client.query_info_string.should eq 'Records: 2 Duplicates: 0 Warnings: 0'
163165
end
164166
end
165167
end

0 commit comments

Comments
 (0)