Reputation: 437
I am writing in Visual C++ using MySQL C Connector.
When I StringCchPrintf this query and execute and get results then it's OK.
SELECT orders.id,
orders.get_date,
orders.work_date,
cars.car_num,
cars.car_mark,
customers.surname,
customers.name,
customers.telephone,
workers.login,
orders.paid,
orders.paid_dead_line
FROM `orders`, `cars`, `customers`, `workers`
WHERE cars.customer_id = customers.id AND
orders.car_id = cars.id AND
orders.customer_id = customers.id AND
orders.worker_id = workers.id AND
DATE(get_date) LIKE DATE('%d-%d-%d')
ORDER BY get_date ASC;
When I StringCchPrintf the query below - program is not calling free functions[1] and when I push the button again my application crashes.
SELECT orders.id,
orders.get_date,
orders.work_date,
cars.car_num,
cars.car_mark,
customers.surname,
customers.name,
customers.telephone,
workers.login,
orders.paid,
orders.paid_dead_line
FROM `orders`, `cars`, `customers`, `workers`
WHERE orders.paid IN ('0', '2', '3') AND //1 == paid
cars.customer_id = customers.id AND
orders.car_id = cars.id AND
orders.customer_id = customers.id AND
orders.worker_id = workers.id
ORDER BY get_date ASC;
[1] I put MessageBox after while ((row = mysql_fetch_row(result)))
and the messagebox is not showing, so cleaning functions are not called and on second button push program crashes. Getting data from database and showing is in separated void function.
My Questions:
Bad query syntax can crash program?
Maybe program is going out of void function before cleaning (strange)?
Regards, David
Upvotes: 0
Views: 92
Reputation: 6663
You have an extra AND
on the last line of your WHERE clause. Change this line:
orders.worker_id = workers.id AND
To this:
orders.worker_id = workers.id
Upvotes: 1