Esempio n. 1
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);
}
Esempio n. 2
0
/**
 * This function provides the start_transaction method for the Database class.
 *
 * @param  self  A reference to the Database object to start the transaction
 *               on.
 *
 * @return  A reference to a Transaction object or nil if a problem occurs.
 *
 */
static VALUE startConnectionTransaction(VALUE self) {
  VALUE result = rb_transaction_new(self);

  if(rb_block_given_p()) {
    result = rb_rescue(startTransactionBlock, result,
                       startTransactionRescue, result);
  }

  return(result);
}
Esempio n. 3
0
static VALUE executeOnConnectionImmediate(VALUE self, VALUE sql)

{

   VALUE transaction = rb_transaction_new(self),

         set         = Qnil,

         results     = Qnil,

         array       = rb_ary_new();



   rb_ary_push(array, self);

   rb_ary_push(array, transaction);

   rb_ary_push(array, sql);
   //fprintf( stderr, "running in own transaction %s\n", STR2CSTR(StringValue(sql)) );

   set = rb_rescue(executeBlock, array, executeRescue, transaction);

   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())

         {
			 //fprintf( stderr, "block exec\n" );

            results = rb_rescue(executeImmediateBlock, set,

                                executeImmediateRescue, set);

         }

         else

         {
			//fprintf( stderr, "plain results?\n" );
            results = set;

         }

      }

      else

      {
		  //fprintf( stderr, "committing immediate transaction %s\n", STR2CSTR(StringValue(sql)) );

		 // force commit will ensure the transaction is committed or rollback, in either
		 // case it needs to be removed as it is now defunct
         rb_funcall(transaction, rb_intern("forceCommit"), 0); 

         results = set;

      }

   }

   else

   {
	   //fprintf( stderr, "committing immediate transaction %s\n", STR2CSTR(StringValue(sql)) );

      rb_funcall(transaction, rb_intern("forceCommit"), 0);

   }



   return(results);

}