Newbie question eruby dbi

P

peter

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 :)


username = ENV['REMOTE_USER']

sth = dbh.execute('select grp from member where username like
"username"')
while row=sth.fetch do
printf "%s<be />", row[0]
end
sth.finish


Regards,
Peter
 
J

Jeff Swensen

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}'")

username = ENV['REMOTE_USER']

sth = dbh.execute('select grp from member where username like
"#{username}"')
while row=sth.fetch do
printf "%s<be />", row[0]
end
sth.finish

Good luck

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

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 :)


username = ENV['REMOTE_USER']

sth = dbh.execute('select grp from member where username like
"username"')
while row=sth.fetch do
printf "%s<be />", row[0]
end
sth.finish


Regards,
Peter

--
Jeffery S. Swensen | Software Engineer
Lextranet | 107 Union Wharf | Boston, MA 02109
http://www.lextranet.com
(617) 227 4469 Extension 234
(e-mail address removed)

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.
 
P

peter

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}'")

username = ENV['REMOTE_USER']

sth = dbh.execute('select grp from member where username like
"#{username}"')
while row=sth.fetch do
printf "%s<be />", row[0]
end
sth.finish

Good luck

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

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 :)


username = ENV['REMOTE_USER']

sth = dbh.execute('select grp from member where username like
"username"')
while row=sth.fetch do
printf "%s<be />", row[0]
end
sth.finish


Regards,
Peter
 

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,777
Messages
2,569,604
Members
45,208
Latest member
RandallLay

Latest Threads

Top