Bug #4721 ENCODE function worck incorrect
Submitted: 23 Jul 2004 13:26 Modified: 23 Jul 2004 18:02
Reporter: Dmitriy Buldakov Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.0.17 OS:FreeBSD (FreeBSD 5.1)
Assigned to: Dean Ellis CPU Architecture:Any

[23 Jul 2004 13:26] Dmitriy Buldakov
Description:
ENCODE function returned same string for some first arguments with same key string if one of first arguments is second of first argument concatinated with one chars.
And as a consequence DECODE returned not ENCODED value

For example: 
SELECT ENCODE( 'Billy Johnson', 'ETAdirect' ) AS `Johnson` , ENCODE( 'Billy Johnso', 'ETAdirect' ) AS `Johnso` , ENCODE( 'Billy Johnson', 'ETAdirect' ) = ENCODE( 'Billy Johnso', 'ETAdirect' ) AS `Johnson_is_Johnson`;

How to repeat:
In MYSQL comand-line client send query:
=========== false result =========== 
mysql> SELECT ENCODE( 'Billy Johnson', 'ETAdirect' ) AS `Johnson` , ENCODE( 'Billy Johnso', 'ETAdirect' ) AS `Johnso` , ENCODE( 'Billy Johnson', 'ETAdirect' ) = ENCODE( 'Billy Johnso', 'ETAdirect' ) AS `Johnson_is_Johnson`;
+---------------+--------------+--------------------+
| Johnson       | Johnso       | Johnson_is_Johnson |
+---------------+--------------+--------------------+
| ┤?КOPЛъ31у  | ┤?КOPЛъ31у |                  1 |
+---------------+--------------+--------------------+
1 row in set (0.00 sec)
============true result=============
mysql> SELECT ENCODE( 'Billy Johnson', 'ETA' ) AS `Johnson` , ENCODE( 'Billy Johnso', 'ETA' ) AS `Johnso` , ENCODE( 'Billy Johnson', 'ETA' ) = ENCODE( 'Billy Johnso', 'ETA' ) AS `Johnson_is_Johnson`;
+---------------+--------------+--------------------+
| Johnson       | Johnso       | Johnson_is_Johnson |
+---------------+--------------+--------------------+
| &#9569;&#8776;r&#9554;&#9604;&#1083;<>&#1057;O[| &#9569;&#8776;r&#9554;&#9604;&#1083;<>&#1057;O[ |                  0 |
+---------------+--------------+--------------------+
1 row in set (0.01 sec)
[23 Jul 2004 18:02] Dean Ellis
I cannot repeat a problem decoding those with 4.0.21:

mysql> SELECT DECODE(ENCODE( 'Billy Johnson', 'ETAdirect' ),'ETAdirect') AS `Johnson` , DECODE(ENCODE('Billy Johnso', 'ETAdirect' ),'ETAdirect') AS `Johnso`;
+---------------+--------------+
| Johnson       | Johnso       |
+---------------+--------------+
| Billy Johnson | Billy Johnso |
+---------------+--------------+

Does the above report a different result for you in a current release?
[26 Jul 2004 10:43] Dmitriy Buldakov
Query like "SELECT DECODE(ENCODE( 'Billy Johnson', 'ETAdirect' ),'ETAdirect') AS 
`Johnson` , DECODE(ENCODE('Billy Johnso', 'ETAdirect' ),'ETAdirect') AS 
`Johnso`" works correctly in 4.0.17 too.  
 
But i send you another one : "SELECT ENCODE( 'Billy Johnson', 'ETAdirect' ) AS 
`Johnson` , ENCODE( 'Billy 
Johnso', 'ETAdirect' ) AS `Johnso` , ENCODE( 'Billy Johnson', 'ETAdirect' ) = 
ENCODE( 'Billy Johnso', 'ETAdirect' ) AS `Johnson_is_Johnson`". Please try it. 
 
I think last char code of result ENCODE( 'Billy Johnson', 'ETAdirect' ) is '0' and last 
char may be lost while comparing or storing operations.
[16 Sep 2004 19:24] Dean Ellis
That query works against 4.0.21 also.  Please try a current release.