Permalink
Browse files

Fix column names when using complete-insert and hex-blob. Huge thanks…

… to github.com/stainleebakhla. Closes #128
  • Loading branch information...
ifsnop committed Jun 30, 2018
1 parent 0678c05 commit 8d063449981e3f7bd28a3a083842e21a24d1f4af
Showing with 53 additions and 3 deletions.
  1. +29 −2 src/Ifsnop/Mysqldump/Mysqldump.php
  2. +10 −0 tests/test.php
  3. +14 −1 tests/test.sh
@@ -900,7 +900,13 @@ private function listValues($tableName)
$onlyOnce = true;
$lineSize = 0;
// colStmt is used to form a query to obtain row values
$colStmt = $this->getColumnStmt($tableName);
// colNames is used to get the name of the columns when using complete-insert
if ($this->dumpSettings['complete-insert']) {
$colNames = $this->getColumnNames($tableName);
}
$stmt = "SELECT ".implode(",", $colStmt)." FROM `$tableName`";
if ($this->dumpSettings['where']) {
@@ -918,7 +924,7 @@ private function listValues($tableName)
if ($this->dumpSettings['complete-insert']) {
$lineSize += $this->compressManager->write(
"INSERT$ignore INTO `$tableName` (".
implode(", ", $colStmt).
implode(", ", $colNames).
") VALUES (".implode(",", $vals).")"
);
} else {
@@ -1035,7 +1041,7 @@ function endListValues($tableName)
}
/**
* Build SQL List of all columns on current table
* Build SQL List of all columns on current table which will be used for selecting
*
* @param string $tableName Name of table to get columns
*
@@ -1059,6 +1065,27 @@ function getColumnStmt($tableName)
return $colStmt;
}
/**
* Build SQL List of all columns on current table which will be used for inserting
*
* @param string $tableName Name of table to get columns
*
* @return string SQL sentence with columns
*/
function getColumnNames($tableName)
{
$colNames = array();
foreach($this->tableColumnTypes[$tableName] as $colName => $colType) {
if ($colType['is_virtual']) {
$this->dumpSettings['complete-insert'] = true;
continue;
} else {
$colNames[] = "`${colName}`";
}
}
return $colNames;
}
}
/**
View
@@ -47,6 +47,16 @@
$dumpSettings);
$dump->start("mysqldump-php_test001.sql");
// checks if complete-insert && hex-blob works ok together
print "starting mysql-php_test001_complete.sql" . PHP_EOL;
$dumpSettings['complete-insert'] = true;
$dump = new IMysqldump\Mysqldump(
"mysql:host=localhost;dbname=test001",
"travis",
"",
$dumpSettings);
$dump->start("mysqldump-php_test001_complete.sql");
print "starting mysql-php_test002.sql" . PHP_EOL;
$dumpSettings['default-character-set'] = IMysqldump\Mysqldump::UTF8MB4;
$dumpSettings['complete-insert'] = true;
View
@@ -46,6 +46,15 @@ mysqldump -utravis test001 \
> mysqldump_test001.sql
ret[((index++))]=$?
mysqldump -utravis test001 \
--no-autocommit \
--extended-insert=false \
--hex-blob=true \
--routines=true \
--complete-insert=true \
> mysqldump_test001_complete.sql
ret[((index++))]=$?
mysqldump -utravis test002 \
--no-autocommit \
--extended-insert=false \
@@ -102,13 +111,14 @@ cat test005.src.sql | grep ^INSERT > test005.filtered.sql
cat test008.src.sql | grep FOREIGN > test008.filtered.sql
cat test010.src.sql | grep CREATE | grep EVENT > test010.filtered.sql
cat test011.src.sql | egrep "INSERT|GENERATED" > test011.filtered.sql
cat test013.src.sql | egrep "INSERT" > test013.filtered.sql
cat mysqldump_test001.sql | grep ^INSERT > mysqldump_test001.filtered.sql
cat mysqldump_test001_complete.sql | grep ^INSERT > mysqldump_test001_complete.filtered.sql
cat mysqldump_test002.sql | grep ^INSERT > mysqldump_test002.filtered.sql
cat mysqldump_test005.sql | grep ^INSERT > mysqldump_test005.filtered.sql
cat mysqldump_test012.sql | grep -E -e '50001 (CREATE|VIEW)' -e '50013 DEFINER' -e 'TRIGGER' | grep -v -e 'TABLE' -e 'CREATE VIEW' > mysqldump_test012.filtered.sql
cat mysqldump_test013.sql | grep "INSERT" > mysqldump_test013.filtered.sql
cat mysqldump-php_test001.sql | grep ^INSERT > mysqldump-php_test001.filtered.sql
cat mysqldump-php_test001_complete.sql | grep ^INSERT > mysqldump-php_test001_complete.filtered.sql
cat mysqldump-php_test002.sql | grep ^INSERT > mysqldump-php_test002.filtered.sql
cat mysqldump-php_test005.sql | grep ^INSERT > mysqldump-php_test005.filtered.sql
cat mysqldump-php_test008.sql | grep FOREIGN > mysqldump-php_test008.filtered.sql
@@ -120,6 +130,9 @@ cat mysqldump-php_test013.sql | grep INSERT > mysqldump-php_test013.filtered.sql
diff test001.filtered.sql mysqldump_test001.filtered.sql
ret[((index++))]=$?
diff mysqldump_test001_complete.filtered.sql mysqldump-php_test001_complete.filtered.sql
ret[((index++))]=$?
diff test002.filtered.sql mysqldump_test002.filtered.sql
ret[((index++))]=$?

0 comments on commit 8d06344

Please sign in to comment.