On Saturday, May 2, 2015 at 11:27:25 AM UTC-7, Bernhard Weichel wrote:
>
> Hi Jeremy,
>
> thanks for squeal, I am using it in a bunch of projects for charity and 
> NGO organizatins. I contact you about a problem which I think is a mistake 
> of mine, but I cannot find where.
>
> If I create a dataset based on a raw sql, I cannot apply further filters 
> to this dataset
>
> [17] pry(main)> ds1 = vrdb.database[:courses]
>
> => #<Sequel::SQLite::Dataset: "SELECT * FROM `courses`">
>
> [18] pry(main)> ds2 = ds1.where(:id => "2150105")
>
> => #<Sequel::SQLite::Dataset: "SELECT * FROM `courses` WHERE (`id` = 
> '2150105')">
>
> [19] pry(main)> ds2.sql
>
> => "SELECT * FROM `courses` WHERE (`id` = '2150105')"
>
>
> The same with raw sql
>
>
> [20] pry(main)> ds3 = vrdb.database["select * from courses"]
>
> => #<Sequel::SQLite::Dataset: "select * from courses">
>
> [21] pry(main)> ds4 = ds3.where(:id => "2150105")
>
> => #<Sequel::SQLite::Dataset: "select * from courses">
>
> [22] pry(main)> ds4.sql
>
> => "select * from courses"
>
>
>
> Could you please give me a hint what happens here?
>
>
> Thanks in advance
>
> Bernhard
>

This is expected. If you provide raw SQL, you can't further modify the
dataset.  By design, Sequel doesn't parse SQL, so it can't figure out
how to modify it.  If you want to be able to modify a dataset with
raw SQL, you need to use a subselect using Dataset#from_self:

irb(main):001:0> ds = DB["select * from courses"]
=> #<Sequel::Mock::Dataset: "select * from courses">
irb(main):002:0> ds2 = ds.from_self
=> #<Sequel::Mock::Dataset: "SELECT * FROM (select * from courses) AS t1">
irb(main):003:0> ds3 = ds2.where(:id=>'2150105')
=> #<Sequel::Mock::Dataset: "SELECT * FROM (select * from courses) AS t1 
WHERE (id = '2150105')">

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