From 7e95b543c95f191e7f3e09afb1588adb4c87b39c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 8 Jul 2010 16:05:50 -0700 Subject: [PATCH] execute is defined on statmenet --- ext/mysql2/statement.c | 15 +++++++++++++++ spec/mysql2/statement_spec.rb | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/ext/mysql2/statement.c b/ext/mysql2/statement.c index 3eb1acf..a12ee06 100644 --- a/ext/mysql2/statement.c +++ b/ext/mysql2/statement.c @@ -42,6 +42,20 @@ static VALUE field_count(VALUE self) return UINT2NUM(mysql_stmt_field_count(stmt)); } +/* call-seq: stmt.execute + * + * Executes the current prepared statement, returns +stmt+. + */ +static VALUE execute(VALUE self) +{ + MYSQL_STMT * stmt; + Data_Get_Struct(self, MYSQL_STMT, stmt); + + mysql_stmt_execute(stmt); + + return self; +} + void init_mysql2_statement() { cMysql2Statement = rb_define_class_under(mMysql2, "Statement", rb_cObject); @@ -49,4 +63,5 @@ void init_mysql2_statement() rb_define_method(cMysql2Statement, "prepare", prepare, 1); rb_define_method(cMysql2Statement, "param_count", param_count, 0); rb_define_method(cMysql2Statement, "field_count", field_count, 0); + rb_define_method(cMysql2Statement, "execute", execute, 0); } diff --git a/spec/mysql2/statement_spec.rb b/spec/mysql2/statement_spec.rb index f66f424..d5670d3 100644 --- a/spec/mysql2/statement_spec.rb +++ b/spec/mysql2/statement_spec.rb @@ -44,4 +44,10 @@ describe Mysql2::Statement do stmt.prepare 'SELECT 1' stmt.field_count.should == 1 end + + it "should let us execute our statement" do + stmt = @client.create_statement + stmt.prepare 'SELECT 1' + stmt.execute.should == stmt + end end