diff --git a/README.md b/README.md index 301ff87b..fe7681ef 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,8 @@ To dump a database, you need the following privileges : - If any table has one or more triggers. - **LOCK TABLES** - If "lock tables" option was enabled. +- **SUPER** + - If "single-transaction" option was enabled. Use **SHOW GRANTS FOR user@host;** to know what privileges user has. See the following link for more information: diff --git a/src/Ifsnop/Mysqldump/Mysqldump.php b/src/Ifsnop/Mysqldump/Mysqldump.php index 605208fe..dd88fa14 100644 --- a/src/Ifsnop/Mysqldump/Mysqldump.php +++ b/src/Ifsnop/Mysqldump/Mysqldump.php @@ -471,7 +471,8 @@ private function getTableStructure($tableName) } $columnTypes = array(); - $columns = $this->dbHandler->query($this->typeAdapter->show_columns($tableName), + $columns = $this->dbHandler->query( + $this->typeAdapter->show_columns($tableName), PDO::FETCH_ASSOC ); @@ -479,7 +480,8 @@ private function getTableStructure($tableName) $types = $this->parseColumnType($col); $columnTypes[$col['Field']] = array( 'is_numeric'=> $types['is_numeric'], - 'is_blob' => $types['is_blob'] + 'is_blob' => $types['is_blob'], + 'type' => $types['type'] ); } $this->tableColumnTypes[$tableName] = $columnTypes; @@ -571,8 +573,6 @@ private function getTriggerStructure($triggerName) /** * Escape values with quotes when needed - * @todo use is_number instead of ctype_digit and intval - * @todo get column data type, use it to quote results * * @param string $tableName Name of table which contains rows * @param array $row Associative array of column names and values to be quoted @@ -586,14 +586,18 @@ private function escape($tableName, $row) foreach ($row as $colName => $colValue) { if (is_null($colValue)) { $ret[] = "NULL"; - } elseif ($columnTypes[$colName]['is_numeric']) { - $ret[] = $colValue; } elseif ($this->dumpSettings['hex-blob'] && $columnTypes[$colName]['is_blob']) { - if (empty($colValue)) { - $ret[] = "''"; + if ($columnTypes[$colName]['type'] == 'bit') { + $ret[] = '0x' . bin2hex(chr($colValue)); } else { - $ret[] = '0x' . bin2hex($colValue); + if (empty($colValue)) { + $ret[] = "''"; + } else { + $ret[] = '0x' . bin2hex($colValue); + } } + } elseif ($columnTypes[$colName]['is_numeric']) { + $ret[] = $colValue; } else { $ret[] = $this->dbHandler->quote($colValue); } diff --git a/tests/test.sh b/tests/test.sh index 29bf36ea..d9aaba3e 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,19 +1,24 @@ mysql -uroot < original.sql mysqldump -uroot test001 --extended-insert=false --hex-blob=true > mysqldump.sql +php test.php cat original.sql | grep ^INSERT > original.filtered.sql cat mysqldump.sql | grep ^INSERT > mysqldump.filtered.sql +cat mysqldump-php.sql | grep ^INSERT > mysqldump-php.filtered.sql diff original.filtered.sql mysqldump.filtered.sql +ret1=$? -ret=$? +diff original.filtered.sql mysqldump-php.filtered.sql +ret2=$? rm original.filtered.sql rm mysqldump.filtered.sql +rm mysqldump-php.filtered.sql +rm mysqldump-php.sql rm mysqldump.sql -echo $ret - +exit $ret1