1

i have encountered an error while trying run an sinatra application. I tried googling it and nothing came up. If you guys can offer any advice on how to fix it or what i am doing wrong it will be great help.

Part of the Code that is erroring out

   def logTownDeltas!(newDate)
        deltas = []

        oldTowns = @db[:towns].filter { data_timestamp < newDate }
        currentTowns = @db[:towns].except(oldTowns)

        destroyedTownIDs = oldTowns.select(:town_id).except(currentTowns.select(:town_id)).collect { |d| d[:town_id] }
        createdTownIDs = currentTowns.select(:town_id).except(oldTowns.select(:town_id)).collect { |c| c[:town_id] }

        alteredTowns = Hash.new
        currentTowns.each { |town|

        }

ERROR

    C:/Ruby22/lib/ruby/gems/2.2.0/gems/sequel-4.29.0/lib/sequel/dataset/query.rb:119:in `except': EXCEPT not supported (Sequel::InvalidOperation)
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:107:in `logTownDeltas!'
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:93:in `parseTownData'
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:45:in `block (2 levels) in run!'
    from C:/Ruby22/lib/ruby/2.2.0/open-uri.rb:154:in `open_uri'
    from C:/Ruby22/lib/ruby/2.2.0/open-uri.rb:716:in `open'
    from C:/Ruby22/lib/ruby/2.2.0/open-uri.rb:34:in `open'
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:44:in `block in run!'
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:41:in `each'
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:41:in `run!'
    from data_syndicator.rb:17:in `<main>'

insert into database

 destroyedTownIDs.each { |d|
            t = oldTowns.filter(:town_id => d).first
            @db[:town_deltas].insert(
                :happened_at => newDate,
                :town_id => d,
                :owner_id => t[:owner_id],
                :name => t[:name],
                :population => 0,
                :is_capital => 0,
                :is_alliance_capital => 0)
        }


        createdTownIDs.each { |c|
            t = currentTowns.filter(:town_id => c).first
            @db[:town_deltas].insert(
                :happened_at => newDate,
                :town_id => c,
                :owner_id => t[:owner_id],
                :name => t[:name],
                :population => t[:population],
                :is_capital => t[:is_capital],
                :is_alliance_capital => t[:is_alliance_capital])
        }

Link to full source just in case

kodabear
  • 340
  • 1
  • 14
  • 1
    I am using a MySql database – kodabear Jan 05 '16 at 02:50
  • MySql doesn't support EXCEPT syntax. See http://stackoverflow.com/questions/16092353/error-when-using-except-in-a-query – Harper Maddox Jan 05 '16 at 03:55
  • 1
    yeah i saw that after i posted this right now i am trying to figure out what i would out in place of EXCEPT – kodabear Jan 05 '16 at 03:59
  • 1
    When i change it to where i start getting C:/Ruby22/lib/ruby/gems/2.2.0/gems/sequel-4.29.0/lib/sequel/adapters/mysql.rb:175:in `query': Mysql::Error: Subquery returns more than 1 row (Sequel::DatabaseError) – kodabear Jan 05 '16 at 04:33

1 Answers1

3

Try this:

def logTownDeltas!(newDate)
  deltas = []
  currentTowns = @db[:towns].filter { data_timestamp >= newDate }

  destroyedTownIDs = @db[:towns].select(:town_id).filter { data_timestamp < newDate }.collect { |d| d[:town_id] }
  createdTownIDs = @db[:towns].select(:town_id).filter { data_timestamp >= newDate }.collect { |c| c[:town_id] }

        alteredTowns = Hash.new
        currentTowns.each { |town|

        }
Harper Maddox
  • 540
  • 4
  • 8
  • 1
    Thank you very much this helped – kodabear Jan 05 '16 at 04:53
  • 1
    I ran into a problem my next line of code after it finds the destroyedTownIDs and createdTownIDs it input the database only destroyedTownIDs has 0 pop and then do the createdTownIDs but right now its creating 0 pop data for every town that was in the database the day before. I put the coding that input the data into the database above – kodabear Jan 19 '16 at 23:43