Bug #15124 error doing query using mysql client, server 5.0.15
Submitted: 22 Nov 2005 1:32 Modified: 22 Nov 2005 15:34
Reporter: Simone Grassi Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.0.15-standard OS:Linux (Mandriva 10.2)
Assigned to: CPU Architecture:Any

[22 Nov 2005 1:32] Simone Grassi
Description:
I have a table, importend from mysql 4.1.15, using mysqldump.
The definition is:

DROP TABLE IF EXISTS `lybra_sql`;
CREATE TABLE `lybra_sql` (
  `sql_id` int(10) unsigned NOT NULL auto_increment,
  `sql` text NOT NULL,
  `description` varchar(255) default NULL,
  `flag_eval` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`sql_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Ogni entry rappresenta una query, scritta in PHP (con $this-';

I can import it (and all the other table of the DB) without errors.
Even INSERTS are ok:

LOCK TABLES `lybra_sql` WRITE;
INSERT INTO `lybra_sql` VALUES (2,'SELECT abstract, uid, title,level_id,icon FROM LEVEL WHERE fid = \'$this->fid\' order by order_value asc, title asc','Recu
pera le categorie - sotto categorie da una Query',1),(3,'SELECT  id FROM AGENDA WHERE fid = \'$this->fid\' order by stdate','Recupera le agende di quella cat
egoira del...',1),(4,'SELECT  count(id) as count FROM AGENDA WHERE fid = \'$this->fid\'','Conta se ci sono delle agende all\'interno di quella categoria',1),
(5,'SELECT distinct YEAR(stdate) AS year \r\nfrom AGENDA \r\nWHERE fid = \'$this->fid\' \r\nORDER BY stdate','Lista degli anni delle agende con quel fid',1),
(6,'SELECT abstract, fid, title FROM LEVEL WHERE uid = \'$this->fid\'','Resupera info sulla categoria corrente',1),(7,'SELECT  count(uid) as count FROM LEVEL
 WHERE fid = \'$this->fid\'','Conta se ci sono sottocategorie per quella categoria',1),(8,'SELECT accessPassword FROM LEVEL WHERE uid=\'$this->fid\'','Selezi
ono le agende protette',1),(10,'Select * from field  where field_level = 2 order by field_name',NULL,0),(9,'Select * from field  where field_level = 1 order 
by field_name',NULL,0),(11,'Select * from field where field_id = 1',NULL,0),(1000,'Select room,room from CDSAGENDA_ROOMS','just a list of available rooms',0)
,(1001,'Select status,status from \r\nCDSAGENDA_AGENDA_STATUS','just a list of possible agenda status',0),(1002,'Select field_id,field_name from field where 
field_level=1 order by order_value asc','field level 1',0),(1003,'Select field_id,field_name from field where field_level=2 order by order_value asc','field 
level 2',0),(1004,'Select session_type,label from cdsagenda_session_types order by priority','type of sessions',0),(1005,'select talk_type_id,label from cdsa
genda_talk_types order by priority','Retrieve the list of talk types',0),(1006,'select level,label from CDSAGENDA_CONFIDENTIALITY_LEVELS','Retrieve the list 
of confidentiality levels',0),(1007,'select label,label from CDSAGENDA_SUBTALK_DURATIONS','List of possible subtalk durations',0),(1008,'select label,label f
rom cdsagenda_daytimes','List of possible subtalk durations',0),(1009,'select label,label from cdsagenda_talk_duration','List of possible subtalk durations',
0);
UNLOCK TABLES;

(I did it in 2 different Mandriva 10.2 with mysql 5.0.15 installed).

The following queries are ok:
SELECT * FROM lybra_sql WHERE sql_id=2;
SELECT * FROM sql_id WHERE sql_id=2;

but when I specify in selected fields the field sql, like with:
SELECT sql,flag_eval FROM lybra_sql WHERE sql_id=2;
SELECT sql FROM lybra_sql WHERE sql_id=2;

I receive the following error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sql,flag_eval FROM lybra_sql WHERE sql_id=2' at line 1

How to repeat:
how to repear  included in Description!

Suggested fix:
I know seems my mistake, but I did it in 2 different installations and with MySQL 4.1.11 and 4.1.15 it is working (in fact I had this problem moving my websites to MySQL 5.0).
[22 Nov 2005 14:55] MySQL Verification Team
Notice in the offended queries the reserved word 'sql':

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

so you need to handle them as described in the above Manual
section.

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 5.0.17-debug

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create table tb1 (id int, `sql` char(10));
Query OK, 0 rows affected (0.01 sec)

mysql> select sql from tb1;
ERROR 1064 (42000): You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near 'sql from tb1' at line 1

mysql> select `sql` from tb1;
Empty set (0.01 sec)

mysql>
[22 Nov 2005 15:00] MySQL Verification Team
Link for correct Manual version:

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
[22 Nov 2005 15:34] Simone Grassi
sorry, I didn't think about reserved works cause it was not reserved in MySQl 4.1.x