Skip to content

Commit 794a4b4

Browse files
committed
when dumping virtual columns, enable complete-insert always
1 parent c476f0f commit 794a4b4

File tree

5 files changed

+43
-33
lines changed

5 files changed

+43
-33
lines changed

.travis.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ php:
99
- 5.6
1010
- 5.5
1111
- 5.4
12-
- 5.3
12+
# - 5.3
1313
- hhvm
1414
- nightly
1515

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

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,32 +113,37 @@ Refer to the [wiki](https://github.com/ifsnop/mysqldump-php/wiki/full-example) f
113113
$pdoSettings = array()
114114
)
115115

116-
$dumpSettingsDefault = array(
116+
$dumpSettingsDefault = array(
117117
'include-tables' => array(),
118118
'exclude-tables' => array(),
119-
'compress' => 'None',
120-
'no-data' => false,
119+
'compress' => Mysqldump::NONE,
120+
'init_commands' => array(),
121+
'no-data' => array(),
121122
'reset-auto-increment' => false,
123+
'add-drop-database' => false,
122124
'add-drop-table' => false,
123-
'single-transaction' => true,
124-
'lock-tables' => false,
125+
'add-drop-trigger' => true,
125126
'add-locks' => true,
126-
'extended-insert' => true,
127127
'complete-insert' => false,
128+
'databases' => false,
129+
'default-character-set' => Mysqldump::UTF8,
128130
'disable-keys' => true,
129-
'where' => '',
131+
'extended-insert' => true,
132+
'events' => false,
133+
'hex-blob' => true, /* faster than escaped content */
134+
'net_buffer_length' => self::MAXLINESIZE,
135+
'no-autocommit' => true,
130136
'no-create-info' => false,
131-
'skip-triggers' => false,
132-
'add-drop-trigger' => true,
137+
'lock-tables' => true,
133138
'routines' => false,
134-
'hex-blob' => true,
135-
'databases' => false,
136-
'add-drop-database' => false,
139+
'single-transaction' => true,
140+
'skip-triggers' => false,
137141
'skip-tz-utc' => false,
138-
'no-autocommit' => true,
139-
'default-character-set' => 'utf8',
140142
'skip-comments' => false,
141143
'skip-dump-date' => false,
144+
'where' => '',
145+
/* deprecated */
146+
'disable-foreign-keys-check' => true
142147
);
143148

144149
$pdoSettingsDefaults = array(
@@ -258,7 +263,7 @@ it is identical tests are OK.
258263

259264
## TODO
260265

261-
...
266+
Write more tests.
262267

263268
## Contributing
264269

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

282-
Currently maintained and improved by Diego Torres.
287+
Currently maintained, developed and improved by Diego Torres.
283288
https://github.com/ifsnop

src/Ifsnop/Mysqldump/Mysqldump.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ private function listValues($tableName)
862862
$lineSize = 0;
863863

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

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

877877
if ($this->dumpSettings['complete-insert']) {
878878
$lineSize += $this->compressManager->write(
879-
"INSERT INTO `$tableName` (`" .
880-
implode("`, `", array_keys($this->tableColumnTypes[$tableName])) .
881-
"`) VALUES (" . implode(",", $vals) . ")"
879+
"INSERT INTO `$tableName` (" .
880+
implode(", ", $colStmt) .
881+
") VALUES (" . implode(",", $vals) . ")"
882882
);
883-
// ojo, no debería ser array_keys, puesto que hemos eliminado algunos nombres de columnas en getcolumnsttmt!!
884-
// getcolumnstmt debería devolver un array, y así hacer implodes dos veces.
885883
} else {
886884
$lineSize += $this->compressManager->write(
887885
"INSERT INTO `$tableName` VALUES (" . implode(",", $vals) . ")"
@@ -1011,12 +1009,12 @@ function getColumnStmt($tableName)
10111009
} else if ($colType['is_blob'] && $this->dumpSettings['hex-blob']) {
10121010
$colStmt[] = "HEX(`${colName}`) AS `${colName}`";
10131011
} else if ($colType['is_virtual']) {
1012+
$this->dumpSettings['complete-insert'] = true;
10141013
continue;
10151014
} else {
10161015
$colStmt[] = "`${colName}`";
10171016
}
10181017
}
1019-
$colStmt = implode($colStmt, ",");
10201018

10211019
return $colStmt;
10221020
}

tests/create_users.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
mysql -u root -e "CREATE USER 'travis';"
3+
mysql -u root -e "CREATE USER 'travis'@'%';"
44
mysql -u root -e "CREATE DATABASE test001;"
55
mysql -u root -e "CREATE DATABASE test002;"
66
mysql -u root -e "CREATE DATABASE test005;"

tests/test.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ for i in 000; do
1818
done
1919
}
2020

21-
for i in $(seq 0 30) ; do
21+
for i in $(seq 0 35) ; do
2222
ret[$i]=0
2323
done
2424

@@ -83,6 +83,7 @@ cat test002.src.sql | grep ^INSERT > test002.filtered.sql
8383
cat test005.src.sql | grep ^INSERT > test005.filtered.sql
8484
cat test008.src.sql | grep FOREIGN > test008.filtered.sql
8585
cat test010.src.sql | grep CREATE | grep EVENT > test010.filtered.sql
86+
cat test011.src.sql | grep INSERT > test011.filtered.sql
8687
cat mysqldump_test001.sql | grep ^INSERT > mysqldump_test001.filtered.sql
8788
cat mysqldump_test002.sql | grep ^INSERT > mysqldump_test002.filtered.sql
8889
cat mysqldump_test005.sql | grep ^INSERT > mysqldump_test005.filtered.sql
@@ -91,6 +92,8 @@ cat mysqldump-php_test002.sql | grep ^INSERT > mysqldump-php_test002.filtered.sq
9192
cat mysqldump-php_test005.sql | grep ^INSERT > mysqldump-php_test005.filtered.sql
9293
cat mysqldump-php_test008.sql | grep FOREIGN > mysqldump-php_test008.filtered.sql
9394
cat mysqldump-php_test010.sql | grep CREATE | grep EVENT > mysqldump-php_test010.filtered.sql
95+
cat mysqldump-php_test011a.sql | grep INSERT > mysqldump-php_test011a.filtered.sql
96+
cat mysqldump-php_test011b.sql | grep INSERT > mysqldump-php_test011b.filtered.sql
9497

9598
diff test001.filtered.sql mysqldump_test001.filtered.sql
9699
ret[((index++))]=$?
@@ -115,22 +118,28 @@ ret[((index++))]=$?
115118
diff test008.filtered.sql mysqldump-php_test008.filtered.sql
116119
ret[((index++))]=$?
117120

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

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

129+
# test virtual column support, with simple inserts forced to complete (a) and complete inserts (b)
130+
diff test011.filtered.sql mysqldump-php_test011a.filtered.sql
131+
ret[((index++))]=$?
132+
diff test011.filtered.sql mysqldump-php_test011b.filtered.sql
133+
ret[((index++))]=$?
134+
126135
rm *.checksum 2> /dev/null
127136
rm *.filtered.sql 2> /dev/null
128137
rm mysqldump* 2> /dev/null
129138

130139
echo "Done $index tests"
131140

132141
retvalue=0
133-
for i in $(seq 0 30) ; do
142+
for i in $(seq 0 35) ; do
134143
if [[ ${ret[$i]} -ne 0 ]]; then
135144
echo "test $i returned ${ret[$i]}"
136145
retvalue=${ret[$i]}

0 commit comments

Comments
 (0)