Answer the question
In order to leave comments, you need to log in
How to correctly insert a variable into a sql query string in c++?
There is a request like this:
myQuery->SQL->Text = "SELECT f_department.CODE, f_department.NAME FROM f_department LEFT JOIN l_modules_22_department ON l_modules_22_department.CODE_2 = f_department.CODE WHERE l_modules_22_department.CODE_1 = '"+ depBlock[i].moduleCode + "'";
myQuery->SQL->Text = "SELECT f_department.CODE, f_department.NAME FROM f_department LEFT JOIN l_modules_22_department ON l_modules_22_department.CODE_2 = f_department.CODE WHERE l_modules_22_department.CODE_1 = " + depBlock[i].moduleCode;
Answer the question
In order to leave comments, you need to log in
Never build queries by concatenation!
Even single quotes won't save you from SQL injection. Look for how to implement prepare-execute in your mySQL library.
Cast strings explicitly to AnsiString:
myQuery->SQL->Text = (AnsiString)"SELECT f_department.CODE, f_department.NAME FROM f_department LEFT JOIN l_modules_22_department ON l_modules_22_department.CODE_2 = f_department.CODE WHERE l_modules_22_department.CODE_1 = '"
+ depBlock[i].moduleCode + (AnsiString)"'";
I like this option
myQuery->SQL->Text = String("SELECT f_department.CODE, f_department.NAME FROM f_department LEFT JOIN l_modules_22_department ON l_modules_22_department.CODE_2 = f_department.CODE WHERE l_modules_22_department.CODE_1 = ") + QuotedStr(depBlock[i].moduleCode);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question