[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Newbie question eruby dbi

Peter Woodsky

2/22/2007 8:59:00 PM

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


3 Answers

SonOfLilit

2/22/2007 9:07:00 PM

0

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/wi...

On 2/22/07, peter <peter@iwebsl.com> wrote:
> 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
>
>
>

Jeff Swensen

2/22/2007 9:10:00 PM

0

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:
> 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/wi...
>
> On 2/22/07, peter <peter@iwebsl.com> wrote:
>> 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.lex...
(617) 227 4469 Extension 234
jswensen@lextranet.com

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.


Peter Woodsky

2/22/2007 9:25:00 PM

0

Thanks!
This works great!

Regards,
Peter

On Fri, 2007-23-02 at 06:10 +0900, Jeff Swensen wrote:
> 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:
> > 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/wi...
> >
> > On 2/22/07, peter <peter@iwebsl.com> wrote:
> >> 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
> >>
> >>
> >>
> >
>