Skip to content

Commit

Permalink
when dumping virtual columns, enable complete-insert always
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsnop committed Apr 17, 2017
1 parent c476f0f commit 794a4b4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ php:
- 5.6
- 5.5
- 5.4
- 5.3
# - 5.3
- hhvm
- nightly

Expand All @@ -20,7 +20,6 @@ before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install
- sudo service mysql stop || echo "mysql not stopped"
- sudo stop mysql-5.6 || echo "mysql-5.6 not stopped"
- echo mysql-apt-config mysql-apt-config/select-server select mysql-5.7 | sudo debconf-set-selections
- wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
- sudo dpkg --install mysql-apt-config_0.7.3-1_all.deb
Expand All @@ -31,10 +30,9 @@ before_script:
- sudo mysqld_safe --skip-grant-tables &
- sleep 4
- sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
- sudo kill -9 `sudo cat /var/lib/mysql/mysqld_safe.pid`
- sudo kill -9 `sudo cat /var/run/mysqld/mysqld.pid`
- sudo service mysql restart
- sleep 4
- sudo mysqladmin shutdown
- sleep 1
- sudo service mysql start
- mysql -V
- tests/create_users.sh

Expand Down
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,37 @@ Refer to the [wiki](https://github.com/ifsnop/mysqldump-php/wiki/full-example) f
$pdoSettings = array()
)

