cobaltblue
20th February 2010, 21:59
Hello. I am currently runnning MySql 3.23 and have been unable to get the bindvalue syntax to work in my code.
q3.prepare("SELECT MONTH(date), avg(speed) AS aspeed"
"FROM vehicle_data"
"WHERE size = 2 AND YEAR(date) = ? AND Location = ?"
"GROUP BY( MONTH(date))"
"VALUES(?,?)"
);
q3.bindValue(2010);
q3.bindValue(bob5)
The same qurry works fine if I simply use a prepare statement such as
qBeforeDate = beforeDate.toString("'SELECT MONTH(date), avg(speed) AS aspeed FROM vehicle_data WHERE size=2 AND YEAR(date) = ' yyyy ' GROUP BY(MONTH(date))'");
yearHold2 = qBeforeDate;
q2.prepare(yearHold2);
However this solution is not enough as I need to allow the qurry to be flexable enough to accept a user entered string and time (the second code block uses toString to fetch the user's selected year in this case).
Is bindvalue the right way to go for this? or do I need attempt this by a different method such as string appending ( which looked messy) or inserting the user string somehow into the statement?
q3.prepare("SELECT MONTH(date), avg(speed) AS aspeed"
"FROM vehicle_data"
"WHERE size = 2 AND YEAR(date) = ? AND Location = ?"
"GROUP BY( MONTH(date))"
"VALUES(?,?)"
);
q3.bindValue(2010);
q3.bindValue(bob5)
The same qurry works fine if I simply use a prepare statement such as
qBeforeDate = beforeDate.toString("'SELECT MONTH(date), avg(speed) AS aspeed FROM vehicle_data WHERE size=2 AND YEAR(date) = ' yyyy ' GROUP BY(MONTH(date))'");
yearHold2 = qBeforeDate;
q2.prepare(yearHold2);
However this solution is not enough as I need to allow the qurry to be flexable enough to accept a user entered string and time (the second code block uses toString to fetch the user's selected year in this case).
Is bindvalue the right way to go for this? or do I need attempt this by a different method such as string appending ( which looked messy) or inserting the user string somehow into the statement?