must connect with a user, show errors again

This commit is contained in:
Brian Lopez 2010-04-02 20:24:13 -07:00
parent 82e2a1de21
commit 799f9809d0
2 changed files with 4 additions and 4 deletions

View File

@ -22,7 +22,7 @@ Benchmark.bmbm do |x|
end end
end end
mysql2 = Mysql2::Client.new mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql2.query "USE #{database}" mysql2.query "USE #{database}"
x.report do x.report do
puts "Mysql2" puts "Mysql2"

View File

@ -69,7 +69,7 @@ static VALUE rb_mysql_client_new(int argc, VALUE * argv, VALUE klass) {
} }
// HACK // HACK
if (!mysql_real_connect(client, host, username, password, database, port, socket, 0)) { if (mysql_real_connect(client, host, username, password, database, port, socket, 0) == NULL) {
// unable to connect // unable to connect
rb_raise(rb_eStandardError, "%s", mysql_error(client)); rb_raise(rb_eStandardError, "%s", mysql_error(client));
return Qnil; return Qnil;
@ -98,14 +98,14 @@ static VALUE rb_mysql_client_query(VALUE self, VALUE sql) {
GetMysql2Client(self, client); GetMysql2Client(self, client);
if (mysql_real_query(client, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0) { if (mysql_real_query(client, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0) {
// fprintf(stdout, "mysql_real_query error: %s\n", mysql_error(client)); fprintf(stdout, "mysql_real_query error: %s\n", mysql_error(client));
return Qnil; return Qnil;
} }
result = mysql_store_result(client); result = mysql_store_result(client);
if (result == NULL) { if (result == NULL) {
// lookup error code and msg, raise exception // lookup error code and msg, raise exception
// fprintf(stdout, "mysql_store_result error: %s\n", mysql_error(client)); fprintf(stdout, "mysql_store_result error: %s\n", mysql_error(client));
return Qnil; return Qnil;
} }
return rb_mysql_result_to_obj(result); return rb_mysql_result_to_obj(result);