From a3cdd92a9ca325280b177dd6489d83f9f1b27a4e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 8 Jul 2010 16:09:21 -0700 Subject: [PATCH] execute raises an exception on error --- ext/mysql2/statement.c | 3 ++- spec/mysql2/statement_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/mysql2/statement.c b/ext/mysql2/statement.c index a12ee06..21eb057 100644 --- a/ext/mysql2/statement.c +++ b/ext/mysql2/statement.c @@ -51,7 +51,8 @@ static VALUE execute(VALUE self) MYSQL_STMT * stmt; Data_Get_Struct(self, MYSQL_STMT, stmt); - mysql_stmt_execute(stmt); + if(mysql_stmt_execute(stmt)) + rb_raise(cMysql2Error, "%s", mysql_stmt_error(stmt)); return self; } diff --git a/spec/mysql2/statement_spec.rb b/spec/mysql2/statement_spec.rb index d5670d3..a505860 100644 --- a/spec/mysql2/statement_spec.rb +++ b/spec/mysql2/statement_spec.rb @@ -50,4 +50,9 @@ describe Mysql2::Statement do stmt.prepare 'SELECT 1' stmt.execute.should == stmt end + + it "should raise an exception on error" do + stmt = @client.create_statement + lambda { stmt.execute }.should raise_error(Mysql2::Error) + end end