ensure the query is a string earlier in the Mysql2::Client#query codepath for 1.9

This commit is contained in:
Brian Lopez 2010-10-31 10:11:49 -07:00
parent 90ddb63e52
commit 1057f976d0
2 changed files with 7 additions and 0 deletions

View File

@ -290,6 +290,7 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
opts = defaults; opts = defaults;
} }
Check_Type(args.sql, T_STRING);
#ifdef HAVE_RUBY_ENCODING_H #ifdef HAVE_RUBY_ENCODING_H
rb_encoding *conn_enc = rb_to_encoding(wrapper->encoding); rb_encoding *conn_enc = rb_to_encoding(wrapper->encoding);
// ensure the string is in the encoding the connection is expecting // ensure the string is in the encoding the connection is expecting

View File

@ -86,6 +86,12 @@ describe Mysql2::Client do
end end
context "#query" do context "#query" do
it "should only accept strings as the query parameter" do
lambda {
@client.query ["SELECT 'not right'"]
}.should raise_error(TypeError)
end
it "should accept an options hash that inherits from Mysql2::Client.default_query_options" do it "should accept an options hash that inherits from Mysql2::Client.default_query_options" do
@client.query "SELECT 1", :something => :else @client.query "SELECT 1", :something => :else
@client.query_options.should eql(@client.query_options.merge(:something => :else)) @client.query_options.should eql(@client.query_options.merge(:something => :else))