Newbie question eruby dbi

Hi List
I’ve spent the last couple days doing tutorials and so far I’m loving
Ruby. My main function will be to use eruby on a web site.

I’ve been able to get many things working but one I’m stumped on one so
I’m hoping someone can point me in the right direction.

I’m trying to use an ENV variable in a where statement as shown in the
sample below. The problem is as soon as I use “” or ‘’ around my var
username the var stops working as a var. I know this must be so simple
that the obvious is escaping me (it does work when I put a username in
manually).

Pleaseeeeeeee help :slight_smile:

username = ENV[‘REMOTE_USER’]

sth = dbh.execute(‘select grp from member where username like
“username”’)
while row=sth.fetch do
printf “%s”, row[0]
end
sth.finish

Regards,
Peter

username = ENV[‘REMOTE_USER’]

sth = dbh.execute(‘select grp from member where username like
“#{username}”’)
while row=sth.fetch do
printf “%s”, row[0]
end
sth.finish

Good luck

Check the RubyMentor project:
http://rubymentor.rubyforge.org/wiki/wiki.pl

Thanks!
This works great!

Regards,
Peter

I think the query needs to be in double quotes to invoke string
interpolation.

sth = dbh.execute(“select grp from member where username like
‘#{username}’”)

SonOfLilit wrote:


Jeffery S. Swensen | Software Engineer
Lextranet | 107 Union Wharf | Boston, MA 02109
http://www.lextranet.com
(617) 227 4469 Extension 234
[email protected]

THE INFORMATION IN THIS MESSAGE IS INTENDED ONLY FOR THE PERSONAL AND
CONFIDENTIAL USE OF THE DESIGNATED RECIPIENTS NAMED ABOVE AND MAY
CONTAIN LEGALLY PRIVILEGED INFORMATION. If the reader of this message is
not the intended recipient or an agent responsible for delivering it to
the intended recipient, you are hereby notified that you have received
this document in error, and that any review, dissemination, distribution
or copying of this message is strictly prohibited. If you have received
this communication in error, please notify us immediately by telephone
at 617-227-4469 Ext. 200. Thank you.