#1643758 Error #1264 importing NULL values in MySQL 5.0

This commit is contained in:
Sebastian Mendel
2007-03-19 15:41:35 +00:00
parent a53ccda75c
commit 8878baf7b1
2 changed files with 28 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ $HeadURL$
- bug #1682044 Export file even if file not selected - bug #1682044 Export file even if file not selected
- bug #1672789 Undefined offset: 4 in sqlparser.lib.php #1674 - bug #1672789 Undefined offset: 4 in sqlparser.lib.php #1674
- bug #1662976 Authentication fails when controluser/pass is set - bug #1662976 Authentication fails when controluser/pass is set
- bug #1643758 Error #1264 importing NULL values in MySQL 5.0
- [gui] avoid displaying a wide selector in server selection - [gui] avoid displaying a wide selector in server selection
+ [core] added PMA_fatalError() and made use of it + [core] added PMA_fatalError() and made use of it
. [i18n] use generic $strOptions . [i18n] use generic $strOptions

View File

@@ -1,9 +1,15 @@
<?php <?php
/* $Id$ */ /* vim: set expandtab sw=4 ts=4 sts=4: */
// vim: expandtab sw=4 ts=4 sts=4: /**
* CSV import plugin for phpMyAdmin
/* CSV import plugin for phpMyAdmin */ *
* @todo add an option for handling NULL values
* @version $Id$
*/
/**
*
*/
if ($plugin_param == 'table') { if ($plugin_param == 'table') {
if (isset($plugin_list)) { if (isset($plugin_list)) {
$plugin_list['csv'] = array( $plugin_list['csv'] = array(
@@ -165,7 +171,10 @@ if ($plugin_param == 'table') {
} }
$fail = FALSE; $fail = FALSE;
$value = ''; $value = '';
while (($need_end && $ch != $csv_enclosed) || (!$need_end && !($ch == $csv_terminated || $ch == $csv_new_line || ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))))) { while (($need_end && $ch != $csv_enclosed)
|| (!$need_end && !($ch == $csv_terminated
|| $ch == $csv_new_line || ($csv_new_line == 'auto'
&& ($ch == "\r" || $ch == "\n"))))) {
if ($ch == $csv_escaped) { if ($ch == $csv_escaped) {
if ($i == $len - 1) { if ($i == $len - 1) {
$fail = TRUE; $fail = TRUE;
@@ -184,6 +193,12 @@ if ($plugin_param == 'table') {
$i++; $i++;
$ch = $buffer[$i]; $ch = $buffer[$i];
} }
// unquoted NULL string
if (false === $need_end && $value === 'NULL') {
$value = null;
}
if ($fail) { if ($fail) {
$i = $fallbacki; $i = $fallbacki;
$ch = $buffer[$i]; $ch = $buffer[$i];
@@ -236,6 +251,7 @@ if ($plugin_param == 'table') {
} }
// Do we have correct count of values? // Do we have correct count of values?
if (count($values) != $required_fields) { if (count($values) != $required_fields) {
// Hack for excel // Hack for excel
if ($values[count($values) - 1] == ';') { if ($values[count($values) - 1] == ';') {
unset($values[count($values) - 1]); unset($values[count($values) - 1]);
@@ -253,7 +269,12 @@ if ($plugin_param == 'table') {
if (!$first) { if (!$first) {
$sql .= ', '; $sql .= ', ';
} }
$sql .= '\'' . addslashes($val) . '\''; if ($val === null) {
$sql .= 'NULL';
} else {
$sql .= '\'' . addslashes($val) . '\'';
}
$first = FALSE; $first = FALSE;
} }
$sql .= ')'; $sql .= ')';