Permalink
Browse files

Detect import errors

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@582 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
jakubvrana
jakubvrana committed Apr 16, 2009
1 parent 16f4210 commit d83b6548fb8deef838acf4593f07f20c77a050c1
Showing with 22 additions and 20 deletions.
  1. +22 −20 select.inc.php
View
@@ -82,26 +82,7 @@
}
exit;
}
- if ($_POST["import"]) {
- $file = preg_replace("~^\xEF\xBB\xBF~", '', get_file("csv_file")); //! character set
- $cols = "";
- $rows = array(); //! packet size
- preg_match_all('~("[^"]*"|[^"\\n]+)+~', $file, $matches);
- foreach ($matches[0] as $key => $val) {
- $row = array();
- preg_match_all('~(("[^"]*")+|[^,]*),~', "$val,", $matches2);
- if (!$key && !array_diff($matches2[1], array_keys($fields))) { //! doesn't work with column names containing ",\n
- $cols = " (" . implode(", ", array_map('idf_escape', $matches2[1])) . ")";
- } else {
- foreach ($matches2[1] as $col) {
- $row[] = (!strlen($col) ? "NULL" : "'" . $mysql->escape_string(str_replace('""', '"', preg_replace('~^".*"$~s', '', $col))) . "'");
- }
- $rows[] = "(" . implode(", ", $row) . ")";
- }
- }
- $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . "$cols VALUES " . implode(", ", $rows));
- query_redirect(queries(), remove_from_uri("page"), lang('%d row(s) has been imported.', $mysql->affected_rows), $result, false, !$result);
- } else {
+ if (!$_POST["import"]) { // edit
$result = true;
$affected = 0;
$command = ($_POST["delete"] ? ($_POST["all"] && !$where ? "TRUNCATE " : "DELETE FROM ") : ($_POST["clone"] ? "INSERT INTO " : "UPDATE ")) . idf_escape($_GET["select"]);
@@ -134,6 +115,27 @@
}
query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result, false, !$result);
//! display edit page in case of an error
+ } elseif (is_string($file = get_file("csv_file"))) {
+ $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set
+ $cols = "";
+ $rows = array(); //! packet size
+ preg_match_all('~("[^"]*"|[^"\\n]+)+~', $file, $matches);
+ foreach ($matches[0] as $key => $val) {
+ $row = array();
+ preg_match_all('~(("[^"]*")+|[^,]*),~', "$val,", $matches2);
+ if (!$key && !array_diff($matches2[1], array_keys($fields))) { //! doesn't work with column names containing ",\n
+ $cols = " (" . implode(", ", array_map('idf_escape', $matches2[1])) . ")";
+ } else {
+ foreach ($matches2[1] as $col) {
+ $row[] = (!strlen($col) ? "NULL" : "'" . $mysql->escape_string(str_replace('""', '"', preg_replace('~^".*"$~s', '', $col))) . "'");
+ }
+ $rows[] = "(" . implode(", ", $row) . ")";
+ }
+ }
+ $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . "$cols VALUES " . implode(", ", $rows));
+ query_redirect(queries(), remove_from_uri("page"), lang('%d row(s) has been imported.', $mysql->affected_rows), $result, false, !$result);
+ } else {
+ $error = lang('Unable to upload a file.');
}
}
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), $error);

0 comments on commit d83b654

Please sign in to comment.