ext/FireRubyException.c in rubyfb-0.5.9 vs ext/FireRubyException.c in rubyfb-0.6

- old
+ new

@@ -53,12 +53,12 @@ rb_raise(rb_eException, "Invalid message parameter specified for exception."); } rb_iv_set(self, "@message", message); - rb_iv_set(self, "@sql_code", 0); - rb_iv_set(self, "@db_code", 0); + rb_iv_set(self, "@sql_code", INT2NUM(0)); + rb_iv_set(self, "@db_code", INT2NUM(0)); return(self); } @@ -102,23 +102,35 @@ return(rb_iv_get(self, "@message")); } /** - * This function decodes the contents of a Firebird ISC_STATUS array into a - * String object. + * This function provides a means to programmatically create a new instance of + * the FireRubyException class. * - * @param status A pointer to the status array to be decoded. - * @param prefix An initial message that may be added to the exception as - * part of the decoding. Ignored if it is NULL or has zero - * length. + * @param message A string containing the error message for the exception. * - * @return A reference to the full decode error message string. + * @return A reference to a newly created FireRubyException object. * */ -VALUE decodeException(const ISC_STATUS *status, const char *prefix) { - VALUE message = rb_str_new2(""), +VALUE rb_fireruby_exception_new(const char *message) { + return rb_funcall(cFireRubyException, rb_intern("new"), 1, rb_str_new2(message)); +} + + +/** + * This function raises a new FireRuby exception. + * + * @param status A pointer to the Firebird status vector containing the error + * details. + * @param message A string containing a message to be prefixed to the error + * text generated by the decoding. + * + */ +void rb_fireruby_raise(const ISC_STATUS *status, const char *prefix) { + VALUE exception = rb_exc_new2(cFireRubyException, ""), + message = rb_str_new2(""), eol = rb_str_new2("\n"); char text[512]; int sqlCode = isc_sqlcode(status), dbCode = 0; const ISC_STATUS **ptr = &status; @@ -147,39 +159,13 @@ rb_str_concat(message, rb_str_new2(text)); sprintf(text, "Firebird Code = %d\n", dbCode); rb_str_concat(message, rb_str_new2(text)); } - return(message); -} - - -/** - * This function provides a means to programmatically create a new instance of - * the FireRubyException class. - * - * @param message A string containing the error message for the exception. - * - * @return A reference to a newly created FireRubyException object. - * - */ -VALUE rb_fireruby_exception_new(const char *message) { - return rb_funcall(cFireRubyException, rb_intern("new"), 1, rb_str_new2(message)); -} - - -/** - * This function raises a new FireRuby exception. - * - * @param status A pointer to the Firebird status vector containing the error - * details. - * @param message A string containing a message to be prefixed to the error - * text generated by the decoding. - * - */ -void rb_fireruby_raise(const ISC_STATUS *status, const char *message) { - VALUE text = decodeException(status, message); - rb_raise(cFireRubyException, "%s", StringValuePtr(text)); + rb_iv_set(exception, "@message", message); + rb_iv_set(exception, "@sql_code", INT2NUM(sqlCode)); + rb_iv_set(exception, "@db_code", INT2NUM(dbCode)); + rb_exc_raise(exception); } /** * This function creates the FireRubyException class within the Ruby environment