From 7ecb95d5d5f071aac80ef3de19509972303b251b Mon Sep 17 00:00:00 2001 From: Coder of Salvation Date: Tue, 24 Dec 2013 11:43:26 +0100 Subject: [PATCH 1/3] multiline csv fix --- ajaximportfile.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ajaximportfile.php b/ajaximportfile.php index 7171d6c..5430477 100644 --- a/ajaximportfile.php +++ b/ajaximportfile.php @@ -74,7 +74,14 @@ function stripCommentLines($in) { $statements = splitQueryText($contents); } else { - $statements = file($file); + // coderofsalvation@ Tue Dec 24 11:42:20 CET 2013 + // file() doesnt work with multiline csv columns + // actually, it should be questioned whether csv need + // to be parsed manually instead of fgetcsv in the firstplace :) + $csv = file_get_contents($file); + $csv = str_replace( array("\r\n", "\n"), "\n", $csv ); // window/linux compat + $csv = str_replace( "\"\n", "\"\"\n", $csv ); // quickndirty way to make multiline explode on next line go fine + $statements = explode("\"\n",$csv ); // see previous comment if (sizeof($statements) == 1 && strpos($statements[0], "\r") > 0) { @@ -167,4 +174,4 @@ function stripCommentLines($in) { } -?> \ No newline at end of file +?> From 8ca7a550ee805b7a4a5e4c6ba5534543cef4cf44 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Tue, 10 Jun 2014 16:15:59 +0200 Subject: [PATCH 2/3] update --- ajaximportfile.php | 15 ++++----------- ajaxsaveedit.php | 4 ++-- editcolumn.php | 4 ++-- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/ajaximportfile.php b/ajaximportfile.php index 5430477..de9a035 100644 --- a/ajaximportfile.php +++ b/ajaximportfile.php @@ -61,18 +61,11 @@ function stripCommentLines($in) { if (isset($file) && is_uploaded_file($file)) { if (isset($format) && $format == "SQL") { - $lines = file($file); + $lines = file_get_contents($file); + $lines = str_replace( array("\r\n", "\n"), "\n", $lines ); // window/linux compat + $lines = str_replace( "\"\n", "\"\"\n", $lines ); // quickndirty way to make multiline explode on next line go fine + $statements = explode("\"\n",$lines ); - // the file() function doesn't handle mac line endings correctly - if (sizeof($lines) == 1 && strpos($lines[0], "\r") > 0) { - $lines = explode("\r", $lines[0]); - } - - $commentFree = array_map("stripCommentLines", $lines); - - $contents = trim(implode('', $commentFree)); - - $statements = splitQueryText($contents); } else { // coderofsalvation@ Tue Dec 24 11:42:20 CET 2013 // file() doesnt work with multiline csv columns diff --git a/ajaxsaveedit.php b/ajaxsaveedit.php index bfe0482..854fa26 100644 --- a/ajaxsaveedit.php +++ b/ajaxsaveedit.php @@ -61,7 +61,7 @@ if ($conn->getAdapter() == "mysql") { if (isset($types) && substr($value, 0, 2) == "0x" && isset($binaryDTs) && in_array($types[$keyname], $binaryDTs)) { $updates .= "`" . $keyname . "`=" . $value . ","; - } else if (!$value && $nulls[$keyname] == "YES") { + } else if (!$value && !($value != '' && (int)$value == 0) && $nulls[$keyname] == "YES") { $updates .= "`" . $keyname . "`=NULL,"; } else { $updates .= "`" . $keyname . "`='" . $value . "',"; @@ -127,4 +127,4 @@ } } -?> \ No newline at end of file +?> diff --git a/editcolumn.php b/editcolumn.php index 9154447..a9afac2 100644 --- a/editcolumn.php +++ b/editcolumn.php @@ -133,7 +133,7 @@ echo "