Bug #28127 Some valid identifiers names are not parsed correctly
Submitted: 27 Apr 2007 0:46 Modified: 4 Jul 2007 3:36
Reporter: Marc Alff
Status: Closed
Category:Server Severity:S3 (Non-critical)
Version:5.0.30, 5.1 OS:Any
Assigned to: Marc Alff Target Version:

[27 Apr 2007 0:46] Marc Alff
Description:
The following column names are all valid :

0yAA, 0xGG, 0bGG, 123AA, 0xAAZ, 0b11Z,

and can be used like in :

create table t1 ( 0yAA int);
show create table t1;
drop table t1;

This works as expected.

However, the following column names, which are valid,
cause the parser to fail:

create table t1 ( 0xF int);
--> fails, which is incorrect since 0xF can not be a HEX_NUM since it does not
have an even number of digits

create table t1 ( 0b02 int);
--> fails, which is incorrect since 0b02 is not a BIN_NUM

create table t1 ( 0b2 int);
--> fails, which is incorrect since 0b2 is not a BIN_NUM

How to repeat:
create table t1 ( 0xF int);

create table t1 ( 0b02 int);

create table t1 ( 0b2 int);

Suggested fix:
The problem is in sql_lex.cc, case MY_LEX_NUMBER_IDENT:

1) parsing 0x'hex-num' does not check for the number of digits

2) parsing 0b'bin-num' uses my_isxdigit instead of '0' and '1'
[27 Apr 2007 9:50] Sveta Smirnova
Thank you for the report.

Verified as described.
[27 Apr 2007 9:52] Sveta Smirnova
But:

mysql> SELECT HEX(15);
+---------+
| HEX(15) |
+---------+
| F       | 
+---------+
1 row in set (0.00 sec)

So seems failure of "create table t1 ( 0xF int);" is OK.

Version 4.1 is not affected:

$mysql41
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 352 to server version: 4.1.23-debug

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

mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create table t1 ( 0xF int);
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 '0xF int)' at
line 1
mysql> create table t1 ( 0b02 int);
Query OK, 0 rows affected (0.07 sec)

mysql> drop table t1;
Query OK, 0 rows affected (0.00 sec)

mysql> create table t1 ( 0b2 int);
Query OK, 0 rows affected (0.07 sec)
[29 Jun 2007 0:44] Marc Alff
Pushed into 5.1.20-beta with Bug#24511
[4 Jul 2007 3:36] Paul DuBois
Noted in 5.1.20 changelog.

Some valid identifiers were not parsed correctly.