Query SQLite looking for boolean records

rubyToday I have needed to ask an SQLite DB to get some records with a field set to true, and all my first attempts to do it have been failed. Finally I have achieved it, and I would like to share this little achievement 🙂

NOT working:

Model.find(:all, :conditions => 'field = true')

NOT working:

Model.find(:all, :conditions => 'field = "true"')

NOT working:

Model.find(:all, :conditions => 'field = 1')

NOT working:

Model.find(:all, :conditions => 'field = "1"')

and finally working:

Model.find(:all, :conditions => 'field = "t"')

The solution has consisted on looking at DB level, which is the real data stored on it. Cheers 🙂

Acerca de Ibon

Me gusta salir a correr, pasear, andar en bici y patinar :) Si no te saludo es que, o no llevo las gafas puestas o que tengo mal día. Pero no te lo tomes a mal: seguro que mañana estoy de mejor humor ;) Me gusta escuchar algunos podcasts sobre divulgación científica: Coffee Break, CienciaES, y algunos otros que divulgan buen karma. Creo en los principios que fundamentan el Software Libre, y me parece una gran herramienta para conseguir una sociedad mas justa.
Esta entrada fue publicada en Programación y etiquetada , , , , , , , . Guarda el enlace permanente.

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.