Skip to content

Commit

Permalink
Add row count to export file. Fixes ifsnop#146
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsnop committed Dec 27, 2018
1 parent d49767f commit d830857
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 62 deletions.
15 changes: 13 additions & 2 deletions src/Ifsnop/Mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,9 @@ private function listValues($tableName)

$ignore = $this->dumpSettings['insert-ignore'] ? ' IGNORE' : '';

$count = 0;
foreach ($resultSet as $row) {
$count++;
$vals = $this->prepareColumnValues($tableName, $row);
if ($onlyOnce || !$this->dumpSettings['extended-insert']) {
if ($this->dumpSettings['complete-insert']) {
Expand Down Expand Up @@ -1015,7 +1017,7 @@ private function listValues($tableName)
$this->compressManager->write(";".PHP_EOL);
}

$this->endListValues($tableName);
$this->endListValues($tableName, $count);
}

/**
Expand Down Expand Up @@ -1070,10 +1072,11 @@ public function prepareListValues($tableName)
* Table rows extractor, close locks and commits after dump
*
* @param string $tableName Name of table to export
* @param int $count Number of rows inserted
*
* @return null
*/
public function endListValues($tableName)
public function endListValues($tableName, $count = 0)
{
if ($this->dumpSettings['disable-keys']) {
$this->compressManager->write(
Expand Down Expand Up @@ -1104,6 +1107,14 @@ public function endListValues($tableName)

$this->compressManager->write(PHP_EOL);

if (!$this->dumpSettings['skip-comments']) {
$this->compressManager->write(
"-- Dumped table `$tableName` with $count row(s)".PHP_EOL.
"--".PHP_EOL.PHP_EOL
);
}


return;
}

Expand Down
136 changes: 76 additions & 60 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,35 @@ done

index=0

mysql -utravis < test001.src.sql; ret[((index++))]=$?
mysql -utravis --default-character-set=utf8mb4 < test002.src.sql; ret[((index++))]=$?
mysql -utravis < test005.src.sql; ret[((index++))]=$?
mysql -utravis < test006.src.sql; ret[((index++))]=$?
mysql -utravis < test008.src.sql; ret[((index++))]=$?
mysql -utravis < test009.src.sql; ret[((index++))]=$?
mysql -utravis < test010.src.sql; ret[((index++))]=$?
mysql -utravis < test001.src.sql; errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo "error test001.src.sql"; fi

mysql -utravis --default-character-set=utf8mb4 < test002.src.sql; errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo "error test002.src.sql"; fi

mysql -utravis < test005.src.sql; errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo "error test005.src.sql"; fi

mysql -utravis < test006.src.sql; errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo "error test006.src.sql"; fi

mysql -utravis < test008.src.sql; errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo "error test008.src.sql"; fi

mysql -utravis < test009.src.sql; errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo "error test001.src.sql"; fi

mysql -utravis < test010.src.sql; errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo "error test010.src.sql"; fi

if [[ $major -eq 5 && $medium -ge 7 ]]; then
# test virtual column support, with simple inserts forced to complete (a) and complete inserts (b)
mysql -utravis < test011.src.sql; ret[((index++))]=$?
mysql -utravis < test011.src.sql; errCode=$?; ret[((index++))]=$errCode
else
echo "test011 disabled, only valid for mysql server version > 5.7.0"
fi
mysql -utravis < test012.src.sql; ret[((index++))]=$?
#mysql -utravis < test013.src.sql; ret[((index++))]=$?
mysql -utravis < test012.src.sql; errCode=$?; ret[((index++))]=$errCode
#mysql -utravis < test013.src.sql; errCode=$?; ret[((index++))]=$errCode

checksum_test001 > test001.src.checksum
checksum_test002 > test002.src.checksum
Expand All @@ -55,7 +69,7 @@ mysqldump -utravis test001 \
--hex-blob \
--routines \
> mysqldump_test001.sql
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode

mysqldump -utravis test001 \
--no-autocommit \
Expand All @@ -64,7 +78,7 @@ mysqldump -utravis test001 \
--hex-blob \
--routines \
> mysqldump_test001_complete.sql
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode

mysqldump -utravis test002 \
--no-autocommit \
Expand All @@ -73,44 +87,44 @@ mysqldump -utravis test002 \
--hex-blob \
--default-character-set=utf8mb4 \
> mysqldump_test002.sql
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode

mysqldump -utravis test005 \
--no-autocommit \
--skip-extended-insert \
--hex-blob \
> mysqldump_test005.sql
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode

mysqldump -utravis test012 \
--no-autocommit \
--skip-extended-insert \
--hex-blob \
--events \
> mysqldump_test012.sql
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode

mysqldump -utravis test001 \
--no-autocommit \
--skip-extended-insert \
--hex-blob \
--insert-ignore \
> mysqldump_test013.sql
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode

php test.php || { echo "ERROR running test.php" && exit -1; }
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode

mysql -utravis test001 < mysqldump-php_test001.sql
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode
mysql -utravis test002 < mysqldump-php_test002.sql
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode
mysql -utravis test005 < mysqldump-php_test005.sql
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode
mysql -utravis test006b < mysqldump-php_test006.sql
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode
mysql -utravis test009 < mysqldump-php_test009.sql
ret[((index++))]=$?
errCode=$?; ret[((index++))]=$errCode

checksum_test001 > mysqldump-php_test001.checksum
checksum_test002 > mysqldump-php_test002.checksum
Expand Down Expand Up @@ -155,101 +169,97 @@ cat mysqldump-php_test013.sql | grep INSERT > mysqldump-php_test013.filtered.sql

test="test $index diff test001.filtered.sql mysqldump_test001.filtered.sql"
diff test001.filtered.sql mysqldump_test001.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

test="test $index diff mysqldump_test001_complete.filtered.sql mysqldump-php_test001_complete.filtered.sql"
diff mysqldump_test001_complete.filtered.sql mysqldump-php_test001_complete.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

test="test $index diff test002.filtered.sql mysqldump_test002.filtered.sql"
diff test002.filtered.sql mysqldump_test002.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

test="test $index diff test001.filtered.sql mysqldump-php_test001.filtered.sql"
diff test001.filtered.sql mysqldump-php_test001.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

test="test $index diff test002.filtered.sql mysqldump-php_test002.filtered.sql"
diff test002.filtered.sql mysqldump-php_test002.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

test="test $index diff test001.src.checksum mysqldump-php_test001.checksum"
diff test001.src.checksum mysqldump-php_test001.checksum
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

test="test $index diff test002.src.checksum mysqldump-php_test002.checksum"
diff test002.src.checksum mysqldump-php_test002.checksum
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

test="test $index diff test005.src.checksum mysqldump-php_test005.checksum"
diff test005.src.checksum mysqldump-php_test005.checksum
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

test="test $index diff mysqldump_test005.filtered.sql mysqldump-php_test005.filtered.sql"
diff mysqldump_test005.filtered.sql mysqldump-php_test005.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

test="test $index diff test008.filtered.sql mysqldump-php_test008.filtered.sql"
diff test008.filtered.sql mysqldump-php_test008.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

#test reset-auto-increment, make sure we don't find an AUTO_INCREMENT
test="test $index cat mysqldump-php_test009.sql \| grep -i ENGINE \| grep AUTO_INCREMENT"
cat mysqldump-php_test009.sql | grep -i ENGINE | (! grep AUTO_INCREMENT)
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

# test backup events
test="test $index diff test010.filtered.sql mysqldump-php_test010.filtered.sql"
diff test010.filtered.sql mysqldump-php_test010.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

if [[ $major -eq 5 && $medium -ge 7 ]]; then
# test virtual column support, with simple inserts forced to complete (a) and complete inserts (b)
test="test $index diff test011.filtered.sql mysqldump-php_test011a.filtered.sql"
diff test011.filtered.sql mysqldump-php_test011a.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi
test="test $index diff test011.filtered.sql mysqldump-php_test011b.filtered.sql"
diff test011.filtered.sql mysqldump-php_test011b.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi
else
echo test011 disabled, only valid for mysql server version > 5.7.0
fi

# Test create views, events, trigger
test="test $index diff mysqldump_test012.filtered.sql mysqldump-php_test012.filtered.sql"
diff mysqldump_test012.filtered.sql mysqldump-php_test012.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

# Make sure we do not find a DEFINER
test="test $index grep 'DEFINER' mysqldump-php_test012_no-definer.sql"
! grep 'DEFINER' mysqldump-php_test012_no-definer.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

# test INSERT IGNORE
test="test $index diff mysqldump_test013.filtered.sql mysqldump-php_test013.filtered.sql"
diff mysqldump_test013.filtered.sql mysqldump-php_test013.filtered.sql
ret[((index++))]=$?
if [[ $? -ne 0 ]]; then echo $test; fi

rm *.checksum 2> /dev/null
rm *.filtered.sql 2> /dev/null
rm mysqldump* 2> /dev/null
errCode=$?; ret[((index++))]=$errCode
if [[ $errCode -ne 0 ]]; then echo $test; fi

echo "Done $index tests"

Expand All @@ -264,4 +274,10 @@ done

echo "Exiting with code $retvalue"

if [[ $retvalue -eq 0 ]]; then
rm *.checksum 2> /dev/null
rm *.filtered.sql 2> /dev/null
rm mysqldump* 2> /dev/null
fi

exit $retvalue

0 comments on commit d830857

Please sign in to comment.