Find not working

S

Shandy Nantz

Hi all,

I have this ruby script that simple rips through a CSV file, retrieves a
username and then search my database for that user and any associated
data. My problem is that the query I'm using to find my users isn't
working even though this is pretty basic stuff that I am trying to do.
My query looks a little something like this:

@finduser = User.find:)first, :conditions => ['upper(username) = ?',
x[11].to_s.upcase])

x[11] is the field in my csv file that has the username, other then
that this is a simple script, but the user is never being found even
though ActiveRecord has the correct host and adapter information. My
question is there anyway to output the query string from my object or
the query that is being built? The only thing I can think of is that the
query is not being built correctly since for some of my test users the
correct username is there and should be found. Thanks in advance and
happy holidays,

-S
 
W

w_a_x_man

Hi all,

I have this ruby script that simple rips through a CSV file, retrieves a
username and then search my database for that user and any associated
data. My problem is that the query I'm using to find my users isn't
working even though this is pretty basic stuff that I am trying to do.
My query looks a little something like this:

@finduser = User.find:)first, :conditions => ['upper(username) = ?',
x[11].to_s.upcase])

x[11] is the field in my csv file that has the  username, other then
that this is a simple script, but the user is never being found even
though ActiveRecord has the correct host and adapter information. My
question is there anyway to output the query string from my object or
the query that is being built? The only thing I can think of is that the
query is not being built correctly since for some of my test users the
correct username is there and should be found. Thanks in advance and
happy holidays,

-S

This is not a Rails forum.
 
H

Hassan Schroeder

My query looks a little something like this:

@finduser =3D User.find:)first, :conditions =3D> ['upper(username) =3D ?'= ,
x[11].to_s.upcase])

x[11] is the field in my csv file that has the =A0username, other then
that this is a simple script, but the user is never being found even
though ActiveRecord has the correct host and adapter information. My
question is there anyway to output the query string from my object or
the query that is being built?

Does the DB you're using have a log? (MySQL does, so you can see
the queries generated directly.)

You could also use print statements or a debugger to confirm that the
value of x[11].to_s.upcase is what you think it is.

--=20
Hassan Schroeder ------------------------ (e-mail address removed)
twitter: @hassan
 
S

Shandy Nantz

Hassan Schroeder wrote in post #970921:
Does the DB you're using have a log? (MySQL does, so you can see
the queries generated directly.)

You could also use print statements or a debugger to confirm that the
value of x[11].to_s.upcase is what you think it is.

I am out putting error messages to a file, but because I am running this
as a script in a simple editor and not as a true rails app, no log is
being produced except for what I output to an error file. I am out
putting the query and all the correct info should be found, so it must
be something minor that I am missing and most likely a simple bug.
Thanks for the reply,

-S
 
H

Hassan Schroeder

I am out putting error messages to a file, but because I am running this
as a script in a simple editor and not as a true rails app, no log is
being produced except for what I output to an error file.

I didn't ask about a application log -- I asked about a DB query log,
which is totally independent of the app accessing it.

What DB are you using?
 
B

Brian Candler

Shandy Nantz wrote in post #970912:
@finduser = User.find:)first, :conditions => ['upper(username) = ?',
x[11].to_s.upcase])

puts x[11].to_s.upcase.inspect

If x[11] is the last column in the CSV, you might find it has an
unexpected \n at the end. If so, you can chomp it off.

I guess this is not mysql, since mysql does case-insensitive comparisons
by default, so there's no need for an upper() conversion

Beware: in other databases, you might find that the upper() conversion
defeats indexing of the column, so you could end up with a very
inefficient full table scan. Try an "explain plan" or equivalent to see.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top