From 1057f976d0819ac3faa90b9639ddf1389c364a67 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Sun, 31 Oct 2010 10:11:49 -0700 Subject: [PATCH] ensure the query is a string earlier in the Mysql2::Client#query codepath for 1.9 --- ext/mysql2/client.c | 1 + spec/mysql2/client_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/ext/mysql2/client.c b/ext/mysql2/client.c index 7fcb28f..00715cb 100644 --- a/ext/mysql2/client.c +++ b/ext/mysql2/client.c @@ -290,6 +290,7 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) { opts = defaults; } + Check_Type(args.sql, T_STRING); #ifdef HAVE_RUBY_ENCODING_H rb_encoding *conn_enc = rb_to_encoding(wrapper->encoding); // ensure the string is in the encoding the connection is expecting diff --git a/spec/mysql2/client_spec.rb b/spec/mysql2/client_spec.rb index 8927410..748b423 100644 --- a/spec/mysql2/client_spec.rb +++ b/spec/mysql2/client_spec.rb @@ -86,6 +86,12 @@ describe Mysql2::Client do end 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 @client.query "SELECT 1", :something => :else @client.query_options.should eql(@client.query_options.merge(:something => :else))