From 620f9b764bccbba5117d756f3f97854f7a54c26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 11 Oct 2004 12:18:03 +0000 Subject: [PATCH] Convert end of line chars we get from MySQL (bug #1042521). --- ChangeLog | 2 ++ libraries/export/sql.php | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index d2e33ee2f..c19dcc72a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,8 @@ $Source$ 2004-10-11 Michal Čihař * tbl_query_box.php: Don't try to replace %t and %f when table name is empty. + * libraries/export/sql.php: Convert end of line chars we get from MySQL + (bug #1042521). 2004-10-08 Garvin Hicking * lots of files: Adjusted superfluous spaces, added diff --git a/libraries/export/sql.php b/libraries/export/sql.php index d159a0572..eee7a5d46 100644 --- a/libraries/export/sql.php +++ b/libraries/export/sql.php @@ -221,6 +221,15 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) $create_query = $row[1]; unset($row); + // Convert end of line chars to one that we want (note that MySQL doesn't return query it will accept in all cases) + if (strpos($create_query, "(\r\n ")) { + $create_query = str_replace("\r\n", $crlf, $create_query); + } elseif (strpos($create_query, "(\n ")) { + $create_query = str_replace("\n", $crlf, $create_query); + } elseif (strpos($create_query, "(\r ")) { + $create_query = str_replace("\r", $crlf, $create_query); + } + // Should we use IF NOT EXISTS? if (isset($GLOBALS['if_not_exists'])) { $create_query = preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $create_query); @@ -229,12 +238,8 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) // are there any constraints to cut out? if (preg_match('@CONSTRAINT|FOREIGN[\s]+KEY@', $create_query)) { - // split the query into lines, so we can easilly handle it - if (strpos(",\r\n ", $create_query) === FALSE) { - $sql_lines = preg_split('@\r|\n@', $create_query); - } else { - $sql_lines = preg_split('@\r\n@', $create_query); - } + // Split the query into lines, so we can easily handle it. We know lines are separated by $crlf (done few lines above). + $sql_lines = explode($crlf, $create_query); $sql_count = count($sql_lines); // lets find first line with constraints