On Oct 7, 2:47 pm, File <[EMAIL PROTECTED]> wrote:
> Hey,
>
> I'm getting a really weird != conversion for sqlite3. Here's my code:
>
> require 'sequel'
>
> $db = Sequel.sqlite 'db/eve.db'
>
> @meta = 3
> $volumeMin = 5.0
> $volumeMax = 100.0
>
> puts $db[:invTypes].
> filter(:marketGroupID > 0).
> filter(:metaType <= @meta).
> filter(:volume => $volumeMin..$volumeMax).
>
> order_by(:categoryName, :groupName, :marketGroupID, :metaType, :typeName).sql
>
> => SELECT * FROM `invTypes` WHERE (((`marketGroupID` > 0) AND
> (`metaType` <= 3)) AND ((`volume` >= 5.0) AND (`volume` <= 100.0)))
> ORDER BY `categoryName`, `groupName`, `marketGroupID`, `metaType`,
> `typeName`
>
> puts $db[:invTypes].
> filter(:marketGroupID != 0).
> filter(:metaType <= @meta).
> filter(:volume => $volumeMin..$volumeMax).
>
> order_by(:categoryName, :groupName, :marketGroupID, :metaType, :typeName).sql
>
> => SELECT * FROM `invTypes` WHERE (('t' AND (`metaType` <= 3)) AND
> ((`volume` >= 5.0) AND (`volume` <= 100.0))) ORDER BY `categoryName`,
> `groupName`, `marketGroupID`, `metaType`, `typeName`
>
> What's with this "...('t' AND ..."???
>
> What am I doing wrong?
You are assuming that "filter(:marketGroupID != 0)" works. It does
not. Ruby doesn't let you define the != operator for any classes, and
even if it did, I'm sure there would already be a Symbol#!= method,
and Sequel doesn't override existing methods on core classes. In
ruby, ":marketGroupID != 0" is just "true", which is where you are
getting the 't'. To specify an SQL != operation in Sequel, you invert
the = operation. The = operation is specified using a hash, which is
inverted with Hash#~. So, to get what you want, you can use
"filter(~{:marketGroupID=>0})". I generally prefer to use
"exclude(:marketGroupID=>0)" in your case, as exclude does the
inversion for you.
Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---