Hi All, new to LiveCode...looks great so far!
I'm having an issue with the 'WHERE' clause in MySQL. I've looked through the dictionary and forum but cannot find a solution.
If I use this to pull out a specific record from the db all works as expected.
--------------
put "SELECT user FROM auth WHERE user='Jason' " into tSQL
//query the database ( format ready for table)
put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
--------------
The problem is when I want to use a variable for the WHERE clause as below;
--------------
put "Jason" into tUsername
put "SELECT user FROM auth WHERE user='tUsername' " into tSQL
//query the database ( format ready for table)
put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
--------------
This results in no data?
So the question is: How do I use a variable in the WHERE clause?
Thanks
Andy
Newbe - MySQL syntax problem? --- SOLVED ---
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Newbe - MySQL syntax problem? --- SOLVED ---
Last edited by AJP on Fri Jun 03, 2011 5:00 pm, edited 1 time in total.
Re: Newbe - MySQL syntax problem?
You have to get your variable out of your string literal SQL statement.
put "SELECT user FROM auth WHERE user='" & tUsername & "'" into tSQL
So that's <equal sign><single quote><double quote> & tUsername & <double quote><single quote><double quote>
That's one way.
Another way is to use a parameter:
put "SELECT user FROM auth WHERE user=:1" into tSQL
Then use the format of DBQuery that accepts the parameters and variables.
put "SELECT user FROM auth WHERE user='" & tUsername & "'" into tSQL
So that's <equal sign><single quote><double quote> & tUsername & <double quote><single quote><double quote>
That's one way.
Another way is to use a parameter:
put "SELECT user FROM auth WHERE user=:1" into tSQL
Then use the format of DBQuery that accepts the parameters and variables.
Last edited by dglass on Fri Jun 03, 2011 4:59 pm, edited 1 time in total.
Re: Newbe - MySQL syntax problem?
Hi Andy,
Your approach would work in PHP but not in LiveCode
One of several possible correct versions of your syntax would be:
mind the quotation marks: single_quote double_quote & variable_name & double_quote single_quote
Kind regards,
Mark
Your approach would work in PHP but not in LiveCode

Code: Select all
put "SELECT user FROM auth WHERE user='" & tuserName & "' into tSQL"
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Newbe - MySQL syntax problem?
Wow quick reply and solution!
Thanks dglass and Mark.
Andy
Thanks dglass and Mark.
Andy