[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ActiveRecord :conditions with .attributes

dkmd_nielsen

10/31/2008 5:55:00 PM

Thanks for any help and suggestions. I'm having troubles with the
following not working. It generates a "miss value for :OCRACR in
OCRACR = :OCRACR..." error.

slct = "OCRACR = :OCRACR and MSG = :MSG and KEYCODE = :KEYCODE and
VERSION = :VERSION and DEPTH = :DEPTH "

unq_rows = Entry.find_by_sql(
"select distinct #{flds} from entries "
).each {|e|
o = Entry.find(:all,:conditions => [slct,e.attributes])
puts o.length
}

When I do "pp e.attributes", it displays the following hash:

{"OCRACR"=>"O", "MSG"=>"", "KEYCODE"=>"212260", "VERSION"=>"01",
"DEPTH"=>"001"}

Shouldn't the find :conditions be ok? The slct string appears
formatted ok. The .attributes hash appears to match the :conditions
string. I'm at a loss for what I am doing incorrectly.

Thanks again,
dvn
2 Answers

dkmd_nielsen

10/31/2008 6:21:00 PM

0

On Oct 31, 12:54 pm, dkmd_nielsen <d...@cmscms.com> wrote:
> Thanks for any help and suggestions.  I'm having troubles with the
> following not working.  It generates a "miss value for :OCRACR in
> OCRACR = :OCRACR..." error.
>
> slct = "OCRACR = :OCRACR and MSG = :MSG and KEYCODE = :KEYCODE and
> VERSION = :VERSION and DEPTH = :DEPTH "
>
> unq_rows = Entry.find_by_sql(
>    "select distinct #{flds} from entries "
> ).each {|e|
>    o = Entry.find(:all,:conditions => [slct,e.attributes])
>    puts o.length
>
> }
>
> When I do "pp e.attributes", it displays the following hash:
>
> {"OCRACR"=>"O", "MSG"=>"", "KEYCODE"=>"212260", "VERSION"=>"01",
> "DEPTH"=>"001"}
>
> Shouldn't the find :conditions be ok?  The slct string appears
> formatted ok.  The .attributes hash appears to match the :conditions
> string.  I'm at a loss for what I am doing incorrectly.
>
> Thanks again,
> dvn

And I'll follow this up with the following that does function:

unq_rows = Entry.find_by_sql(
"select distinct #{flds} from entries "
).each {|e|
slct = ""
e.attributes.each {|key,value|
slct << "#{key} = '#{value}' and " if key != 'id'
}
o = Entry.find(:all,:conditions => slct[0,slct.length-4] )
puts "#{e.KEYCODE} #{o.length}"
}

I'm sure the error is related to :KEYCODE versus 'KEYCODE' in the hash
key.

Let me ask a simpler question: What is the easiest method for getting
the COUNT of rows for each distinct set of column values. In the
above case, I want to get the count of rows for each unique
combination of column values. Is there a simpler sql solution?

Thanks again for any responses,
dvn

The Nice Mean Man

11/3/2010 7:17:00 AM

0

On Nov 3, 2:29 am, Rango <drphrankenbe...@yahoo.com> wrote:
> On Nov 2, 10:19 pm, The Nice Mean Man <hitherand...@aol.com> wrote:
>
> > On Nov 3, 1:04 am, Rango <drphrankenbe...@yahoo.com> wrote:
>
> > > I've got the very same photo, albeit as a poster. Same size even. I
> > > doubt this is worth $500, let alone thousands...
>
> > > Opinions please:http://www.wabi.tv/news/15274/beatles-vintage-photo-found-i......
>
> > Jealously will buy you precious little around here, Bub....
>
> > The Nice Mean Man
>
> I'm old enough to know not to allow myself to be baited, but how in
> the hell is jealousy involved here?
>
> These people are foolish, and they muddy the waters both on the
> collectors' front and in terms of history.
>
> That un-retouched version of the Pepper cover photo has been floating
> around for decades amongst fans.
> To think someone is going to try to bilk others into paying an
> inflated price for it because someone says
> it's rare is criminal.

You sound a little too comfortable with a rush to judgment. Almost
with an air of wishful thinking, I should suppose. Couldn’t help but
notice. Sorry if I hit a soft spot, but I call ‘em as I see ‘em...



The Nice Mean Man