On Feb 10, 10:00 am, Cheese  Lottery <[email protected]> wrote:
> Hello,
>
> I've got some sqlite databases with boolean columns that use 1 and 0
> as true and false. Sequel can read this just fine. When I write to a
> database with something like DB[:some_table].update(:some_column =>
> boolean) Sequel will write the boolean as 't' or 'f', which I don't
> want. Of course I could explicitly write 1 or 0, but it would be nice
> if I did not have to. So this is what I wrote, to be required after
> requiring sequel:
>
> module Sequel
>   module SQLite
>     module DatasetMethods
>       BOOL_TRUE = '1'.freeze
>       BOOL_FALSE = '0'.freeze
>     end
>
>     class Dataset < Sequel::Dataset
>       def literal_true
>         BOOL_TRUE
>       end
>
>       def literal_false
>         BOOL_FALSE
>       end
>     end
>   end
> end
>
> It seems to work so far in a few minutes worth of testing. Is there a
> better way to do this?

That's probably the best way.  The reason Sequel doesn't operate that
way by default, besides historical behavior, is the SQLite adapter
does not do type translation on values SQLite stores as integers.  If
you have a boolean column and you put in an integer value, SQLite
stores it as an integer, so upon retrieval, you would get a 1 or 0
instead of true or false.

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.

Reply via email to