#20510 [Bgs]: All spaces on a right padded string getting chopped

From: Date: Wed, 20 Nov 2002 19:35:46 +0000
Subject: #20510 [Bgs]: All spaces on a right padded string getting chopped
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-25358@lists.php.net to get a copy of this message
ID: 20510 Updated by: georg@php.net Reported By: jrust@php.net Status: Bogus Bug Type: MySQL related Operating System: Linux PHP Version: 4.3.0RC1 New Comment: Couldn't verify this with MySQL-Versions 3.23.52, 3.23.53, 4.0.4 and 4.1. Be sure, that you don't use a buggy distribution rpm (Redhat 7 and Mandrake 8 rpm's are buggy). Always use the actual original MySQL AB rpm's/binaries. Previous Comments: ------------------------------------------------------------------------ [2002-11-20 12:16:07] jrust@php.net Hmm...wierd. Here's my info. Same problem happens with php 4.2.1 with MySQL compiled as dynamic module. <jrust:rhun dir="jrust"/>$ /usr/local/bin/php -v PHP 4.3.0-pre2 (cli), Copyright (c) 1997-2002 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2002 Zend Technologies <jrust:rhun dir="jrust"/>$ /usr/local/bin/php -m [PHP Modules] xml tokenizer standard session posix pcre overload mysql mbstring ctype [Zend Modules] <jrust:rhun dir="jrust"/>$ rpm -qa|grep mysql mysqlclient9-3.23.22-6 mysql-3.23.41-1 mysql-server-3.23.41-1 mysql-devel-3.23.41-1 <jrust:rhun dir="jrust"/>$ /usr/local/bin/php foo.php array(2) { [0]=> string(4) "test" [1]=> string(8) "join two" } array(2) { [0]=> string(4) "test" [1]=> string(8) "join one" } Data without ORDER BY: array(2) { [0]=> string(15) "test " [1]=> string(15) "join one " } array(2) { [0]=> string(15) "test " [1]=> string(15) "join two " } ------------------------------------------------------------------------ [2002-11-20 12:09:09] derick@php.net Works fine here: [derick@kossu derick]$ mysqldump -u root -p bug20510 Enter password: -- MySQL dump 8.21 -- -- Host: localhost Database: bug20510 --------------------------------------------------------- -- Server version 3.23.49a -- -- Table structure for table 'table1' -- CREATE TABLE table1 ( record int(10) unsigned NOT NULL auto_increment, field1 varchar(30) NOT NULL default '', PRIMARY KEY (record) ) TYPE=MyISAM; -- -- Dumping data for table 'table1' -- INSERT INTO table1 VALUES (1,'test'); -- -- Table structure for table 'table2' -- CREATE TABLE table2 ( record int(10) unsigned NOT NULL auto_increment, joinID int(10) unsigned NOT NULL default '0', field2 varchar(30) NOT NULL default '', PRIMARY KEY (record) ) TYPE=MyISAM; -- -- Dumping data for table 'table2' -- INSERT INTO table2 VALUES (1,1,'join one'); INSERT INTO table2 VALUES (3,1,'join two'); [derick@kossu derick]$ cat bug20510.php <?php mysql_connect('localhost', 'root', 'mypassword'); mysql_select_db('bug20510'); $res = mysql_query ("SELECT RPAD(t1.field1,15, ' '), RPAD(t2.field2, 15, ' ') FROM table1 as t1 LEFT JOIN table2 AS t2 ON t1.record=t2.joinID ORDER BY t1.record DESC"); while ($row = mysql_fetch_row($res)) { var_dump ($row); } ?> [derick@kossu derick]$ php -v PHP 4.3.0-dev (cli) (built: Nov 19 2002 21:39:05) Copyright (c) 1997-2002 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2002 Zend Technologies [derick@kossu derick]$ php bug20510.php array(2) { [0]=> string(15) "test " [1]=> string(15) "join one " } array(2) { [0]=> string(15) "test " [1]=> string(15) "join two " } Compiled against the bundled library, using mysql 3.23.49a as server. Which versions do you use? Derick ------------------------------------------------------------------------ [2002-11-20 11:47:24] jrust@php.net Ok, here is the dump schema of the tables. My hunch now is that it is a MySQL problem in general, because a similar happens from the MySQL command line. Anyhow, I've put in a thread about it over at mysql.com. However, I don't think as a bug it's Bogus, because I'm not talking about putting data into a VARCHAR field, but rather padding any type of field on the fly on it's way out. And the data as you'll see if you run the test, is padded without the ORDER BY, but not padded when the ORDER BY is present. Oh, and one more wierd caveat I discovered. The query has to be joining on more than one row, if it only joins on one row it works fine....wierd. So, the dump schema: # start test table schema. USE DATABASE test; # # Table structure for table table1 # CREATE TABLE table1 ( record int(10) unsigned NOT NULL auto_increment, field1 varchar(30) NOT NULL default '', PRIMARY KEY (record) ) TYPE=MyISAM; # # Dumping data for table table1 # INSERT INTO table1 VALUES (1, 'test'); # # Table structure for table table2 # CREATE TABLE table2 ( record int(10) unsigned NOT NULL auto_increment, joinID int(10) unsigned NOT NULL default '0', field2 varchar(30) NOT NULL default '', PRIMARY KEY (record) ) TYPE=MyISAM; # # Dumping data for table table2 # INSERT INTO table2 VALUES (1, 1, 'join one'); INSERT INTO table2 VALUES (3, 1, 'join two'); ------------------------------------------------------------------------ [2002-11-20 07:34:32] derick@php.net Read the 2nd paragraph on: http://www.mysql.com/doc/en/CHAR.html "When CHAR values are stored, they are right-padded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed. " Not a bug -> bogus ------------------------------------------------------------------------ [2002-11-19 20:27:01] nicos@php.net <Zeev> it *seems* like a MySQL issue, but it could be some obscure PHP issue. Lets see. C API should be tested with MySQL 3 and MySQL4. Same for the PHP extension. I will do some tests and give feedbacks. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/20510 -- Edit this bug report at http://bugs.php.net/?id=20510&edit=1

« previous php.bugs (#25358) next »