I''m using SQLite3, but have been a longtime MySQL user. I have been wracking my brain over why I was getting a "0" result for a count when it should be "10". The statement.... Table.count (:conditions => "approved = 0") The result in SQLite3: 0 The result in MySQL: 10 The corrected (I think) statement for SQLite: Table.count (:conditions => "approved = ''f'' ") I am surprised and wonder why SQLite using the ''f'' and ''t'' nomenclature when ''0'' and ''1'' have worked so well.... Since this specificity would rule out me easily switching my DB back to SQL, how can I write my command to use True and False? Thanks a ton... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I did solve my problem... Table.count (:conditions => {approved => false} ) On Feb 8, 3:20 pm, yachtman <carson.c...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m using SQLite3, but have been a longtime MySQL user. I have been > wracking my brain over why I was getting a "0" result for a count when > it should be "10". > > The statement.... > Table.count (:conditions => "approved = 0") > > The result in SQLite3: 0 > The result in MySQL: 10 > > The corrected (I think) statement for SQLite: > Table.count (:conditions => "approved = ''f'' ") > > I am surprised and wonder why SQLite using the ''f'' and ''t'' > nomenclature when ''0'' and ''1'' have worked so well.... > > Since this specificity would rule out me easily switching my DB back > to SQL, how can I write my command to use True and False? > > Thanks a ton...--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yachtman wrote:> I did solve my problem... > > Table.count (:conditions => {approved => false} )Or this will work as well: Table.count(:conditions => [ "approved = ?", true ]) Putting the value in the conditions string doesn''t gives Rails a chance to process it. Instead it just goes directly into the WHERE clause as is. Both the hash version and the value substitution using the question mark version allow Rails to process and properly sanitize the SQL. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Robert Walker wrote:> Table.count(:conditions => [ "approved = ?", true ])Well I meant Table.count(:conditions => [ "approved = ?", false ]), but you get the idea. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Robert, Thanks for the reply. I imagine in this case, since I am only counting based on a boolean value, there should be no worry about sanitization? On Feb 8, 3:54 pm, Robert Walker <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Robert Walker wrote: > > Table.count(:conditions => [ "approved = ?", true ]) > > Well I meant Table.count(:conditions => [ "approved = ?", false ]), but > you get the idea. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 9, 2009, at 9:52 PM, yachtman wrote:> Robert, > > Thanks for the reply. > > I imagine in this case, since I am only counting based on a boolean > value, there should be no worry about sanitization? > > On Feb 8, 3:54 pm, Robert Walker <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> Robert Walker wrote: >>> Table.count(:conditions => [ "approved = ?", true ]) >> >> Well I meant Table.count(:conditions => [ "approved = ?", false ]), >> but >> you get the idea. >> --You''re not doing [''approved = ?'',false] for the sanitization as much as for letting the database adapter fill in its own notion of what value it uses for false. Even if you were doing more than counting, you have control of the inputs so there''s no SQL injection here. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
seems to work. I think rails is doing its thing either way.>> issue = Issue.count(:conditions => {:published => false})=> 3 [4;36;1mSQL (0.000348) [0m [0;1mSELECT count(*) AS count_all FROM `issues` WHERE (`issues`.`published` = 0) [0m On Mon, Feb 9, 2009 at 9:14 PM, Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org>wrote:> > On Feb 9, 2009, at 9:52 PM, yachtman wrote: > > Robert, > > > > Thanks for the reply. > > > > I imagine in this case, since I am only counting based on a boolean > > value, there should be no worry about sanitization? > > > > On Feb 8, 3:54 pm, Robert Walker <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > >> Robert Walker wrote: > >>> Table.count(:conditions => [ "approved = ?", true ]) > >> > >> Well I meant Table.count(:conditions => [ "approved = ?", false ]), > >> but > >> you get the idea. > >> -- > > > You''re not doing [''approved = ?'',false] for the sanitization as much > as for letting the database adapter fill in its own notion of what > value it uses for false. Even if you were doing more than counting, > you have control of the inputs so there''s no SQL injection here. > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > > > > >-- Available for Ruby on Rails development opportunities --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---