Sean O'Halpin <sean.ohalpin / gmail.com> writes:

> On 11/4/05, Yohanes Santoso <ysantoso-rubytalk / dessyku.is-a-geek.org> wrote:
>> Just yesterday I was trying the ODBC DBD and encountered SEGV when I
>> call stored procedures in a certain way.
>
> I've been using it for 4-5 years now and never had a problem either
> with stability or performance. What exactly did you do?
>
> Regards,
>
> Sean


I'm using iodbc 3.52.2, freetds CVS (downloaded yesterday), ruby-odbc
0.996.

This is the error I'm getting. All data and exact query string has
been falsified since they contain sensitive info.


$ ruby1.8 create_account_odbc_trial.rb 
Connecting...
There are 1 connections
List of tid:
99999936
99999836
99999906
99999979
99999921
-------------------------
PAN=xxxxxxxxxxxxxxxxx
Connecting...
There are 2 connections
i=99999936
Connecting...
There are 3 connections
Done connecting...
i=99999836
Connecting...
There are 3 connections
Done connecting...
i=99999906
Connecting...
create_account_odbc_trial.rb:21: [BUG] Segmentation fault
ruby 1.8.2 (2005-04-11) [i386-linux]

aborted
$



I am also including the code that causes this SEGV. I am not trimming
down the code since the result is different, depending on the length
of the code.

E.g., if I have the following appended to line 75 and beyond:

exit
puts "hohohasijdoaifhkjhasdfkuh"
puts "hohohasijdoaifhkjhasdfkuh"
puts "hohohasijdoaifhkjhasdfkuh"
puts "hohohasijdoaifhkjhasdfkuh"
puts "hohohasijdoaifhkjhasdfkuh"
puts "hohohasijdoaifhkjhasdfkuh"
puts "hohohasijdoaifhkjhasdfkuh"
puts "hohohasijdoaifhkjhasdfkuh"
puts "hohohasijdoaifhkjhasdfkuh"


then the program completes gracefully.


YS.



     1	require 'odbc'
     2	
     3	DBAUTH=[....]

     5	PANS = [

    14	  ]
    15	
    16	$total_connection = 0
    17	
    18	def with_dbh
    19	  result = nil
    20	  puts "Connecting..."
    21	  ODBC.connect(*DBAUTH) {|dbh|
    22	    $total_connection += 1
    23	    begin
    24	      puts "There are #{$total_connection} connections"
    25	      dbh.autocommit = false # need this, otherwise dbh.transaction will cause an error
    26	      dbh.transaction{|dbh|
    27	        result = yield dbh
    28	      }
    29	    ensure
    30	      $total_connection -= 1
    31	    end
    32	  }
    33	  puts "Done connecting..."
    34	  result
    35	end
    36	
    37	
    38	def run_and_select_all(sql, *args)
    39	  with_dbh{|dbh|
    40	    dbh.run(sql, *args) {|stmt|
    41	      all = []
    42	      stmt.each{|row|
    43	        all << row
    44	      }
    45	      yield all
    46	    }
    47	  }
    48	end
    49	
    50	def run_and_select_one(sql, *args)
    51	  with_dbh{|dbh|
    52	    dbh.run(sql, *args) {|stmt|
    53	      row = stmt.fetch
    54	      yield row
    55	    }
    56	  }
    57	end
    58	
    59	run_and_select_all('select top 5 blablabla with one ?', FOO){|tids|
    60	  puts "List of tid:"
    61	  tids = tids.flatten
    62	  puts tids.join("\n")
    63	  puts "-"*25
    64	  PANS.each{|pan|
    65	    puts "PAN=#{pan}"
    66	    run_and_select_one('select * from cust where blablablabla with one ?', pan) {
    67	      tids.each{|tid|
    68	        i = tid.to_i
    69	        puts "i=#{i}"
    70	        run_and_select_one('execute some_sp ?', i) {}
    71	      }
    72	    }
    73	  }
    74	}