Skip to content

Commit

Permalink
fix hhvm bug (mysql column type returns between mysql drivers is not …
Browse files Browse the repository at this point in the history
…standard)
  • Loading branch information
ifsnop committed Sep 13, 2014
1 parent 0dea65e commit c5c9c2e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
29 changes: 21 additions & 8 deletions src/Ifsnop/Mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,12 @@ private function escape($tableName, $row)
$ret[] = "NULL";
} elseif ($this->dumpSettings['hex-blob'] && $columnTypes[$colName]['is_blob']) {
if ($columnTypes[$colName]['type'] == 'bit') {
$ret[] = '0x' . bin2hex(chr($colValue));
$ret[] = "0x${colValue}";
} else {
if (empty($colValue)) {
$ret[] = "''";
} else {
$ret[] = '0x' . bin2hex($colValue);
$ret[] = "0x${colValue}";
}
}
} elseif ($columnTypes[$colName]['is_numeric']) {
Expand Down Expand Up @@ -580,7 +580,20 @@ private function listValues($tableName)

$onlyOnce = true;
$lineSize = 0;
$stmt = "SELECT * FROM `$tableName`";
$colStmt = array();

foreach($this->tableColumnTypes[$tableName] as $colName => $colType) {
if ($colType['type'] == 'bit' && $this->dumpSettings['hex-blob']) {
$colStmt[] = "LPAD(HEX(`${colName}`),2,'0') AS `${colName}`";
} else if ($colType['is_blob'] && $this->dumpSettings['hex-blob']) {
$colStmt[] = "HEX(`${colName}`) AS `${colName}`";
} else {
$colStmt[] = "`${colName}`";
}
}
$colStmt = implode($colStmt, ",");
$stmt = "SELECT $colStmt FROM `$tableName`";

if ($this->dumpSettings['where']) {
$stmt .= " WHERE {$this->dumpSettings['where']}";
}
Expand Down Expand Up @@ -1054,10 +1067,10 @@ public function databases()
$ret = $this->getDatabaseHeader(); // include headers now
}

$ret .= "CREATE DATABASE /*!32312 IF NOT EXISTS*/ `${args[0]}`".
$ret .= "CREATE DATABASE /*!32312 IF NOT EXISTS*/ `${databaseName}`".
" /*!40100 DEFAULT CHARACTER SET " . $characterSet .
" COLLATE " . $collationDb . "*/;" . PHP_EOL . PHP_EOL .
"USE `${args[0]}`;" . PHP_EOL . PHP_EOL;
" COLLATE ${collationDb} */;" . PHP_EOL . PHP_EOL .
"USE `${databaseName}`;" . PHP_EOL . PHP_EOL;

return $ret;
}
Expand All @@ -1081,7 +1094,7 @@ public function create_table($row)
{
$ret = "";
if (isset($row['Create Table'])) {
$ret = $row['Create Table'] . ";" . PHP_EOL . PHP_EOL;
$ret .= $row['Create Table'] . ";" . PHP_EOL . PHP_EOL;
} else {
throw new Exception("Error getting table code, unknown output");
}
Expand Down Expand Up @@ -1140,7 +1153,7 @@ public function create_trigger($row)
if ( false === $triggerStmtReplaced ) {
$triggerStmtReplaced = $triggerStmt;
}
$ret = "DELIMITER ;;" . PHP_EOL .
$ret .= "DELIMITER ;;" . PHP_EOL .
$triggerStmtReplaced . "*/;;" . PHP_EOL .
"DELIMITER ;" . PHP_EOL . PHP_EOL;
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/original.sql
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ CREATE TABLE `test029` (
`id` int,
`col` blob NOT NULL
);
INSERT INTO `test029` VALUES (1,0x0001020304050607080990919293949596979899);
INSERT INTO `test029` VALUES (1,0x00010203040506070809909192939495969798A9);
INSERT INTO `test029` VALUES (2,'');

DROP TABLE IF EXISTS `test033`;
Expand Down
5 changes: 5 additions & 0 deletions tests/test.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/*
for($i=0;$i<128;$i++) {
echo "$i>" . bin2hex(chr($i)) . "<" . PHP_EOL;
}
*/

error_reporting(E_ALL);

Expand Down

0 comments on commit c5c9c2e

Please sign in to comment.