abnormal program termination with dynamic data, but not with fixed data

Discussion in 'Ruby' started by walter@mwsewall.com, Jul 13, 2003.

  1. Guest

    hi everyone. I am stumped!

    I have code that is part of a simple persistent object manager.
    The system takes an object, builds an update statement, and
    builds the parameter list.

    I keep getting an abnormal program termination. Hoever as you
    can see in the modified code segment below, I can run the same query
    with the same data that is hand keyed and it works fine.

    Below, you can see that the dynamically created arrays and the
    hand keyed one are identical, but one always aborts and one works
    fine. I am running ruby 1.8 on windows 2000 using the pragmatic
    programmers installer.

    Does anyone have any ideas?


    Walt



    This one ends in a segmentation fault
    ## original code ##
    def update(obj)
    raise SpomDBClosedException.new if closed?
    executeCount = 0
    dbObject = @spom.getObjectMapping(obj.class)
    dbHandle.prepare(dbObject.updateSQL) do |sth|
    params = []
    dbObject.nonKeyFields.each{|field| params <<
    field.toDB(obj)}
    dbObject.keyFields.each{|field| params
    <<field.toDB(obj)}
    executeCount = sth.execute(*params)
    end
    executeCount
    end
    ## end original code ##



    this modified version works. The main difference is that I am
    executing the update with a fixed array, not the dynamically computed

    array. It also has some code to compare the dynamically computed
    array, and the fixed one. It appears that they are identical,
    however,
    the dynamically created one always ends with :

    C:/ruby/lib/ruby/site_ruby/1.8/DBD/ODBC/ODBC.rb:202: [BUG]
    Segmentation fault
    ruby 1.8.0 (2003-05-26) [i386-mswin32]


    abnormal program termination


    ## modified code ##
    def update(obj)
    raise SpomDBClosedException.new if closed?
    executeCount = 0
    dbObject = @spom.getObjectMapping(obj.class)
    dbHandle.prepare(dbObject.updateSQL) do |sth|
    params = []
    dbObject.nonKeyFields.each{|field| params <<
    field.toDB(obj)}
    dbObject.keyFields.each{|field| params
    <<field.toDB(obj)}

    puts "computed data"
    puts compData = params.join(",")
    compClasses = params.collect{|i| i.class}
    puts compClasses.join(",")

    keyed = [Date.today, 'aaa', 'POIL', 'line1', 'line2', 'city', 'st',
    'zip', 'country', 'p', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    '10', Date.today, '-' , '', '', '', '', '', '', '', 20, 21, 'sic',
    'disp', 'oth3', "31", "32", "33", "34", "35", 'POIL', 999999]

    puts ""
    puts "hand keyed data"
    puts keyedData = keyed.join(",")
    keyedClasses = keyed.collect{|i| i.class}
    puts keyedClasses.join(",")

    puts ""
    puts "size (#{params.size}) same? #{params.size == keyed.size}"
    puts "raw data same? #{params == keyed}"
    puts "joined data same? #{compData == keyedData}"
    puts "raw classes same #{compClasses == keyedClasses}"

    #note nothing prints
    params.each_with_index do |p, index|
    puts "******* #{index} does NOT equal data" if p != keyed[index]
    puts "******* #{index} does NOT equal class" if p.class !=
    keyed[index].class
    end

    params = keyed #NOTE: replace dynamic data with keyed data

    executeCount = sth.execute(*params)
    end
    executeCount
    end

    ## end modified code ##

    ******************
    ***** OUTPUT *****
    ******************

    computed data
    2003-07-
    12,aaa,POIL,line1,line2,city,st,zip,country,p,1,2,3,4,5,6,7,8,9,10,200
    3-07-12,-,,,,,,,,20,21,sic,disp,oth3,31,32,33,34,35,POIL,999999
    Date,String,String,String,String,String,String,String,String,String,St
    ring,String,String,String,String,String,String,String,String,String,Da
    te,String,String,String,String,String,String,String,String,Fixnum,Fixn
    um,String,String,String,String,String,String,String,String,String,Fixn
    um

    hand keyed data
    2003-07-
    12,aaa,POIL,line1,line2,city,st,zip,country,p,1,2,3,4,5,6,7,8,9,10,200
    3-07-12,-,,,,,,,,20,21,sic,disp,oth3,31,32,33,34,35,POIL,999999
    Date,String,String,String,String,String,String,String,String,String,St
    ring,String,String,String,String,String,String,String,String,String,Da
    te,String,String,String,String,String,String,String,String,Fixnum,Fixn
    um,String,String,String,String,String,String,String,String,String,Fixn
    um

    size (41) same? true
    raw data same? true
    joined data same? true
    raw classes same true

    *****************************************************
    Walter Szewelanczyk
    IS Director
    M.W. Sewall & CO. email :
    259 Front St. Phone : (207) 442-7994 x 128
    Bath, ME 04530 Fax : (207) 443-6284
    *****************************************************
     
    , Jul 13, 2003
    #1
    1. Advertising

  2. Sean O'Dell Guest

    "Sean O'Dell" <> wrote in message
    news:HiBRa.265$...
    > <> wrote in message
    > news:3F1094D4.21763.2AFC3C8@localhost...
    > > hi everyone. I am stumped!
    > >
    > > I have code that is part of a simple persistent object manager.
    > > The system takes an object, builds an update statement, and
    > > builds the parameter list.
    > >
    > > I keep getting an abnormal program termination. Hoever as you
    > > can see in the modified code segment below, I can run the same query
    > > with the same data that is hand keyed and it works fine.
    > >
    > > Below, you can see that the dynamically created arrays and the
    > > hand keyed one are identical, but one always aborts and one works
    > > fine. I am running ruby 1.8 on windows 2000 using the pragmatic
    > > programmers installer.
    > >
    > > Does anyone have any ideas?
    > >
    > >
    > > Walt
    > >
    > >
    > >
    > > This one ends in a segmentation fault
    > > ## original code ##
    > > def update(obj)
    > > raise SpomDBClosedException.new if closed?
    > > executeCount = 0
    > > dbObject = @spom.getObjectMapping(obj.class)
    > > dbHandle.prepare(dbObject.updateSQL) do |sth|
    > > params = []
    > > dbObject.nonKeyFields.each{|field| params <<
    > > field.toDB(obj)}
    > > dbObject.keyFields.each{|field| params
    > > <<field.toDB(obj)}
    > > executeCount = sth.execute(*params)
    > > end
    > > executeCount
    > > end
    > > ## end original code ##
    > >
    > >
    > >
    > > this modified version works. The main difference is that I am
    > > executing the update with a fixed array, not the dynamically computed
    > >
    > > array. It also has some code to compare the dynamically computed
    > > array, and the fixed one. It appears that they are identical,
    > > however,
    > > the dynamically created one always ends with :
    > >
    > > C:/ruby/lib/ruby/site_ruby/1.8/DBD/ODBC/ODBC.rb:202: [BUG]
    > > Segmentation fault
    > > ruby 1.8.0 (2003-05-26) [i386-mswin32]
    > >
    > >
    > > abnormal program termination
    > >
    > >
    > > ## modified code ##
    > > def update(obj)
    > > raise SpomDBClosedException.new if closed?
    > > executeCount = 0
    > > dbObject = @spom.getObjectMapping(obj.class)
    > > dbHandle.prepare(dbObject.updateSQL) do |sth|
    > > params = []
    > > dbObject.nonKeyFields.each{|field| params <<
    > > field.toDB(obj)}
    > > dbObject.keyFields.each{|field| params
    > > <<field.toDB(obj)}
    > >
    > > puts "computed data"
    > > puts compData = params.join(",")
    > > compClasses = params.collect{|i| i.class}
    > > puts compClasses.join(",")
    > >
    > > keyed = [Date.today, 'aaa', 'POIL', 'line1', 'line2', 'city', 'st',
    > > 'zip', 'country', 'p', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    > > '10', Date.today, '-' , '', '', '', '', '', '', '', 20, 21, 'sic',
    > > 'disp', 'oth3', "31", "32", "33", "34", "35", 'POIL', 999999]
    > >
    > > puts ""
    > > puts "hand keyed data"
    > > puts keyedData = keyed.join(",")
    > > keyedClasses = keyed.collect{|i| i.class}
    > > puts keyedClasses.join(",")
    > >
    > > puts ""
    > > puts "size (#{params.size}) same? #{params.size == keyed.size}"
    > > puts "raw data same? #{params == keyed}"
    > > puts "joined data same? #{compData == keyedData}"
    > > puts "raw classes same #{compClasses == keyedClasses}"
    > >
    > > #note nothing prints
    > > params.each_with_index do |p, index|
    > > puts "******* #{index} does NOT equal data" if p != keyed[index]
    > > puts "******* #{index} does NOT equal class" if p.class !=
    > > keyed[index].class
    > > end
    > >
    > > params = keyed #NOTE: replace dynamic data with keyed data
    > >
    > > executeCount = sth.execute(*params)
    > > end
    > > executeCount
    > > end
    > >
    > > ## end modified code ##
    > >
    > > ******************
    > > ***** OUTPUT *****
    > > ******************
    > >
    > > computed data
    > > 2003-07-
    > > 12,aaa,POIL,line1,line2,city,st,zip,country,p,1,2,3,4,5,6,7,8,9,10,200
    > > 3-07-12,-,,,,,,,,20,21,sic,disp,oth3,31,32,33,34,35,POIL,999999
    > > Date,String,String,String,String,String,String,String,String,String,St
    > > ring,String,String,String,String,String,String,String,String,String,Da
    > > te,String,String,String,String,String,String,String,String,Fixnum,Fixn
    > > um,String,String,String,String,String,String,String,String,String,Fixn
    > > um
    > >
    > > hand keyed data
    > > 2003-07-
    > > 12,aaa,POIL,line1,line2,city,st,zip,country,p,1,2,3,4,5,6,7,8,9,10,200
    > > 3-07-12,-,,,,,,,,20,21,sic,disp,oth3,31,32,33,34,35,POIL,999999
    > > Date,String,String,String,String,String,String,String,String,String,St
    > > ring,String,String,String,String,String,String,String,String,String,Da
    > > te,String,String,String,String,String,String,String,String,Fixnum,Fixn
    > > um,String,String,String,String,String,String,String,String,String,Fixn
    > > um
    > >
    > > size (41) same? true
    > > raw data same? true
    > > joined data same? true
    > > raw classes same true

    >
    > Which line is line 202?


    Actually, what is the entire backtrace? What line in your code is causing
    the failure?

    Sean O'Dell
     
    Sean O'Dell, Jul 17, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. R6_2003
    Replies:
    1
    Views:
    539
    Peter van Merkerk
    Oct 23, 2003
  2. Mahmood Ahmad
    Replies:
    3
    Views:
    574
    Mahmood Ahmad
    Feb 22, 2004
  3. John Pote
    Replies:
    2
    Views:
    480
    John Pote
    Nov 11, 2004
  4. Hugh
    Replies:
    2
    Views:
    412
  5. PyDenis
    Replies:
    16
    Views:
    829
    Chris Mellon
    Mar 15, 2006
Loading...

Share This Page