Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

On Booleans And Database Portability

DZone's Guide to

On Booleans And Database Portability

·
Free Resource
From Coda Hale: http://blog.codahale.com/2006/04/20/on-booleans-and-database-portability/.

On booleans and database portability

Oh, booleans. Simplest and most elusive of database types. How to specify you? Y and N? T and F? 0 or NULL and anything else? If only we knew…

When working on a Rails app that uses different databases (say, SQLite for development/testing and MySQL for production), be sure that your conditions clauses aren’t assuming a particular form of boolean representation.

This will return nothing in SQLite:

@monkeys = Monkey.find(:all,
  :conditions => 'rabid = 0')

But it’ll work in MySQL.
A Solution

Autogenerate that sucker!

@monkeys = Monkey.find(:all,
  :conditions => ['rabid = ?', false])

Yay! 
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}