$dumpSettingsDefault = array(
$dumpSettingsDefault = array(
'include-tables' => array(),
'exclude-tables' => array(),
'compress' => 'None',
'no-data' => false,
'compress' => Mysqldump::NONE,
'init_commands' => array(),
'no-data' => array(),
'reset-auto-increment' => false,
'add-drop-database' => false,
'add-drop-table' => false,
'single-transaction' => true,
'lock-tables' => false,
'add-drop-trigger' => true,
'add-locks' => true,
'extended-insert' => true,
'complete-insert' => false,
'databases' => false,
'default-character-set' => Mysqldump::UTF8,
'disable-keys' => true,
'where' => '',
'extended-insert' => true,
'events' => false,
'hex-blob' => true, /* faster than escaped content */
'net_buffer_length' => self::MAXLINESIZE,
'no-autocommit' => true,
'no-create-info' => false,
'skip-triggers' => false,
'add-drop-trigger' => true,
'lock-tables' => true,
'routines' => false,
'hex-blob' => true,
'databases' => false,
'add-drop-database' => false,
'single-transaction' => true,
'skip-triggers' => false,
'skip-tz-utc' => false,
'no-autocommit' => true,
'default-character-set' => 'utf8',
'skip-comments' => false,
'skip-dump-date' => false,
'where' => '',
/* deprecated */
'disable-foreign-keys-check' => true
);

$pdoSettingsDefaults = array(
Expand Down Expand Up @@ -258,7 +263,7 @@ it is identical tests are OK.

## TODO

...
Write more tests.

## Contributing

Expand All @@ -279,5 +284,5 @@ http://code.google.com/p/db-mysqldump/
Adapted and extended by Michael J. Calkins.
https://github.com/clouddueling

Currently maintained and improved by Diego Torres.
Currently maintained, developed and improved by Diego Torres.
https://github.com/ifsnop
12 changes: 5 additions & 7 deletions src/Ifsnop/Mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ private function listValues($tableName)
$lineSize = 0;

$colStmt = $this->getColumnStmt($tableName);
$stmt = "SELECT $colStmt FROM `$tableName`";
$stmt = "SELECT " . implode(",", $colStmt) . " FROM `$tableName`";

if ($this->dumpSettings['where']) {
$stmt .= " WHERE {$this->dumpSettings['where']}";
Expand All @@ -876,12 +876,10 @@ private function listValues($tableName)

if ($this->dumpSettings['complete-insert']) {
$lineSize += $this->compressManager->write(
"INSERT INTO `$tableName` (`" .
implode("`, `", array_keys($this->tableColumnTypes[$tableName])) .
"`) VALUES (" . implode(",", $vals) . ")"
"INSERT INTO `$tableName` (" .
implode(", ", $colStmt) .
") VALUES (" . implode(",", $vals) . ")"
);
// ojo, no debería ser array_keys, puesto que hemos eliminado algunos nombres de columnas en getcolumnsttmt!!
// getcolumnstmt debería devolver un array, y así hacer implodes dos veces.
} else {
$lineSize += $this->compressManager->write(
"INSERT INTO `$tableName` VALUES (" . implode(",", $vals) . ")"
Expand Down Expand Up @@ -1011,12 +1009,12 @@ function getColumnStmt($tableName)
} else if ($colType['is_blob'] && $this->dumpSettings['hex-blob']) {
$colStmt[] = "HEX(`${colName}`) AS `${colName}`";
} else if ($colType['is_virtual']) {
$this->dumpSettings['complete-insert'] = true;
continue;
} else {
$colStmt[] = "`${colName}`";
}
}
$colStmt = implode($colStmt, ",");

return $colStmt;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/create_users.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

mysql -u root -e "CREATE USER 'travis';"
mysql -u root -e "CREATE USER 'travis'@'%';"
mysql -u root -e "CREATE DATABASE test001;"
mysql -u root -e "CREATE DATABASE test002;"
mysql -u root -e "CREATE DATABASE test005;"
Expand Down
15 changes: 12 additions & 3 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ for i in 000; do
done
}

for i in $(seq 0 30) ; do
for i in $(seq 0 35) ; do
ret[$i]=0
done

Expand Down Expand Up @@ -83,6 +83,7 @@ cat test002.src.sql | grep ^INSERT > test002.filtered.sql
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 | grep INSERT > test011.filtered.sql
cat mysqldump_test001.sql | grep ^INSERT > mysqldump_test001.filtered.sql
cat mysqldump_test002.sql | grep ^INSERT > mysqldump_test002.filtered.sql
cat mysqldump_test005.sql | grep ^INSERT > mysqldump_test005.filtered.sql
Expand All @@ -91,6 +92,8 @@ cat mysqldump-php_test002.sql | grep ^INSERT > mysqldump-php_test002.filtered.sq
cat mysqldump-php_test005.sql | grep ^INSERT > mysqldump-php_test005.filtered.sql
cat mysqldump-php_test008.sql | grep FOREIGN > mysqldump-php_test008.filtered.sql
cat mysqldump-php_test010.sql | grep CREATE | grep EVENT > mysqldump-php_test010.filtered.sql
cat mysqldump-php_test011a.sql | grep INSERT > mysqldump-php_test011a.filtered.sql
cat mysqldump-php_test011b.sql | grep INSERT > mysqldump-php_test011b.filtered.sql

diff test001.filtered.sql mysqldump_test001.filtered.sql
ret[((index++))]=$?
Expand All @@ -115,22 +118,28 @@ ret[((index++))]=$?
diff test008.filtered.sql mysqldump-php_test008.filtered.sql
ret[((index++))]=$?

#test 24 - reset-auto-increment
#test reset-auto-increment
test009=`cat mysqldump-php_test009.sql | grep -i ENGINE | grep AUTO_INCREMENT`
if [[ -z $test009 ]]; then ret[((index++))]=0; else ret[((index++))]=1; fi

# test backup events
diff test010.filtered.sql mysqldump-php_test010.filtered.sql
ret[((index++))]=$?

# test virtual column support, with simple inserts forced to complete (a) and complete inserts (b)
diff test011.filtered.sql mysqldump-php_test011a.filtered.sql
ret[((index++))]=$?
diff test011.filtered.sql mysqldump-php_test011b.filtered.sql
ret[((index++))]=$?

rm *.checksum 2> /dev/null
rm *.filtered.sql 2> /dev/null
rm mysqldump* 2> /dev/null

echo "Done $index tests"

retvalue=0
for i in $(seq 0 30) ; do
for i in $(seq 0 35) ; do
if [[ ${ret[$i]} -ne 0 ]]; then
echo "test $i returned ${ret[$i]}"
retvalue=${ret[$i]}
Expand Down

0 comments on commit 794a4b4

Please sign in to comment.