On Tuesday, September 22, 2015 at 10:24:39 AM UTC-7, Nic wrote:
>
> *Here is my function:*
> def search_SQL_database(sku)
>   posts = @tbl.where(:"product code/sku" => sku)
>   if posts[:"product code/sku"] == sku
>     puts "The SKU was found"
>   else
>     puts "The SKU was not found"
>   end
> end
>
> *This is the line that isn't working:* if posts[:"product code/sku"] == 
> sku
>
> *Here is the error: 
> *.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sequel-4.26.0/lib/sequel/adapters/tinytds.rb:218:in
>  
> `fields': TinyTds::Error: An expression of non-boolean type specified in a 
> context where a condition is expected, near ')'. (Sequel::DatabaseError)
>
> If 'posts' is a hash, why can I not access it like other hashes? product 
> code/sku is the key and I am looking to compare the value of that key to 
> the value of 'sku'.
>
> *Thanks!*
>

posts isn't a Hash, it's a Sequel::Dataset.  You probably want something 
like:

 def search_SQL_database(sku)
  posts = @tbl.where(:"product code/sku" => sku).all
  if posts.empty?
    puts "The SKU was not found"
  else
    puts "The SKU was found"
  end

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to