Skip to content

multiple raised errors ... only last one captured #78

Open
@ghost

Description

I have an app that uses extensive stored procs and with a few tweaks, tiny_tds works great (thanks!). I do have one issue that if a proc has multiple raised errors (happens a lot when procs call procs), tiny_tds only captures the last error. I believe it's due to the
way tinytds_msg_handler calls rb_tinytds_raise_error which creates a new error instead of buffering them up.

I would love to submit a patch but I'm hitting the wall on my ruby internals knowledge (pointers welcome, I'm more than happy to tackle this if someone can point me in a halfway decent direction).

I do have this simple test case that displays the problem:

require 'test_helper'

class MultiErrorsTest < ActiveSupport::TestCase

  test 'should have multi errors' do

    @client = TinyTds::Client.new( 
      :dataserver => 'DEV', 
      :username => 'sa',
      :password => 'xxxxx',
      :tds_version => '42',
      :database => 'tempdb' 
    )

   begin
     @client.execute( 'DROP PROCEDURE inner_proc_test' ).do
     @client.execute( 'DROP PROCEDURE outer_proc_test' ).do
   rescue
     # do nothing ... we don't care about drop warnings
   end

   inner_proc_test  = @client.execute( "create procedure inner_proc_test as raiserror 20014 'Inner Proc Error'" ).do
   outer_proc_test  = @client.execute( "create procedure outer_proc_test as exec inner_proc_test raiserror 20014 'Outer Proc Error'" ).do

   begin 
     results = @client.execute( 'exec outer_proc_test' ).do
   rescue Exception => e
     assert_match( /inner/, e.message )
   end

  end
end

This will fail because e is just the error from the outer_proc_test raise .. inner_proc_test raise is lost (and leaked?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions