2

Working with Ruby 2.0, Qt4 gem and Mysql2 gem. I need to compare the text of two lineedit and make a query with them, which is a failure so far.

client = Mysql2::Client.new(:host => "localhost", :username => "root", :password => "123456", :database => "school")
# text of both lineedits saved into local variables
[email protected]() 
[email protected]()
#then
res= client.query("SELECT usr_name, usr_pass, usr_tipo FROM user WHERE usr_name = tName AND usr_pass = tPass")

The only thing that fails is that query. I've tried to put the local variable as global (@tName, @tPass), or put them into #{}, which search for columns in the table user named tName and tPass, also tried to put them into '' but that only search for a user named tName.

I want the query to search for usr_name= "text inside tName". What am I doing wrong?

EDIT: if you are wondering, tName, tPass are strings and the fields usr_name and usr_pass are varchar(50).

1 Answer 1

1

Looks like you didn't interpolate the variables. do the following

res= client.query("SELECT usr_name, usr_pass, usr_tipo 
                   FROM user 
                   WHERE usr_name = '#{tName}' AND usr_pass = '#{tPass}'")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, indeed I was missing the whole '#{tName}' thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.