diff --git a/src/Ifsnop/Mysqldump/Mysqldump.php b/src/Ifsnop/Mysqldump/Mysqldump.php index 0f07f686..a8d24df8 100644 --- a/src/Ifsnop/Mysqldump/Mysqldump.php +++ b/src/Ifsnop/Mysqldump/Mysqldump.php @@ -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; + } } /** diff --git a/tests/test.php b/tests/test.php index 50b30ebb..72712f0c 100644 --- a/tests/test.php +++ b/tests/test.php @@ -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; diff --git a/tests/test.sh b/tests/test.sh index 0d22bbd1..fb333255 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -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++))]=$?