Error when Deleting - Unknown column 'xxx' in 'where clause'

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
crafty
Posts: 15
Joined: Thu 30 Aug 2007 15:34

Error when Deleting - Unknown column 'xxx' in 'where clause'

Post by crafty » Tue 04 Dec 2007 00:40

Hi,

I've encountered a problem when deleting rows from my query. I've come up to the following procedure to reproduce the error:

Create two tables and populate them:

CREATE TABLE `test` (
`id` int(11) NOT NULL auto_increment,
`names` varchar(20) default NULL,
PRIMARY KEY (`id`)
);

INSERT INTO `test` VALUES (2,'aaaa');
INSERT INTO `test` VALUES (3,'bbbb');

CREATE TABLE `test2` (
`id` int(11) NOT NULL auto_increment,
`parent_id` int(11) default NULL,
PRIMARY KEY (`id`)
);

INSERT INTO `test2` VALUES (1,2);
INSERT INTO `test2` VALUES (2,3);
INSERT INTO `test2` VALUES (3,2);


Create TMyQuery with the following SQL:

select TC.id,
if(T.id<0,'abc',T.names) as names
from
test2 TC
left join test T on (T.id = TC.parent_id)
order by T.names

Add fields with the `Field Editor`.
Now either use the `Date Editor` in the IDE or launch app and issue MyQuery.Delete - both will result with the same error:
#42S22Unknown column 'names' in 'where clause'

Remove the if clause (or the 'order by') from the SQL query and there will be no error so the query above should also work.

Regards,
Crafty

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 05 Dec 2007 11:50

Thank you for information. This problem has already been fixed. The fix will be available in the next MyDAC build.
As a temporary solution, you can generate the query for the SQLDelete property at design time and fix this query.

crafty
Posts: 15
Joined: Thu 30 Aug 2007 15:34

Post by crafty » Wed 05 Dec 2007 22:17

It's very nice to here that you care about users and that the issue is fixed :D

Regards,
Crafty

P.S. I've already discovered SQLDelete to be a temporary solution, but thanks anyways.

Post Reply