Beispiel #1
0
VALUE executeBlock(VALUE array)

{

   VALUE result      = Qnil,

         connection  = rb_ary_entry(array, 0),

         transaction = rb_ary_entry(array, 1),

         sql         = rb_ary_entry(array, 2),

         dialect     = INT2FIX(3),

         statement   = Qnil;



   statement = rb_statement_new(connection, transaction, sql, dialect);


   //result    = rb_execute_statement(statement);

   //rb_statement_close(statement);

   result = rb_ensure( executeStatementForExecuteBlock, statement, 
	   ensureStatementClosedForExecuteBlock, statement );
         

   return(result);

}
Beispiel #2
0
/**
 * This function provides the execute_immediate method for the Connection class.
 *
 * @param  self  A reference to the connection object to perform the execution
 *               through.
 * @param  sql   A reference to the SQL statement to be executed.
 *
 * @return  Always returns nil.
 *
 */
static VALUE executeOnConnectionImmediate(VALUE self, VALUE sql) {
  VALUE transaction = rb_transaction_new(self),
        set         = Qnil,
        results     = Qnil,
        array       = rb_ary_new(),
        dialect     = INT2FIX(3),
        statement   = rb_statement_new(self, transaction, sql, dialect);

  rb_ary_push(array, self);
  rb_ary_push(array, transaction);
  rb_ary_push(array, sql);
  rb_ary_push(array, statement);

  set = rb_rescue(executeBlock, array, executeRescue, array);
  if(set != Qnil) {
    if(TYPE(set) == T_DATA &&
       RDATA(set)->dfree == (RUBY_DATA_FUNC)resultSetFree) {
      rb_assign_transaction(set, transaction);
      if(rb_block_given_p()) {
        results = rb_rescue(executeImmediateBlock, set,
                            executeImmediateRescue, set);
      } else {
        results = set;
      }
    } else {
      rb_funcall(transaction, rb_intern("commit"), 0);
      results = set;
    }
  } else {
    rb_funcall(transaction, rb_intern("commit"), 0);
  }

  return(results);
}
Beispiel #3
0
static VALUE executeOnConnection(VALUE self, VALUE sql, VALUE transaction)

{

   VALUE results   = Qnil,

         statement = rb_statement_new(self, transaction, sql, INT2FIX(3));



   results = rb_execute_statement(statement);

   if(results != Qnil && rb_obj_is_kind_of(results, rb_cInteger) == Qfalse)

   {

      if(rb_block_given_p())

      {

         VALUE row  = rb_funcall(results, rb_intern("fetch"), 0),

               last = Qnil;

         

         while(row != Qnil)

         {

            last = rb_yield(row);

            row  = rb_funcall(results, rb_intern("fetch"), 0);

         }

         rb_funcall(results, rb_intern("close"), 0);

         results = last;

      }

   }

   rb_statement_close(statement);

         

   return(results);

}
Beispiel #4
0
/**
 * Create statement object
 *
 * @param  self  A reference to the connection object to perform the execution
 *               through.
 * @param  sql   A reference to the SQL statement to be executed.
 *
 * @return  Reference to the statement object.
 *
 */
VALUE createStatement(VALUE self, VALUE sql) {
  return rb_statement_new(self, sql);
}