[Phpmyadmin-devel] BugFix question

Rabus rabus at bugfixes.info
Fri Nov 1 04:11:03 CET 2002


-----Original Message-----
From: Robin Johnson
>
> On Fri, Nov 01, 2002 at 09:28:36AM +0100, Rabus wrote:
> > Hmm, my code would convert your "\n\r\n\r" into "\n\n\n"...
> > But, where is a line feed style like "\n\r" used? I only
> > know about these three
> > ones:
> >
> > Unix: "\n"
> > Mac: "\r"
> > Windows: "\r\n"
> PalmPilot: "\n\r"

Argh!!!
I'd suggest to burn all Palms... ;-)
So, adding another line should magically solve the problem:

  $sql = str_replace("\r\n", "\n", $sql);
+ $sql = str_replace("\n\r", "\n", $sql);
  $sql = str_replace("\r", "\n", $sql);


> > As I tested my code about the ANSI style comment variation,
> > I noticed that your code in line 243 got problems with my
> > Windows line feeds...
> >
> > $pos  = $GLOBALS['PMA_strpos']($sql, "\n", $count2);
> >
> > imho, it would be annoying to handle all types of line
> > feeds whenever we look for one. This is why I added these
> > two lines at the beginning of the function.
> Ok, for that bit we need it. However removing the \n or \r
> anything inside a string is expressly out. I actually have
> databases where I want that data preserved properly. So the
> only remaining solution is to write a little function that
> imitates strpos looking for a line end character.

Well, is the query passed by reference to the parser?
My code should only change the query string the parser uses for ist
work. The one that will be send to the server should not be affected,
should it?

> > > Intend that it could match broken ANSI comments of '--\n' in
> > > addition to the standard '-- '. Should we support this as it
> > > is partially supported by MySQL? I say partially, because the
> > > MySQL commandline client strips out anything matching
> > > '--.*\n', but the actualy MySQL server if it is sent raw
> > > commands throws a syntax error on '--\n'.
> >
> > I does NOT! I tested it myself here and MySQL server treated "--\n"
> > like a comment. I tested this behavior on MySQL 3.23.51 (Linux x86)
> > and 4.0.4-beta
> > (WindowsNT)
> How did you test it?
> a raw mysql query, or using phpMyAdmin?

Both with the same result.

> I used a raw mysql query in PHP, and got this error:
> You have an error in your SQL syntax near '; --
>  SELECT 1' at line 1
>
> Test code:
> <?php
> $con = mysql_connect('localhost','test','testing');
> $res = mysql_query("SELECT 2; --\n SELECT 1;");
> echo "E: ".mysql_errno()." ".mysql_error(). "\n";
> ?>

Confirmed!
Looks like we've found a MySQL bug here, because

mysql_query("SELECT 2; -- SELECT 1;");

throws an error, too, although it's not meant to!
It appears to me as if MySQL only accepts ANSI comments before a real
SQL command.
Try this one:

mysql_query("--\n-- This is a comment\n--\nSELECT 'foo';");

This one works fine.

Alexander







More information about the Developers mailing list